Material grabber functional
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { MaterialsFormBuilder } from './MaterialsFormBuilder';
|
||||
import { forceShow } from '../../utils';
|
||||
import { Builders } from '../Builder/Builders';
|
||||
import { structureCollection } from '../Structure/StructureCollection';
|
||||
|
||||
export class MaterialsForm {
|
||||
constructor(player) {
|
||||
@@ -10,14 +11,13 @@ export class MaterialsForm {
|
||||
|
||||
show() {
|
||||
try {
|
||||
return forceShow(this.player, MaterialsFormBuilder.buildInstanceSelector()).then((response) => {
|
||||
return forceShow(this.player, MaterialsFormBuilder.buildInstanceSelector(this.player)).then((response) => {
|
||||
if (response.canceled)
|
||||
return;
|
||||
let selection = response.selection;
|
||||
const selectedInstanceName = structureCollection.getInstanceNames()[selection];
|
||||
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
||||
if (selectedInstanceName) {
|
||||
this.setActiveInstance(selectedInstanceName);
|
||||
this.player.sendMessage(`§8Selected instance for material grabber: §2${selectedInstanceName}`);
|
||||
this.player.sendMessage(`§7Selected instance for material grabber: §2${selectedInstanceName}`);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
import { ActionFormData } from "@minecraft/server-ui";
|
||||
import { MenuFormBuilder } from "../MenuFormBuilder";
|
||||
import { structureCollection } from "../Structure/StructureCollection";
|
||||
import { Builders } from "../Builder/Builders";
|
||||
|
||||
export class InstanceFormBuilder {
|
||||
menuTitle = MenuFormBuilder.menuTitle + ' Material Grabber';
|
||||
export class MaterialsFormBuilder {
|
||||
static menuTitle = MenuFormBuilder.menuTitle + ' Material Grabber';
|
||||
|
||||
static buildInstanceSelector() {
|
||||
static buildInstanceSelector(player) {
|
||||
const allInstanceNameForm = new ActionFormData()
|
||||
.title(this.menuTitle)
|
||||
.body('Select an instance:');
|
||||
.title(this.menuTitle);
|
||||
const currInstanceName = Builders.get(player.id).materialInstanceName;
|
||||
let body = '§7Current instance: ';
|
||||
if (currInstanceName)
|
||||
body += `§2${currInstanceName}`;
|
||||
else
|
||||
body += '§7None';
|
||||
body += '\n§7Select an instance:';
|
||||
allInstanceNameForm.body(body);
|
||||
structureCollection.getInstanceNames().forEach(instanceName => {
|
||||
allInstanceNameForm.button(`§2${instanceName}`);
|
||||
});
|
||||
|
||||
@@ -9,12 +9,45 @@ class StructureMaterials {
|
||||
|
||||
refresh() {
|
||||
this.clear();
|
||||
this.populateActive();
|
||||
this.populateInstance();
|
||||
}
|
||||
|
||||
populateInstance() {
|
||||
try {
|
||||
if (this.instance.hasLocation())
|
||||
this.populateActive();
|
||||
else
|
||||
this.populateAll();
|
||||
} catch (e) {
|
||||
if (e.name === 'InstanceNotPlacedError')
|
||||
this.clear();
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
get(itemType) {
|
||||
return this.materials[itemType];
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return Object.keys(this.materials).length === 0;
|
||||
}
|
||||
|
||||
has(itemType) {
|
||||
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];
|
||||
}
|
||||
|
||||
populateAll() {
|
||||
for (const layer = 0; layer < this.instance.getMaxLayer(); layer++)
|
||||
this.getLayer(layer)
|
||||
for (let layer = 0; layer < this.instance.getMaxLayer(); layer++)
|
||||
this.populateLayer(layer)
|
||||
}
|
||||
|
||||
populateLayer(layer) {
|
||||
|
||||
Reference in New Issue
Block a user