How to add structures screen
This commit is contained in:
@@ -13,7 +13,7 @@ class BlockInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static showStructureBlockInfo(player) {
|
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)) {
|
if (!block && this.shownToLastTick.has(player.id)) {
|
||||||
player.onScreenDisplay.setActionBar({ text: 'Structure:\n§7None' });
|
player.onScreenDisplay.setActionBar({ text: 'Structure:\n§7None' });
|
||||||
this.shownToLastTick.delete(player.id);
|
this.shownToLastTick.delete(player.id);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { forceShow } from '../utils';
|
|||||||
import { structureCollection } from './StructureCollection';
|
import { structureCollection } from './StructureCollection';
|
||||||
import { MenuFormBuilder } from './MenuFormBuilder';
|
import { MenuFormBuilder } from './MenuFormBuilder';
|
||||||
import { InstanceEditForm } from './InstanceEditForm';
|
import { InstanceEditForm } from './InstanceEditForm';
|
||||||
|
import { world } from '@minecraft/server';
|
||||||
|
|
||||||
export class MenuForm {
|
export class MenuForm {
|
||||||
constructor(player, { jumpToInstance = true } = {}) {
|
constructor(player, { jumpToInstance = true } = {}) {
|
||||||
@@ -36,6 +37,10 @@ export class MenuForm {
|
|||||||
try {
|
try {
|
||||||
return forceShow(this.player, MenuFormBuilder.buildAllInstanceName()).then((response) => {
|
return forceShow(this.player, MenuFormBuilder.buildAllInstanceName()).then((response) => {
|
||||||
if (response.canceled) return;
|
if (response.canceled) return;
|
||||||
|
if (response.selection === structureCollection.getInstanceNames().length + 1) {
|
||||||
|
MenuFormBuilder.buildHowToAddNewStructures().show(this.player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
||||||
return selectedInstanceName || this.createNewInstance();
|
return selectedInstanceName || this.createNewInstance();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export class MenuFormBuilder {
|
|||||||
allInstanceNameForm.button(`§2${instanceName}`);
|
allInstanceNameForm.button(`§2${instanceName}`);
|
||||||
});
|
});
|
||||||
allInstanceNameForm.button('Create New Instance');
|
allInstanceNameForm.button('Create New Instance');
|
||||||
|
allInstanceNameForm.button('How to Add New Structures');
|
||||||
return allInstanceNameForm;
|
return allInstanceNameForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,4 +41,14 @@ export class MenuFormBuilder {
|
|||||||
.textField('Enter the Structure ID:', 'example_structure')
|
.textField('Enter the Structure ID:', 'example_structure')
|
||||||
.submitButton('Submit');
|
.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,13 +4,13 @@ import { world } from "@minecraft/server";
|
|||||||
export class Raycaster {
|
export class Raycaster {
|
||||||
static STEP_SIZE = 0.2;
|
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
|
// Can probably be optimized by the fact that we only need full blocks and aren't checking for partial blocks
|
||||||
const blocks = [];
|
const blocks = [];
|
||||||
let location = startLocation;
|
let location = startLocation;
|
||||||
let distance = 0;
|
let distance = 0;
|
||||||
while (distance < maxDistance) {
|
while (distance < maxDistance) {
|
||||||
const locatedStructures = structureCollection.getStructures(dimension.id, location);
|
const locatedStructures = structureCollection.getStructures(dimension.id, location, { useLayers });
|
||||||
if (locatedStructures.length !== 0) {
|
if (locatedStructures.length !== 0) {
|
||||||
const structure = locatedStructures[0];
|
const structure = locatedStructures[0];
|
||||||
const block = structure.getBlock(structure.toStructureCoords(location));
|
const block = structure.getBlock(structure.toStructureCoords(location));
|
||||||
@@ -36,11 +36,11 @@ export class Raycaster {
|
|||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getTargetedStructureBlock(player, { isFirst = true, collideWithWorldBlocks = true }) {
|
static getTargetedStructureBlock(player, { isFirst = true, collideWithWorldBlocks = true, useLayers = true } = {}) {
|
||||||
const startLocation = player.getHeadLocation();
|
const startLocation = player.getHeadLocation();
|
||||||
const direction = player.getViewDirection();
|
const direction = player.getViewDirection();
|
||||||
const maxDistance = 7;
|
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)
|
if (blocks.length === 0)
|
||||||
return void 0;
|
return void 0;
|
||||||
return isFirst ? blocks[0] : blocks[blocks.length - 1];
|
return isFirst ? blocks[0] : blocks[blocks.length - 1];
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export class StructureInstance {
|
|||||||
this.#structure = world.structureManager.get(structureId);
|
this.#structure = world.structureManager.get(structureId);
|
||||||
if (!this.#structure)
|
if (!this.#structure)
|
||||||
throw new Error(`[StrucTool] Structure '${structureId}' not found.`);
|
throw new Error(`[StrucTool] Structure '${structureId}' not found.`);
|
||||||
|
this.#structure.saveToWorld();
|
||||||
this.#options = this.loadOptions();
|
this.#options = this.loadOptions();
|
||||||
this.#options.structureId = structureId;
|
this.#options.structureId = structureId;
|
||||||
if (this.#options.isEnabled)
|
if (this.#options.isEnabled)
|
||||||
|
|||||||
Reference in New Issue
Block a user