wip: Construct API
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user