Merge branch 'material-list'
This commit is contained in:
@@ -10,5 +10,6 @@ export const InstanceButtons = Object.freeze({
|
|||||||
PreviousLayer: 'Decrease Layer',
|
PreviousLayer: 'Decrease Layer',
|
||||||
Move: 'Move Here',
|
Move: 'Move Here',
|
||||||
Statistics: 'Statistics',
|
Statistics: 'Statistics',
|
||||||
Settings: 'Settings'
|
Settings: 'Settings',
|
||||||
|
Materials: 'Material List'
|
||||||
});
|
});
|
||||||
@@ -12,8 +12,9 @@ export class InstanceForm {
|
|||||||
InstanceButtons.NextLayer,
|
InstanceButtons.NextLayer,
|
||||||
InstanceButtons.PreviousLayer,
|
InstanceButtons.PreviousLayer,
|
||||||
InstanceButtons.Move,
|
InstanceButtons.Move,
|
||||||
InstanceButtons.Statistics,
|
|
||||||
InstanceButtons.Settings,
|
InstanceButtons.Settings,
|
||||||
|
InstanceButtons.Statistics,
|
||||||
|
InstanceButtons.Materials,
|
||||||
InstanceButtons.Rename,
|
InstanceButtons.Rename,
|
||||||
InstanceButtons.Disable
|
InstanceButtons.Disable
|
||||||
],
|
],
|
||||||
@@ -90,15 +91,18 @@ export class InstanceForm {
|
|||||||
this.instance.decreaseLayer();
|
this.instance.decreaseLayer();
|
||||||
new InstanceForm(this.player, this.instanceName);
|
new InstanceForm(this.player, this.instanceName);
|
||||||
break;
|
break;
|
||||||
case InstanceButtons.Settings:
|
|
||||||
this.settingsForm();
|
|
||||||
break;
|
|
||||||
case InstanceButtons.Move:
|
case InstanceButtons.Move:
|
||||||
this.instance.move(this.player.dimension.id, this.player.location);
|
this.instance.move(this.player.dimension.id, this.player.location);
|
||||||
break;
|
break;
|
||||||
|
case InstanceButtons.Settings:
|
||||||
|
this.settingsForm();
|
||||||
|
break;
|
||||||
case InstanceButtons.Statistics:
|
case InstanceButtons.Statistics:
|
||||||
this.statisticsForm();
|
this.statisticsForm();
|
||||||
break;
|
break;
|
||||||
|
case InstanceButtons.Materials:
|
||||||
|
this.materialsForm();
|
||||||
|
break;
|
||||||
case InstanceButtons.MainMenu:
|
case InstanceButtons.MainMenu:
|
||||||
new MenuForm(this.player, { jumpToInstance: false });
|
new MenuForm(this.player, { jumpToInstance: false });
|
||||||
break;
|
break;
|
||||||
@@ -160,7 +164,15 @@ export class InstanceForm {
|
|||||||
this.instance.setVerifierDistance(5);
|
this.instance.setVerifierDistance(5);
|
||||||
else
|
else
|
||||||
this.instance.setVerifierDistance(0);
|
this.instance.setVerifierDistance(0);
|
||||||
this.instance.setLayer(parseInt(response.formValues[3]));
|
this.instance.setLayer(parseInt(response.formValues[2]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
materialsForm(onlyShowMissingMaterials = false) {
|
||||||
|
forceShow(this.player, InstanceFormBuilder.buildMaterialList(this.instance, onlyShowMissingMaterials, this.player)).then((response) => {
|
||||||
|
if (response.canceled) return;
|
||||||
|
if (response.selection === 0)
|
||||||
|
this.materialsForm(!onlyShowMissingMaterials);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import { ActionFormData, ModalFormData } from '@minecraft/server-ui';
|
|||||||
import { MenuFormBuilder } from '../MenuFormBuilder';
|
import { MenuFormBuilder } from '../MenuFormBuilder';
|
||||||
import { StructureVerifier } from '../Verifier/StructureVerifier';
|
import { StructureVerifier } from '../Verifier/StructureVerifier';
|
||||||
import { StructureStatistics } from '../Structure/StructureStatistics';
|
import { StructureStatistics } from '../Structure/StructureStatistics';
|
||||||
import { TicksPerSecond } from '@minecraft/server';
|
import { EntityComponentTypes, TicksPerSecond } from '@minecraft/server';
|
||||||
|
|
||||||
export class InstanceFormBuilder {
|
export class InstanceFormBuilder {
|
||||||
static structureVerifier;
|
static structureVerifier;
|
||||||
@@ -46,9 +46,39 @@ export class InstanceFormBuilder {
|
|||||||
return new ModalFormData()
|
return new ModalFormData()
|
||||||
.title(MenuFormBuilder.menuTitle)
|
.title(MenuFormBuilder.menuTitle)
|
||||||
.toggle('Block Validation', { defaultValue: instance.options.verifier.isEnabled, tooltip: 'Shows missing and incorrect block overlay.' })
|
.toggle('Block Validation', { defaultValue: instance.options.verifier.isEnabled, tooltip: 'Shows missing and incorrect block overlay.' })
|
||||||
.toggle('Distance-Based Block Validation', { defaultValue: instance.verifier.getTrackPlayerDistance() !== 0, tooltip: `If enabled, the verifier will only check within ${instance.verifier.getTrackPlayerDistance()} blocks of the player. This should stay enabled unless your structure is very small.` })
|
.toggle('Distance-Based Block Validation', { defaultValue: instance.verifier.getTrackPlayerDistance() !== 0, tooltip: `If enabled, the verifier will only check within ${instance.verifier.getTrackPlayerDistance()} blocks of the player. This should stay enabled unless your structure is very small or in layer mode.` })
|
||||||
.label('Use the slider to select the layer. Use 0 for all layers.')
|
.slider("Layer", 0, instance.getMaxLayer(), { defaultValue: instance.getLayer(), valueStep: 1, tooltip: 'Changes the active layer. Use 0 for all layers.' })
|
||||||
.slider("Layer", 0, instance.getMaxLayer(), { defaultValue: instance.getLayer(), valueStep: 1 })
|
|
||||||
.submitButton('§2Apply');
|
.submitButton('§2Apply');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static buildMaterialList(instance, onlyMissing = false, player = false) {
|
||||||
|
const materials = instance.getActiveMaterials();
|
||||||
|
const form = new ActionFormData()
|
||||||
|
.title(MenuFormBuilder.menuTitle)
|
||||||
|
const bodyText = { rawtext: [] };
|
||||||
|
let buttonText = void 0;
|
||||||
|
if (onlyMissing) {
|
||||||
|
const inventoryContainer = player?.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||||
|
if (!inventoryContainer) {
|
||||||
|
form.body('§cNo player inventory found.');
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
bodyText.rawtext.push({ text: `§cMaterials Missing From Inventory:` });
|
||||||
|
if (instance.hasLayerSelected())
|
||||||
|
bodyText.rawtext.push({ text: ` §7(layer ${instance.getLayer()})` });
|
||||||
|
bodyText.rawtext.push({ text: `§f\n\n` });
|
||||||
|
bodyText.rawtext.push(materials.formatString(materials.getMaterialsDifference(inventoryContainer)));
|
||||||
|
buttonText = "Show All Materials";
|
||||||
|
} else {
|
||||||
|
bodyText.rawtext.push({ text: `§aAll Materials:` });
|
||||||
|
if (instance.hasLayerSelected())
|
||||||
|
bodyText.rawtext.push({ text: ` §7(layer ${instance.getLayer()})` });
|
||||||
|
bodyText.rawtext.push({ text: `§f\n\n` });
|
||||||
|
bodyText.rawtext.push(materials.formatString());
|
||||||
|
buttonText = "Show Missing Materials";
|
||||||
|
}
|
||||||
|
form.body(bodyText);
|
||||||
|
form.button(buttonText);
|
||||||
|
return form;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
import { MaterialsFormBuilder } from './MaterialsFormBuilder';
|
import { MaterialGrabberFormBuilder } from './MaterialGrabberFormBuilder';
|
||||||
import { forceShow } from '../../utils';
|
import { forceShow } from '../../utils';
|
||||||
import { Builders } from '../Builder/Builders';
|
import { Builders } from '../Builder/Builders';
|
||||||
import { structureCollection } from '../Structure/StructureCollection';
|
import { structureCollection } from '../Structure/StructureCollection';
|
||||||
|
|
||||||
export class MaterialsForm {
|
export class MaterialGrabberForm {
|
||||||
constructor(player) {
|
constructor(player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.show();
|
this.show();
|
||||||
@@ -11,7 +11,7 @@ export class MaterialsForm {
|
|||||||
|
|
||||||
show() {
|
show() {
|
||||||
try {
|
try {
|
||||||
return forceShow(this.player, MaterialsFormBuilder.buildInstanceSelector(this.player)).then((response) => {
|
return forceShow(this.player, MaterialGrabberFormBuilder.buildInstanceSelector(this.player)).then((response) => {
|
||||||
if (response.canceled)
|
if (response.canceled)
|
||||||
return;
|
return;
|
||||||
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
const selectedInstanceName = structureCollection.getInstanceNames()[response.selection];
|
||||||
+1
-1
@@ -3,7 +3,7 @@ import { MenuFormBuilder } from "../MenuFormBuilder";
|
|||||||
import { structureCollection } from "../Structure/StructureCollection";
|
import { structureCollection } from "../Structure/StructureCollection";
|
||||||
import { Builders } from "../Builder/Builders";
|
import { Builders } from "../Builder/Builders";
|
||||||
|
|
||||||
export class MaterialsFormBuilder {
|
export class MaterialGrabberFormBuilder {
|
||||||
static menuTitle = MenuFormBuilder.menuTitle + ' Material Grabber';
|
static menuTitle = MenuFormBuilder.menuTitle + ' Material Grabber';
|
||||||
|
|
||||||
static buildInstanceSelector(player) {
|
static buildInstanceSelector(player) {
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { ItemStack } from "@minecraft/server";
|
||||||
|
|
||||||
class StructureMaterials {
|
class StructureMaterials {
|
||||||
instance;
|
instance;
|
||||||
materials;
|
materials;
|
||||||
@@ -74,28 +76,54 @@ class StructureMaterials {
|
|||||||
delete this.materials[key];
|
delete this.materials[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
formatString(otherMaterials = void 0) {
|
||||||
let message = [];
|
const materials = otherMaterials || this.materials;
|
||||||
for (const blockType in this.materials) {
|
let message = { rawtext: [] };
|
||||||
let count = this.materials[blockType].count;
|
const sortedTypes = Object.keys(materials).sort(
|
||||||
|
(a, b) => materials[b].count - materials[a].count
|
||||||
|
);
|
||||||
|
for (const blockType of sortedTypes) {
|
||||||
|
let count = materials[blockType].count;
|
||||||
let countStr = '';
|
let countStr = '';
|
||||||
const stackSize = this.materials[blockType].stackSize;
|
const stackSize = materials[blockType].stackSize;
|
||||||
const fullShulker = 27 * stackSize;
|
const fullShulker = 27 * stackSize;
|
||||||
if (count >= fullShulker)
|
if (count >= fullShulker)
|
||||||
countStr = `${Math.floor(count / fullShulker)} \uE200`;
|
countStr = `${Math.floor(count / fullShulker)}\uE200`;
|
||||||
if (count > fullShulker)
|
if (count > fullShulker && count % fullShulker > 0)
|
||||||
countStr += ' + ';
|
countStr += ' + ';
|
||||||
count %= fullShulker;
|
count %= fullShulker;
|
||||||
if (count >= stackSize)
|
if (count >= stackSize) {
|
||||||
countStr += `${Math.floor(count / stackSize)} stack`;
|
const numStacks = Math.floor(count / stackSize);
|
||||||
if (count > stackSize)
|
countStr += `${numStacks} stack`;
|
||||||
|
if (numStacks > 1)
|
||||||
|
countStr += 's';
|
||||||
|
}
|
||||||
|
if (count > stackSize && count % stackSize > 0)
|
||||||
countStr += ' + ';
|
countStr += ' + ';
|
||||||
count %= stackSize;
|
count %= stackSize;
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
countStr += count;
|
countStr += count;
|
||||||
message.push(` ${blockType}: ${countStr}`);
|
message.rawtext.push({ text: '§3' });
|
||||||
|
message.rawtext.push({ translate: new ItemStack(blockType).localizationKey })
|
||||||
|
message.rawtext.push({ text: `§f: ${countStr}\n` });
|
||||||
}
|
}
|
||||||
return message.sort().join('\n');
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
getMaterialsDifference(container) {
|
||||||
|
const missingMaterials = JSON.parse(JSON.stringify(this.materials));
|
||||||
|
for (let slotIndex = 0; slotIndex < container.size; slotIndex++) {
|
||||||
|
const slot = container.getSlot(slotIndex);
|
||||||
|
if (slot.hasItem()) {
|
||||||
|
const itemType = slot.getItem().typeId;
|
||||||
|
if (!missingMaterials[itemType])
|
||||||
|
continue;
|
||||||
|
missingMaterials[itemType].count -= slot.amount;
|
||||||
|
if (missingMaterials[itemType].count <= 0)
|
||||||
|
delete missingMaterials[itemType];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missingMaterials;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
||||||
import { EntityComponentTypes, ItemStack, Player, world, system } from '@minecraft/server';
|
import { EntityComponentTypes, ItemStack, Player, world, system } from '@minecraft/server';
|
||||||
import { MaterialsForm } from '../classes/Materials/MaterialsForm';
|
import { MaterialGrabberForm } from '../classes/Materials/MaterialGrabberForm';
|
||||||
import { Builders } from '../classes/Builder/Builders';
|
import { Builders } from '../classes/Builder/Builders';
|
||||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ function onItemUse(event) {
|
|||||||
if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.source.id))
|
if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.source.id))
|
||||||
return;
|
return;
|
||||||
event.cancel = true;
|
event.cancel = true;
|
||||||
system.run(() => new MaterialsForm(event.source));
|
system.run(() => new MaterialGrabberForm(event.source));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPlayerInteract(event) {
|
function onPlayerInteract(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user