Redo managing structure how-to page and rename ./menu to ./structool
This commit is contained in:
@@ -27,11 +27,8 @@ export class MenuForm {
|
||||
async getInstanceNameFromForm() {
|
||||
try {
|
||||
return forceShow(this.player, MenuFormBuilder.buildAllInstanceName()).then((response) => {
|
||||
if (response.canceled) return;
|
||||
if (response.selection === structureCollection.getInstanceNames().length + 1) {
|
||||
MenuFormBuilder.buildHowToAddNewStructures().show(this.player);
|
||||
if (response.canceled)
|
||||
return;
|
||||
}
|
||||
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
||||
return selectedInstanceName || this.createNewInstance();
|
||||
});
|
||||
@@ -63,6 +60,10 @@ export class MenuForm {
|
||||
return MenuFormBuilder.buildAllStructures().show(this.player).then((response) => {
|
||||
if (response.canceled)
|
||||
return;
|
||||
if (response.selection === structureCollection.getWorldStructureIds().length + 1) {
|
||||
MenuFormBuilder.buildHowTo().show(this.player);
|
||||
return;
|
||||
}
|
||||
const selectedStructureId = structureCollection.getWorldStructureIds()[response.selection];
|
||||
return selectedStructureId || this.getOtherStructureId();
|
||||
});
|
||||
|
||||
@@ -12,7 +12,6 @@ export class MenuFormBuilder {
|
||||
allInstanceNameForm.button(`§2${instanceName}`);
|
||||
});
|
||||
allInstanceNameForm.button('Create New Instance');
|
||||
allInstanceNameForm.button('How to Add New Structures');
|
||||
return allInstanceNameForm;
|
||||
}
|
||||
|
||||
@@ -32,6 +31,7 @@ export class MenuFormBuilder {
|
||||
allStructuresForm.button(`§2${structureName}`);
|
||||
});
|
||||
allStructuresForm.button('Other');
|
||||
allStructuresForm.button('How to Add/Remove Structures');
|
||||
return allStructuresForm;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,13 @@ export class MenuFormBuilder {
|
||||
.submitButton('Submit');
|
||||
}
|
||||
|
||||
static buildHowToAddNewStructures() {
|
||||
let body = "How to Add Structures:\n"
|
||||
body += "§7- Save a structure using a structure block or the /structure command.\n"
|
||||
body += "§7OR\n"
|
||||
static buildHowTo() {
|
||||
let body = "§aHow to Add Structures:\n"
|
||||
body += "§7- Save a structure using a §fstructure block§7 or the §f/structure§7 command.\n"
|
||||
body += "§f§lOR§r\n"
|
||||
body += "§7- Add a .mcstructure file to this pack's structures folder. When selecting your structure, select the 'Other' option and then use the filename (without '.mcstructure') as the Structure ID. After its first use, it will be added to the list of structures.";
|
||||
body += "\n\n§cHow to Remove Structures:\n"
|
||||
body += "§7- Use the §f/structure delete§7 command to remove a structure from the world.\n"
|
||||
return new ActionFormData()
|
||||
.title(this.menuTitle)
|
||||
.body(body);
|
||||
|
||||
@@ -50,7 +50,18 @@ class StructureCollection {
|
||||
}
|
||||
|
||||
getStructures(dimensionId, location, options = {}) {
|
||||
return Object.values(this.structures).filter(structure => structure.isLocationActive(dimensionId, structure.toStructureCoords(location), options));
|
||||
return Object.values(this.structures).filter(structure => {
|
||||
try {
|
||||
return structure.isLocationActive(dimensionId, structure.toStructureCoords(location), options)
|
||||
} catch (e) {
|
||||
if (e.name === 'InvalidStructureError') {
|
||||
structureCollection.delete(structure.name);
|
||||
return false;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getStructure(dimensionId, location, options = {}) {
|
||||
|
||||
@@ -9,10 +9,17 @@ export class StructureOutliner {
|
||||
}
|
||||
|
||||
pullInstanceData() {
|
||||
try {
|
||||
this.dimension = this.instance.getDimension();
|
||||
this.bounds = this.instance.getBounds();
|
||||
this.bounds.min = this.instance.toGlobalCoords(this.bounds.min);
|
||||
this.bounds.max = this.instance.toGlobalCoords(this.bounds.max);
|
||||
} catch (e) {
|
||||
if (e.name === 'InvalidStructureError')
|
||||
this.outliner.stopDraw();
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
|
||||
@@ -5,20 +5,16 @@ import { MenuForm } from '../classes/MenuForm';
|
||||
|
||||
const ACTION_ITEM = 'minecraft:paper';
|
||||
|
||||
const structCmd = new Command({
|
||||
name: 'menu',
|
||||
description: { text: 'Manages current StrucTool structures.' },
|
||||
usage: 'menu',
|
||||
callback: structCommand
|
||||
const structoolCmd = new Command({
|
||||
name: 'structool',
|
||||
description: { text: 'Opens the StrucTool Menu. Using a paper will also open the menu.' },
|
||||
usage: 'structool',
|
||||
callback: (sender) => new MenuForm(sender)
|
||||
});
|
||||
extension.addCommand(structCmd);
|
||||
extension.addCommand(structoolCmd);
|
||||
|
||||
world.beforeEvents.itemUse.subscribe((event) => {
|
||||
if (!event.source || event.itemStack?.typeId !== ACTION_ITEM) return;
|
||||
event.cancel = true;
|
||||
system.run(() => structCommand(event.source));
|
||||
system.run(() => structoolCmd.getCallback()(event.source));
|
||||
});
|
||||
|
||||
function structCommand(sender) {
|
||||
new MenuForm(sender);
|
||||
}
|
||||
+1
-2
@@ -3,8 +3,7 @@ import './rules/easyPlace';
|
||||
import './rules/fastEasyPlace';
|
||||
|
||||
// Commands
|
||||
import './commands/struct';
|
||||
import './commands/menu';
|
||||
import './commands/structool';
|
||||
|
||||
// Other
|
||||
import './classes/BlockInfo';
|
||||
|
||||
@@ -10,7 +10,7 @@ const ACTION_SLOT = 35;
|
||||
|
||||
const easyPlace = new Rule({
|
||||
identifier: 'easyPlace',
|
||||
description: { text: "Simplifies placing blocks in a structure (paper named 'easyPlace' in bottom right inventory slot)." },
|
||||
description: { text: "Automatically places the correct block in a structure (paper named 'easyPlace' in bottom right inventory slot)." },
|
||||
onEnableCallback: () => { world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock); },
|
||||
onDisableCallback: () => { world.beforeEvents.playerPlaceBlock.unsubscribe(onPlayerPlaceBlock); }
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Raycaster } from '../classes/Raycaster';
|
||||
let runner = void 0;
|
||||
const easyPlace = new Rule({
|
||||
identifier: 'fastEasyPlace',
|
||||
description: { text: "Looking at structure blocks with a paper named 'easyPlace' in your hand will place them." },
|
||||
description: { text: "Looking at a structure block with a paper named 'easyPlace' in your hand will place it." },
|
||||
onEnableCallback: () => { runner = system.runInterval(onTick, 2); },
|
||||
onDisableCallback: () => { system.clearRun(runner); }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user