setLayer form and make easyPlace rules require paper named "easyPlace"
This commit is contained in:
@@ -2,6 +2,7 @@ import { structureCollection } from './StructureCollection';
|
|||||||
import { MenuForm } from '../classes/MenuForm';
|
import { MenuForm } from '../classes/MenuForm';
|
||||||
import { ActionFormData } from '@minecraft/server-ui';
|
import { ActionFormData } from '@minecraft/server-ui';
|
||||||
import { InstanceEditOptions } from './InstanceEditOptions';
|
import { InstanceEditOptions } from './InstanceEditOptions';
|
||||||
|
import { InstanceEditFormBuilder } from './InstanceEditFormBuilder';
|
||||||
|
|
||||||
export class InstanceEditForm {
|
export class InstanceEditForm {
|
||||||
instanceName;
|
instanceName;
|
||||||
@@ -34,8 +35,8 @@ export class InstanceEditForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show() {
|
show() {
|
||||||
const form = this.buildInstanceForm();
|
const currentOptions = this.instance.isPlaced() ? this.options.isPlaced : this.options.notPlaced;
|
||||||
form.show(this.player).then((response) => {
|
InstanceEditFormBuilder.buildInstance(this.instanceName, currentOptions, this.options.common).show(this.player).then((response) => {
|
||||||
if (response.canceled) return;
|
if (response.canceled) return;
|
||||||
let selectedOption;
|
let selectedOption;
|
||||||
if (this.instance.isPlaced())
|
if (this.instance.isPlaced())
|
||||||
@@ -46,20 +47,6 @@ export class InstanceEditForm {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
buildInstanceForm() {
|
|
||||||
const instanceOptions = this.instance.isPlaced() ? this.options.isPlaced : this.options.notPlaced;
|
|
||||||
const form = new ActionFormData()
|
|
||||||
.title('§l§2StrucTool §8Menu')
|
|
||||||
.body(`Instance: §2${this.instanceName}`)
|
|
||||||
instanceOptions.forEach(option => {
|
|
||||||
form.button(`${option}`);
|
|
||||||
});
|
|
||||||
this.options.common.forEach(option => {
|
|
||||||
form.button(`${option}`);
|
|
||||||
});
|
|
||||||
return form;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleOption(option) {
|
handleOption(option) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case InstanceEditOptions.PlaceInstance:
|
case InstanceEditOptions.PlaceInstance:
|
||||||
@@ -111,6 +98,10 @@ export class InstanceEditForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLayerForm() {
|
setLayerForm() {
|
||||||
// should have a toggle for if it should layer the structure or notw
|
InstanceEditFormBuilder.buildSetLayer(this.instance.getBounds().max.y, this.instance.getLayer()).show(this.player).then((response) => {
|
||||||
|
if (response.canceled) return;
|
||||||
|
const selectedLayer = response.formValues[0];
|
||||||
|
this.instance.setLayer(parseInt(selectedLayer));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,32 @@
|
|||||||
import { ActionFormData, ModalFormData } from '@minecraft/server-ui';
|
import { ActionFormData, ModalFormData } from '@minecraft/server-ui';
|
||||||
|
import { MenuFormBuilder } from './MenuFormBuilder';
|
||||||
|
|
||||||
export class InstanceEditFormBuilder {
|
export class InstanceEditFormBuilder {
|
||||||
static buildRenameInstance() {
|
static buildInstance(instanceName, currentOptions, commonOptions) {
|
||||||
|
const form = new ActionFormData()
|
||||||
|
.title(MenuFormBuilder.menuTitle)
|
||||||
|
.body(`Instance: §2${instanceName}`)
|
||||||
|
currentOptions.forEach(option => {
|
||||||
|
form.button(`${option}`);
|
||||||
|
});
|
||||||
|
commonOptions.forEach(option => {
|
||||||
|
form.button(`${option}`);
|
||||||
|
});
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
static buildRenameInstance() {
|
||||||
|
return new ModalFormData()
|
||||||
|
.title(MenuFormBuilder.menuTitle)
|
||||||
|
.textField('Enter a new name for the instance:', 'example_instance')
|
||||||
|
.submitButton('Rename');
|
||||||
|
}
|
||||||
|
|
||||||
|
static buildSetLayer(maxLayer, currentLayer) {
|
||||||
|
return new ModalFormData()
|
||||||
|
.title(MenuFormBuilder.menuTitle)
|
||||||
|
.label('Use the slider to select the layer. Use 0 for all layers.')
|
||||||
|
.slider("Layer", 0, maxLayer, 1, currentLayer)
|
||||||
|
.submitButton('Set Layer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ export class MenuForm {
|
|||||||
|
|
||||||
async getInstanceNameFromForm() {
|
async getInstanceNameFromForm() {
|
||||||
try {
|
try {
|
||||||
return forceShow(this.player, MenuFormBuilder.buildAllInstanceNameForm()).then((response) => {
|
return forceShow(this.player, MenuFormBuilder.buildAllInstanceName()).then((response) => {
|
||||||
if (response.canceled) return;
|
if (response.canceled) return;
|
||||||
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
||||||
return selectedInstanceName || this.createNewInstance();
|
return selectedInstanceName || this.createNewInstance();
|
||||||
@@ -43,7 +43,7 @@ export class MenuForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createNewInstance() {
|
async createNewInstance() {
|
||||||
return MenuFormBuilder.buildNewInstanceForm().show(this.player).then(async (response) => {
|
return MenuFormBuilder.buildNewInstance().show(this.player).then(async (response) => {
|
||||||
if (response.canceled)
|
if (response.canceled)
|
||||||
return;
|
return;
|
||||||
const instanceName = response.formValues[0];
|
const instanceName = response.formValues[0];
|
||||||
@@ -58,7 +58,7 @@ export class MenuForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getStructureId() {
|
async getStructureId() {
|
||||||
return MenuFormBuilder.buildAllStructuresForm().show(this.player).then((response) => {
|
return MenuFormBuilder.buildAllStructures().show(this.player).then((response) => {
|
||||||
if (response.canceled)
|
if (response.canceled)
|
||||||
return;
|
return;
|
||||||
const selectedStructureId = structureCollection.getWorldStructureIds()[response.selection];
|
const selectedStructureId = structureCollection.getWorldStructureIds()[response.selection];
|
||||||
@@ -67,7 +67,7 @@ export class MenuForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getOtherStructureId() {
|
getOtherStructureId() {
|
||||||
return MenuFormBuilder.buildOtherStructureForm().show(this.player).then((response) => {
|
return MenuFormBuilder.buildOtherStructure().show(this.player).then((response) => {
|
||||||
if (response.canceled)
|
if (response.canceled)
|
||||||
return;
|
return;
|
||||||
const structureId = response.formValues[0];
|
const structureId = response.formValues[0];
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { structureCollection } from './StructureCollection';
|
|||||||
export class MenuFormBuilder {
|
export class MenuFormBuilder {
|
||||||
static menuTitle = '§l§2StrucTool §8Menu';
|
static menuTitle = '§l§2StrucTool §8Menu';
|
||||||
|
|
||||||
static buildAllInstanceNameForm() {
|
static buildAllInstanceName() {
|
||||||
const allInstanceNameForm = new ActionFormData()
|
const allInstanceNameForm = new ActionFormData()
|
||||||
.title(this.menuTitle)
|
.title(this.menuTitle)
|
||||||
.body('Select an instance:');
|
.body('Select an instance:');
|
||||||
@@ -15,14 +15,14 @@ export class MenuFormBuilder {
|
|||||||
return allInstanceNameForm;
|
return allInstanceNameForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
static buildNewInstanceForm() {
|
static buildNewInstance() {
|
||||||
return new ModalFormData()
|
return new ModalFormData()
|
||||||
.title(this.menuTitle)
|
.title(this.menuTitle)
|
||||||
.textField('Enter a name for the new instance:', 'example_instance')
|
.textField('Enter a name for the new instance:', 'example_instance')
|
||||||
.submitButton('Submit');
|
.submitButton('Submit');
|
||||||
}
|
}
|
||||||
|
|
||||||
static buildAllStructuresForm() {
|
static buildAllStructures() {
|
||||||
const allStructuresForm = new ActionFormData()
|
const allStructuresForm = new ActionFormData()
|
||||||
.title(this.menuTitle)
|
.title(this.menuTitle)
|
||||||
.body('Select a structure:');
|
.body('Select a structure:');
|
||||||
@@ -34,7 +34,7 @@ export class MenuFormBuilder {
|
|||||||
return allStructuresForm;
|
return allStructuresForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
static buildOtherStructureForm() {
|
static buildOtherStructure() {
|
||||||
return new ModalFormData()
|
return new ModalFormData()
|
||||||
.title(this.menuTitle)
|
.title(this.menuTitle)
|
||||||
.textField('Enter the Structure ID:', 'example_structure')
|
.textField('Enter the Structure ID:', 'example_structure')
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export class StructureInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLayer(layer) {
|
setLayer(layer) {
|
||||||
if (layer < 1 || layer > this.#structure.size.y)
|
if (layer < 0 || layer > this.#structure.size.y)
|
||||||
throw new Error(`[StrucTool] Instance '${this.name}' of '${this.structureId}' does not have layer ${layer}.`);
|
throw new Error(`[StrucTool] Instance '${this.name}' of '${this.structureId}' does not have layer ${layer}.`);
|
||||||
this.#options.currentLayer = layer;
|
this.#options.currentLayer = layer;
|
||||||
this.updateOptions();
|
this.updateOptions();
|
||||||
@@ -129,7 +129,7 @@ export class StructureInstance {
|
|||||||
const { min, max } = this.getLayeredBounds();
|
const { min, max } = this.getLayeredBounds();
|
||||||
this.outliner = new Outliner(this.#options.dimensionId, this.toGlobalCoords(min), this.toGlobalCoords(max));
|
this.outliner = new Outliner(this.#options.dimensionId, this.toGlobalCoords(min), this.toGlobalCoords(max));
|
||||||
} else {
|
} else {
|
||||||
this.outliner = new Outliner(dimensionId, this.toGlobalCoords(this.getBounds().min), this.toGlobalCoords(this.getBounds().max));
|
this.outliner = new Outliner(this.#options.dimensionId, this.toGlobalCoords(this.getBounds().min), this.toGlobalCoords(this.getBounds().max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { Command } from '../lib/canopy/CanopyExtension';
|
import { Command } from '../lib/canopy/CanopyExtension';
|
||||||
import { extension } from '../config';
|
import { extension } from '../config';
|
||||||
import { structureCollection } from '../classes/StructureCollection';
|
|
||||||
import { MaterialCounter } from '../classes/MaterialCounter';
|
|
||||||
import { world, system } from '@minecraft/server';
|
import { world, system } from '@minecraft/server';
|
||||||
import { MenuForm } from '../classes/MenuForm';
|
import { MenuForm } from '../classes/MenuForm';
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const ACTION_SLOT = 35;
|
|||||||
|
|
||||||
const easyPlace = new Rule({
|
const easyPlace = new Rule({
|
||||||
identifier: 'easyPlace',
|
identifier: 'easyPlace',
|
||||||
description: { text: 'Simplifies placing blocks in a structure (paper in bottom right inventory slot).' },
|
description: { text: "Simplifies placing blocks in a structure (paper named 'easyPlace' in bottom right inventory slot)." },
|
||||||
onEnableCallback: () => { world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock); },
|
onEnableCallback: () => { world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock); },
|
||||||
onDisableCallback: () => { world.beforeEvents.playerPlaceBlock.unsubscribe(onPlayerPlaceBlock); }
|
onDisableCallback: () => { world.beforeEvents.playerPlaceBlock.unsubscribe(onPlayerPlaceBlock); }
|
||||||
})
|
})
|
||||||
@@ -29,7 +29,7 @@ function hasActionItemInCorrectSlot(player) {
|
|||||||
if (!inventory)
|
if (!inventory)
|
||||||
return false;
|
return false;
|
||||||
const actionSlot = inventory.getSlot(ACTION_SLOT);
|
const actionSlot = inventory.getSlot(ACTION_SLOT);
|
||||||
return actionSlot.hasItem() && actionSlot.typeId === 'minecraft:paper';
|
return actionSlot.hasItem() && actionSlot.typeId === 'minecraft:paper' && actionSlot.nameTag === 'easyPlace';
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchStructureBlock(location) {
|
function fetchStructureBlock(location) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Raycaster } from '../classes/Raycaster';
|
|||||||
let runner = void 0;
|
let runner = void 0;
|
||||||
const easyPlace = new Rule({
|
const easyPlace = new Rule({
|
||||||
identifier: 'fastEasyPlace',
|
identifier: 'fastEasyPlace',
|
||||||
description: { text: 'Looking at structure blocks with paper in your hand will place them.' },
|
description: { text: "Looking at structure blocks with paper named 'easyPlace' in your hand will place them." },
|
||||||
onEnableCallback: () => { runner = system.runInterval(onTick, 2); },
|
onEnableCallback: () => { runner = system.runInterval(onTick, 2); },
|
||||||
onDisableCallback: () => { system.clearRun(runner); }
|
onDisableCallback: () => { system.clearRun(runner); }
|
||||||
})
|
})
|
||||||
@@ -35,7 +35,7 @@ function isHoldingActionItem(player) {
|
|||||||
const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand);
|
const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand);
|
||||||
if (!mainhandItemStack)
|
if (!mainhandItemStack)
|
||||||
return false;
|
return false;
|
||||||
return mainhandItemStack.typeId === 'minecraft:paper';
|
return mainhandItemStack.typeId === 'minecraft:paper' && mainhandItemStack.nameTag === 'easyPlace';
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||||
|
|||||||
Reference in New Issue
Block a user