@@ -1,7 +1,7 @@
|
||||
import { MaterialGrabberFormBuilder } from './MaterialGrabberFormBuilder';
|
||||
import { forceShow } from '../../utils';
|
||||
import { Builders } from '../Builder/Builders';
|
||||
import { structureCollection } from '../Structure/StructureCollection';
|
||||
import { instanceCollection } from '../Instance/InstanceCollection';
|
||||
|
||||
export class MaterialGrabberForm {
|
||||
constructor(player) {
|
||||
@@ -11,10 +11,11 @@ export class MaterialGrabberForm {
|
||||
|
||||
show() {
|
||||
try {
|
||||
return forceShow(this.player, MaterialGrabberFormBuilder.buildInstanceSelector(this.player)).then((response) => {
|
||||
const instanceNames = instanceCollection.getInstanceNamesSortedByEnabled();
|
||||
return forceShow(this.player, MaterialGrabberFormBuilder.buildInstanceSelector(this.player, instanceNames)).then((response) => {
|
||||
if (response.canceled)
|
||||
return;
|
||||
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
||||
const selectedInstanceName = instanceNames[response.selection];
|
||||
if (selectedInstanceName) {
|
||||
this.setActiveInstance(selectedInstanceName);
|
||||
this.player.sendMessage({ translate: 'construct.materials.grabber.menu.success', with: [selectedInstanceName] });
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { ActionFormData } from "@minecraft/server-ui";
|
||||
import { MenuFormBuilder } from "../MenuFormBuilder";
|
||||
import { structureCollection } from "../Structure/StructureCollection";
|
||||
import { instanceCollection } from "../Instance/InstanceCollection";
|
||||
import { Builders } from "../Builder/Builders";
|
||||
|
||||
export class MaterialGrabberFormBuilder {
|
||||
static menuTitle = { rawtext: [MenuFormBuilder.menuTitle, { translate: 'construct.materials.grabber.menu.title' }] };
|
||||
|
||||
static buildInstanceSelector(player) {
|
||||
static buildInstanceSelector(player, instanceNames) {
|
||||
const allInstanceNameForm = new ActionFormData()
|
||||
.title(this.menuTitle);
|
||||
const currInstanceName = Builders.get(player.id).materialInstanceName;
|
||||
@@ -18,8 +18,8 @@ export class MaterialGrabberFormBuilder {
|
||||
body.rawtext.push({ text: '\n' });
|
||||
body.rawtext.push({ translate: 'construct.materials.grabber.menu.selectinstance' });
|
||||
allInstanceNameForm.body(body);
|
||||
structureCollection.getInstanceNames().forEach(instanceName => {
|
||||
allInstanceNameForm.button(`§2${instanceName}`);
|
||||
instanceNames.forEach(instanceName => {
|
||||
allInstanceNameForm.button(`${instanceCollection.get(instanceName).isEnabled() ? '§2' : '§c'}${instanceName}`);
|
||||
});
|
||||
return allInstanceNameForm;
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import { InstanceNotPlacedError } from "../Errors/InstanceNotPlacedError";
|
||||
|
||||
class StructureMaterials {
|
||||
instance;
|
||||
materials;
|
||||
#materials;
|
||||
|
||||
constructor(instance) {
|
||||
this.instance = instance;
|
||||
this.materials = {};
|
||||
this.#materials = {};
|
||||
}
|
||||
|
||||
refresh() {
|
||||
@@ -31,26 +31,26 @@ class StructureMaterials {
|
||||
}
|
||||
|
||||
get materials() {
|
||||
return this.materials;
|
||||
return this.#materials;
|
||||
}
|
||||
|
||||
get(itemType) {
|
||||
return this.materials[itemType];
|
||||
return this.#materials[itemType];
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return Object.keys(this.materials).length === 0;
|
||||
return Object.keys(this.#materials).length === 0;
|
||||
}
|
||||
|
||||
has(itemType) {
|
||||
return this.materials[itemType] !== undefined;
|
||||
return this.#materials[itemType] !== undefined;
|
||||
}
|
||||
|
||||
remove(itemType, amount) {
|
||||
if (!this.materials[itemType]) return;
|
||||
this.materials[itemType].count -= amount;
|
||||
if (this.materials[itemType].count <= 0)
|
||||
delete this.materials[itemType];
|
||||
if (!this.#materials[itemType]) return;
|
||||
this.#materials[itemType].count -= amount;
|
||||
if (this.#materials[itemType].count <= 0)
|
||||
delete this.#materials[itemType];
|
||||
}
|
||||
|
||||
*populateAll() {
|
||||
@@ -78,21 +78,21 @@ class StructureMaterials {
|
||||
}
|
||||
|
||||
countBlock(block) {
|
||||
const itemStack = block?.getItemStack();
|
||||
const itemStack = block?.permutation.getItemStack();
|
||||
const typeId = itemStack?.typeId;
|
||||
if (!typeId) return;
|
||||
if (!this.materials[typeId])
|
||||
this.materials[typeId] = { count: 0, stackSize: itemStack.maxAmount };
|
||||
this.materials[typeId].count++;
|
||||
if (!this.#materials[typeId])
|
||||
this.#materials[typeId] = { count: 0, stackSize: itemStack.maxAmount };
|
||||
this.#materials[typeId].count++;
|
||||
}
|
||||
|
||||
clear() {
|
||||
for (const key in this.materials)
|
||||
delete this.materials[key];
|
||||
for (const key in this.#materials)
|
||||
delete this.#materials[key];
|
||||
}
|
||||
|
||||
formatString(otherMaterials = void 0) {
|
||||
const materials = otherMaterials || this.materials;
|
||||
const materials = otherMaterials || this.#materials;
|
||||
let message = { rawtext: [] };
|
||||
const sortedTypes = Object.keys(materials).sort(
|
||||
(a, b) => materials[b].count - materials[a].count
|
||||
@@ -126,7 +126,7 @@ class StructureMaterials {
|
||||
}
|
||||
|
||||
getMaterialsDifference(container) {
|
||||
const missingMaterials = JSON.parse(JSON.stringify(this.materials));
|
||||
const missingMaterials = JSON.parse(JSON.stringify(this.#materials));
|
||||
for (let slotIndex = 0; slotIndex < container.size; slotIndex++) {
|
||||
const slot = container.getSlot(slotIndex);
|
||||
if (slot.hasItem()) {
|
||||
|
||||
Reference in New Issue
Block a user