How to add structures screen

This commit is contained in:
ForestOfLight
2025-04-13 01:50:15 -07:00
Unverified
parent 79b22e5fd7
commit 77994b26dd
5 changed files with 22 additions and 5 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class BlockInfo {
}
static showStructureBlockInfo(player) {
const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true });
const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true, useLayers: false });
if (!block && this.shownToLastTick.has(player.id)) {
player.onScreenDisplay.setActionBar({ text: 'Structure:\n§7None' });
this.shownToLastTick.delete(player.id);
+5
View File
@@ -2,6 +2,7 @@ import { forceShow } from '../utils';
import { structureCollection } from './StructureCollection';
import { MenuFormBuilder } from './MenuFormBuilder';
import { InstanceEditForm } from './InstanceEditForm';
import { world } from '@minecraft/server';
export class MenuForm {
constructor(player, { jumpToInstance = true } = {}) {
@@ -36,6 +37,10 @@ export class MenuForm {
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);
return;
}
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
return selectedInstanceName || this.createNewInstance();
});
+11
View File
@@ -12,6 +12,7 @@ export class MenuFormBuilder {
allInstanceNameForm.button(`§2${instanceName}`);
});
allInstanceNameForm.button('Create New Instance');
allInstanceNameForm.button('How to Add New Structures');
return allInstanceNameForm;
}
@@ -40,4 +41,14 @@ export class MenuFormBuilder {
.textField('Enter the Structure ID:', 'example_structure')
.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"
body += "§7- Add a mcstructure file to this pack's structures folder. It will not appear in the list of structures, so enter the filename (without '.mcstructure') as the Structure ID.";
return new ActionFormData()
.title(this.menuTitle)
.body(body);
}
}
+4 -4
View File
@@ -4,13 +4,13 @@ import { world } from "@minecraft/server";
export class Raycaster {
static STEP_SIZE = 0.2;
static getStructureBlocks(dimension, startLocation, direction, { maxDistance, getFirst = true, collideWithWorldBlocks = true }) {
static getStructureBlocks(dimension, startLocation, direction, { maxDistance = 7, getFirst = true, collideWithWorldBlocks = true, useLayers = true }) {
// Can probably be optimized by the fact that we only need full blocks and aren't checking for partial blocks
const blocks = [];
let location = startLocation;
let distance = 0;
while (distance < maxDistance) {
const locatedStructures = structureCollection.getStructures(dimension.id, location);
const locatedStructures = structureCollection.getStructures(dimension.id, location, { useLayers });
if (locatedStructures.length !== 0) {
const structure = locatedStructures[0];
const block = structure.getBlock(structure.toStructureCoords(location));
@@ -36,11 +36,11 @@ export class Raycaster {
return blocks;
}
static getTargetedStructureBlock(player, { isFirst = true, collideWithWorldBlocks = true }) {
static getTargetedStructureBlock(player, { isFirst = true, collideWithWorldBlocks = true, useLayers = true } = {}) {
const startLocation = player.getHeadLocation();
const direction = player.getViewDirection();
const maxDistance = 7;
const blocks = this.getStructureBlocks(player.dimension, startLocation, direction, { maxDistance, getFirst: isFirst, collideWithWorldBlocks });
const blocks = this.getStructureBlocks(player.dimension, startLocation, direction, { maxDistance, getFirst: isFirst, collideWithWorldBlocks, useLayers });
if (blocks.length === 0)
return void 0;
return isFirst ? blocks[0] : blocks[blocks.length - 1];
+1
View File
@@ -19,6 +19,7 @@ export class StructureInstance {
this.#structure = world.structureManager.get(structureId);
if (!this.#structure)
throw new Error(`[StrucTool] Structure '${structureId}' not found.`);
this.#structure.saveToWorld();
this.#options = this.loadOptions();
this.#options.structureId = structureId;
if (this.#options.isEnabled)