Start working at 1.2.0
/ build (push) Waiting to run

This commit is contained in:
2026-08-26 09:54:39 +08:00
Unverified
parent 36f2dd0685
commit 136d5ffa3b
159 changed files with 60793 additions and 617 deletions
+7 -1
View File
@@ -13,6 +13,10 @@ export class Builder {
return BuilderOptions.isEnabled(optionId, this.playerId);
}
getOptionValue(optionId) {
return BuilderOptions.getValue(optionId, this.playerId);
}
setOption(optionId, value) {
return BuilderOptions.setValue(optionId, this.playerId, value);
}
@@ -27,7 +31,8 @@ export class Builder {
easyPlace: this.isOptionEnabled('easyPlace'),
fastEasyPlace: this.isOptionEnabled('fastEasyPlace'),
materialGrabber: this.isOptionEnabled('materialGrabber'),
materialInstanceName: this.materialInstanceName
materialInstanceName: this.materialInstanceName,
defaultRenderMode: this.getOptionValue('defaultRenderMode')
};
}
@@ -35,6 +40,7 @@ export class Builder {
this.setOption('easyPlace', builderOptions.easyPlace);
this.setOption('fastEasyPlace', builderOptions.fastEasyPlace);
this.setOption('materialGrabber', builderOptions.materialGrabber);
this.setOption('defaultRenderMode', builderOptions.defaultRenderMode);
this.materialInstanceName = builderOptions.materialInstanceName;
}
}
@@ -0,0 +1,60 @@
import { BuilderOption } from "./BuilderOption";
import { world } from "@minecraft/server";
export class BuilderChoiceOption extends BuilderOption {
choices;
choiceLabels;
defaultValue;
constructor({ identifier, displayName, description, choices, choiceLabels, defaultValue, onChangeCallback = () => {} }) {
super({ identifier, displayName, description, howToUse: description });
this.choices = choices;
this.choiceLabels = choiceLabels;
this.defaultValue = defaultValue;
this.onChange = onChangeCallback;
}
getValue(playerId) {
const stored = world.getDynamicProperty(this.dynamicPropertyKey(playerId));
return this.choices.includes(stored) ? stored : this.defaultValue;
}
isEnabled(playerId) {
return this.getValue(playerId) !== this.defaultValue;
}
setValue(playerId, value) {
if (!this.choices.includes(value))
return void 0;
const previous = this.getValue(playerId);
this.save(playerId, value);
if (previous === value)
return void 0;
this.onChange(playerId, value);
return value;
}
getLabel(value) {
return this.choiceLabels[this.choices.indexOf(value)];
}
addControlTo(form, playerId) {
form.dropdown(this.displayName, this.choiceLabels, {
defaultValueIndex: Math.max(this.choices.indexOf(this.getValue(playerId)), 0),
tooltip: this.description
});
}
applyFormValue(playerId, formValue) {
const changedToValue = this.setValue(playerId, this.choices[formValue]);
if (changedToValue === void 0)
return void 0;
return { rawtext: [
{ text: `§a` },
this.displayName,
{ translate: 'construct.option.setto' },
this.getLabel(changedToValue),
{ text: `§a.` }
]};
}
}
@@ -18,31 +18,9 @@ export class BuilderForm {
applySettings(formValues) {
const optionIds = BuilderOptions.getOptionIds();
for (let i = 0; i < optionIds.length; i++) {
const option = BuilderOptions.get(optionIds[i]);
const changedToValue = option.setValue(this.player.id, formValues[i]);
if (changedToValue === true) {
this.player.sendMessage({ rawtext: [
{ text: `§a` },
option.displayName,
{ translate: 'construct.option.enabled' },
{ text: `§7 ` },
option.howToUse
]});
} else if (changedToValue === false) {
this.player.sendMessage({ rawtext: [
{ text: `§c` },
option.displayName,
{ translate: 'construct.option.disabled' }
]});
}
const message = BuilderOptions.get(optionIds[i]).applyFormValue(this.player.id, formValues[i]);
if (message)
this.player.sendMessage(message);
}
}
valueChangedToEnabled(hasChanged, newValue) {
return hasChanged && newValue === true;
}
valueChangedToDisabled(hasChanged, newValue) {
return hasChanged && newValue === false;
}
}
@@ -6,10 +6,8 @@ export class BuilderFormBuilder {
static buildBuilderOptions(player) {
const form = new ModalFormData()
.title(MenuFormBuilder.menuTitle);
for (const optionId of BuilderOptions.getOptionIds()) {
const option = BuilderOptions.get(optionId);
form.toggle(option.displayName, { defaultValue: option.isEnabled(player.id), tooltip: option.description });
}
for (const optionId of BuilderOptions.getOptionIds())
BuilderOptions.get(optionId).addControlTo(form, player.id);
form.submitButton({ translate: "construct.menu.submit" });
return form;
}
@@ -1,6 +1,8 @@
import { BuilderOptions } from "./BuilderOptions";
import { world } from "@minecraft/server";
const DP_NAMESPACE = "builderOptions";
export class BuilderOption {
identifier;
displayName;
@@ -8,7 +10,6 @@ export class BuilderOption {
howToUse;
#onEnable;
#onDisable;
#DP_NAMESPACE = "builderOptions";
constructor({ identifier, displayName, description, howToUse, onEnableCallback = () => {}, onDisableCallback = () => {} }) {
this.identifier = identifier;
@@ -20,10 +21,18 @@ export class BuilderOption {
BuilderOptions.add(this);
}
isEnabled(playerId) {
return world.getDynamicProperty(`${this.#DP_NAMESPACE}:${playerId}:${this.identifier}`) === true;
dynamicPropertyKey(playerId) {
return `${DP_NAMESPACE}:${playerId}:${this.identifier}`;
}
isEnabled(playerId) {
return world.getDynamicProperty(this.dynamicPropertyKey(playerId)) === true;
}
getValue(playerId) {
return this.isEnabled(playerId);
}
setValue(playerId, value) {
if (this.isEnabled(playerId) !== value) {
this.save(playerId, value);
@@ -38,6 +47,29 @@ export class BuilderOption {
}
save(playerId, value) {
world.setDynamicProperty(`${this.#DP_NAMESPACE}:${playerId}:${this.identifier}`, value);
world.setDynamicProperty(this.dynamicPropertyKey(playerId), value);
}
}
addControlTo(form, playerId) {
form.toggle(this.displayName, { defaultValue: this.isEnabled(playerId), tooltip: this.description });
}
applyFormValue(playerId, formValue) {
const changedToValue = this.setValue(playerId, formValue);
if (changedToValue === void 0)
return void 0;
if (changedToValue)
return { rawtext: [
{ text: `§a` },
this.displayName,
{ translate: 'construct.option.enabled' },
{ text: `§7 ` },
this.howToUse
]};
return { rawtext: [
{ text: `§c` },
this.displayName,
{ translate: 'construct.option.disabled' }
]};
}
}
@@ -17,6 +17,10 @@ export class BuilderOptions {
return this.options[optionId].isEnabled(playerId);
}
static getValue(optionId, playerId) {
return this.options[optionId].getValue(playerId);
}
static setValue(optionId, playerId, value) {
return this.options[optionId].setValue(playerId, value);
}