wip: Construct API

This commit is contained in:
ForestOfLight
2026-05-29 23:27:11 +02:00
Unverified
parent f750710732
commit 2b90020e37
25 changed files with 454 additions and 29 deletions
@@ -20,4 +20,21 @@ export class Builder {
isFlexibleInstanceMoving() {
return this.flexibleInstanceMovement !== void 0;
}
asPacket() {
return {
playerId: this.playerId,
easyPlace: this.isOptionEnabled('easyPlace'),
fastEasyPlace: this.isOptionEnabled('fastEasyPlace'),
materialGrabber: this.isOptionEnabled('materialGrabber'),
materialInstanceName: this.materialInstanceName
};
}
setOptions(builderOptions) {
this.setOption('easyPlace', builderOptions.easyPlace);
this.setOption('fastEasyPlace', builderOptions.fastEasyPlace);
this.setOption('materialGrabber', builderOptions.materialGrabber);
this.materialInstanceName = builderOptions.materialInstanceName;
}
}
+13 -6
View File
@@ -1,29 +1,36 @@
import { world } from "@minecraft/server";
import { Builder } from "./Builder";
import { BuilderNotFoundError } from "../Errors/BuilderNotFoundError";
export class Builders {
static builders = {};
static add(playerId) {
if (this.builders[playerId])
if (Builders.builders[playerId])
return;
this.builders[playerId] = new Builder(playerId);
Builders.builders[playerId] = new Builder(playerId);
}
static remove(playerId) {
delete this.builders[playerId];
delete Builders.builders[playerId];
}
static get(id) {
return this.builders[id];
const builder = Builders.builders[id];
if (builder === void 0)
throw new BuilderNotFoundError(id);
}
static onJoin(playerId) {
this.add(playerId);
Builders.add(playerId);
}
static onLeave(playerId) {
this.remove(playerId);
Builders.remove(playerId);
}
static getIds() {
return Object.keys(Builders.builders);
}
}
@@ -0,0 +1,6 @@
export class BuilderNotFoundError extends Error {
constructor(builderId) {
super(`§cBuilder "${builderId}" not found.`);
this.name = 'BuilderNotFoundError';
}
}
@@ -8,7 +8,7 @@ export class CommandResponseError extends Error {
throw new Error('getRawMessage() must be implemented by subclasses of CommandResponseError');
}
sendTo(source) {
source.sendMessage(this.getRawMessage());
sendTo(origin) {
origin.sendMessage(this.getRawMessage());
}
}
@@ -1,3 +0,0 @@
import { PROTO } from '../../lib/MCBE-IPC/ipc'
export const Ready = PROTO.Void;
@@ -1,6 +0,0 @@
import { system } from "@minecraft/server";
import { Ready } from "./Ready.ipc";
system.runTimeout(() => {
IPC.send(`constructExtension:ready`, Ready, void 0);
}, 1);
@@ -46,13 +46,8 @@ export class InstanceOptions extends Option {
return world.getDimension(this.dimensionId);
}
enable() {
this.isEnabled = true;
this.save();
}
disable() {
this.isEnabled = false;
setEnabled(enable) {
this.isEnabled = enable;
this.save();
}
@@ -69,7 +64,7 @@ export class InstanceOptions extends Option {
}
setLayer(layer) {
this.currentLayer = layer;
this.currentLayer = layer.floor();
this.save();
}
@@ -82,4 +77,9 @@ export class InstanceOptions extends Option {
this.verifier.trackPlayerDistance = distance;
this.save();
}
setVerifierParticleLifetime(lifetime) {
this.verifier.particleLifetime = lifetime;
this.save();
}
}
@@ -7,6 +7,8 @@ import { world, system, TicksPerSecond } from "@minecraft/server";
import { InstanceNotPlacedError } from "../Errors/InstanceNotPlacedError";
import { StructureMaterials } from "../Materials/StructureMaterials";
import { VerificationRenderer } from "../Render/VerificationRenderer";
import { structureCollection } from "../Structure/StructureCollection";
import { InstanceExistsError } from "../Errors/InstanceExistsError";
export class StructureInstance {
options;
@@ -185,19 +187,26 @@ export class StructureInstance {
}
enable() {
this.options.enable();
this.options.setEnabled(true);
this.refreshBox();
}
disable() {
this.options.disable();
this.options.setEnabled(false);
this.refreshBox();
}
rename(newName) {
if (structureCollection.has(newName))
throw new InstanceExistsError(newName);
this.options.rename(newName);
}
setStructure(structureId) {
this.options.structureId = structureId;
this.structure = new Structure(structureId);
}
place(dimensionId, worldLocation) {
this.enable();
this.move(dimensionId, worldLocation);
@@ -277,4 +286,36 @@ export class StructureInstance {
toStructureCoords(worldLocation) {
return Vector.from(worldLocation).subtract(this.options.worldLocation);
}
asPacket() {
const dimensionLocation = this.getLocation();
return {
name: this.getName(),
structureId: this.getStructureId(),
isEnabled: this.isEnabled(),
dimensionId: dimensionLocation.dimensionId,
location: { x: dimensionLocation.location.x, y: dimensionLocation.location.y, z: dimensionLocation.location.z },
bounds: this.getBounds(),
currentLayer: this.getLayer(),
maxLayer: this.getMaxLayer(),
verifier: {
isEnabled: this.options.verifier.isEnabled,
trackPlayerDistance: this.options.verifier.trackPlayerDistance,
particleLifetime: this.options.verifier.particleLifetime
}
};
}
setOptions(newOptions) {
const newVerifierOptions = newOptions.verifier;
this.options.rename(newOptions.name);
this.options.setStructure(newOptions.structureId);
this.options.setEnabled(newOptions.isEnabled);
this.options.move(newOptions.dimensionId, newOptions.location);
this.options.setLayer(newOptions.currentLayer);
this.options.setVerifierEnabled(newVerifierOptions.isEnabled);
this.options.setVerifierDistance(newVerifierOptions.trackPlayerDistance);
this.options.setVerifierParticleLifetime(newVerifierOptions.particleLifetime);
this.options.save();
}
}
@@ -30,6 +30,10 @@ class StructureMaterials {
}
}
get materials() {
return this.materials;
}
get(itemType) {
return this.materials[itemType];
}