Files
Construct/scripts/classes/StructureCollection.js
T
2025-03-10 23:16:42 -07:00

39 lines
945 B
JavaScript

import { world } from '@minecraft/server';
import { Structure } from './Structure';
class StructureCollection {
#structures;
constructor() {
this.#structures = {};
}
add(name) {
const struct = world.structureManager.get(name);
this.#structures[name] = new Structure(name, struct);
}
get(name) {
const structure = this.#structures[name];
if (!structure) {
throw new Error(`Structure ${name} not found.`);
}
return structure;
}
remove(name) {
const struct = this.get(name);
struct.remove();
delete this.#structures[name];
}
place(name, dimensionId, location) {
const struct = this.get(name);
if (!struct) {
throw new Error(`Structure ${name} not found.`);
}
struct.place(dimensionId, location);
}
}
export const structureCollection = new StructureCollection();