configure for regolith
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
||||
import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, ItemStack, system, world } from '@minecraft/server';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks,
|
||||
blockIdToItemStackMap } from '../data';
|
||||
import { fetchMatchingItemSlot, placeBlock } from '../utils';
|
||||
import { Builders } from '../classes/Builder/Builders';
|
||||
|
||||
const builderOption = new BuilderOption({
|
||||
identifier: 'easyPlace',
|
||||
displayName: 'Easy Place',
|
||||
description: 'Always place the correct structure block.',
|
||||
howToUse: "Hold the Easy Place item in your offhand and place blocks in a structure to have them be corrected automatically.",
|
||||
onEnableCallback: (playerId) => giveActionItem(playerId),
|
||||
onDisableCallback: (playerId) => removeActionItem(playerId)
|
||||
});
|
||||
|
||||
function giveActionItem(playerId) {
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
const itemStack = new ItemStack('construct:easy_place');
|
||||
if (!container.contains(itemStack)) {
|
||||
const remainingItemStack = container.addItem(itemStack);
|
||||
if (remainingItemStack)
|
||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||
}
|
||||
}
|
||||
|
||||
function removeActionItem(playerId) {
|
||||
const builder = Builders.get(playerId);
|
||||
if (builder.isOptionEnabled('fastEasyPlace'))
|
||||
return;
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
for (let i = 0; i < container.size; i++) {
|
||||
const itemStack = container.getItem(i);
|
||||
if (itemStack?.typeId === 'construct:easy_place')
|
||||
container.setItem(i, void 0);
|
||||
}
|
||||
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
||||
const offhandItemStack = equipment?.getEquipment(EquipmentSlot.Offhand);
|
||||
if (offhandItemStack?.typeId === 'construct:easy_place') {
|
||||
equipment.setEquipment(EquipmentSlot.Offhand, void 0);
|
||||
}
|
||||
}
|
||||
|
||||
world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock);
|
||||
|
||||
function onPlayerPlaceBlock(event) {
|
||||
const { player, block } = event;
|
||||
if (!player || !block || !builderOption.isEnabled(player.id) || !isHoldingActionItem(player)) return;
|
||||
const structureBlock = structureCollection.fetchStructureBlock(block.dimension.id, block.location);
|
||||
if (!structureBlock)
|
||||
return;
|
||||
tryPlaceBlock(event, player, block, structureBlock);
|
||||
}
|
||||
|
||||
function isHoldingActionItem(player) {
|
||||
const offhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Offhand);
|
||||
if (!offhandItemStack)
|
||||
return false;
|
||||
return offhandItemStack.typeId === 'construct:easy_place';
|
||||
}
|
||||
|
||||
function tryPlaceBlock(event, player, block, structureBlock) {
|
||||
if (shouldPreventAction(player, structureBlock))
|
||||
return preventAction(event, player);
|
||||
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
||||
if (player.getGameMode() === GameMode.Creative) {
|
||||
event.cancel = true;
|
||||
placeBlock(player, block, structureBlock);
|
||||
} else if (player.getGameMode() === GameMode.Survival) {
|
||||
structureBlock = tryConvertToDefaultState(structureBlock);
|
||||
tryPlaceBlockSurvival(event, player, block, structureBlock);
|
||||
}
|
||||
}
|
||||
|
||||
function shouldPreventAction(player, structureBlock) {
|
||||
return isBannedBlock(player, structureBlock);
|
||||
}
|
||||
|
||||
function preventAction(event, player) {
|
||||
event.cancel = true;
|
||||
system.run(() => {
|
||||
player.onScreenDisplay.setActionBar('§cAction prevented by Easy Place.');
|
||||
});
|
||||
}
|
||||
|
||||
function isBannedBlock(player, structureBlock) {
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
if (bannedBlocks.includes(blockId))
|
||||
return true;
|
||||
if (bannedDimensionBlocks[player.dimension.id.replace('minecraft:', '')]?.includes(blockId))
|
||||
return true;
|
||||
const allowedStates = whitelistedBlockStates[blockId];
|
||||
if (allowedStates) {
|
||||
for (const [stateKey, stateValue] of Object.entries(allowedStates)) {
|
||||
if (structureBlock.getState(stateKey) !== stateValue)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function tryConvertBannedToValidBlock(structureBlock) {
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
if (Object.keys(bannedToValidBlockMap).includes(blockId))
|
||||
return BlockPermutation.resolve(bannedToValidBlockMap[blockId], structureBlock.getAllStates());
|
||||
return structureBlock;
|
||||
}
|
||||
|
||||
function tryConvertToDefaultState(structureBlock) {
|
||||
const newStates = {};
|
||||
for (const [stateKey, stateValue] of Object.entries(structureBlock.getAllStates())) {
|
||||
if (resetToBlockStates[stateKey] !== void 0 && stateValue !== resetToBlockStates[stateKey])
|
||||
newStates[stateKey] = resetToBlockStates[stateKey];
|
||||
else
|
||||
newStates[stateKey] = stateValue;
|
||||
}
|
||||
return BlockPermutation.resolve(structureBlock.type.id, newStates);
|
||||
}
|
||||
|
||||
function tryPlaceBlockSurvival(event, player, block, structureBlock) {
|
||||
const placeableItemStack = getPlaceableItemStack(structureBlock);
|
||||
const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId);
|
||||
if (itemSlotToUse) {
|
||||
event.cancel = true;
|
||||
placeBlock(player, block, structureBlock, itemSlotToUse);
|
||||
} else {
|
||||
preventAction(event, player);
|
||||
}
|
||||
}
|
||||
|
||||
function getPlaceableItemStack(structureBlock) {
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
const newItemId = blockIdToItemStackMap[blockId];
|
||||
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
||||
import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, InputMode, ItemStack, system, world } from '@minecraft/server';
|
||||
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks,
|
||||
blockIdToItemStackMap } from '../data';
|
||||
import { placeBlock } from '../utils';
|
||||
import { Raycaster } from '../classes/Raycaster';
|
||||
import { Builders } from '../classes/Builder/Builders';
|
||||
|
||||
const PROCESS_INTERVAL = 2; // Fast Easy Place will attempt to place twice when at an interval of 1.
|
||||
|
||||
const builderOption = new BuilderOption({
|
||||
identifier: 'fastEasyPlace',
|
||||
displayName: 'Fast Easy Place',
|
||||
description: 'Place correct structure blocks just by looking at them.',
|
||||
howToUse: "Hold the Easy Place item in your main hand and look at blocks in a structure to place them.",
|
||||
onEnableCallback: (playerId) => giveActionItem(playerId),
|
||||
onDisableCallback: (playerId) => removeActionItem(playerId)
|
||||
});
|
||||
|
||||
function giveActionItem(playerId) {
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
const itemStack = new ItemStack('construct:easy_place');
|
||||
if (!container.contains(itemStack)) {
|
||||
const remainingItemStack = container.addItem(itemStack);
|
||||
if (remainingItemStack)
|
||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||
}
|
||||
}
|
||||
|
||||
function removeActionItem(playerId) {
|
||||
const builder = Builders.get(playerId);
|
||||
if (builder.isOptionEnabled('easyPlace'))
|
||||
return;
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
for (let i = 0; i < container.size; i++) {
|
||||
const itemStack = container.getItem(i);
|
||||
if (itemStack?.typeId === 'construct:easy_place')
|
||||
container.setItem(i, void 0);
|
||||
}
|
||||
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
||||
const offhandItemStack = equipment?.getEquipment(EquipmentSlot.Offhand);
|
||||
if (offhandItemStack?.typeId === 'construct:easy_place') {
|
||||
equipment.setEquipment(EquipmentSlot.Offhand, void 0);
|
||||
}
|
||||
}
|
||||
|
||||
system.runInterval(onTick, PROCESS_INTERVAL);
|
||||
world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock);
|
||||
|
||||
function onTick() {
|
||||
for (const player of world.getAllPlayers()) {
|
||||
if (player && builderOption.isEnabled(player.id))
|
||||
processEasyPlace(player);
|
||||
}
|
||||
}
|
||||
|
||||
function onPlayerInteractWithBlock(event) {
|
||||
const { player, block, isFirstEvent } = event;
|
||||
if (!player || !isFirstEvent || !block || !builderOption.isEnabled(player.id) || !isHoldingActionItem(player)) return;
|
||||
preventAction(event, player);
|
||||
}
|
||||
|
||||
function processEasyPlace(player) {
|
||||
if (!player || !isHoldingActionItem(player)) return;
|
||||
const structureBlock = Raycaster.getTargetedStructureBlock(player, { isFirst: true });
|
||||
if (!structureBlock)
|
||||
return;
|
||||
const worldBlock = player.dimension.getBlock(structureBlock.location);
|
||||
tryPlaceBlock(player, worldBlock, structureBlock.permutation);
|
||||
}
|
||||
|
||||
function preventAction(event, player) {
|
||||
event.cancel = true;
|
||||
system.run(() => {
|
||||
player.onScreenDisplay.setActionBar('§cAction prevented by Easy Place.');
|
||||
});
|
||||
}
|
||||
|
||||
function isHoldingActionItem(player) {
|
||||
const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand);
|
||||
if (!mainhandItemStack)
|
||||
return false;
|
||||
return mainhandItemStack.typeId === 'construct:easy_place';
|
||||
}
|
||||
|
||||
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(worldBlock)) return;
|
||||
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
||||
if (player.getGameMode() === GameMode.Creative) {
|
||||
placeBlock(player, worldBlock, structureBlock);
|
||||
} else if (player.getGameMode() === GameMode.Survival) {
|
||||
structureBlock = tryConvertToDefaultState(structureBlock);
|
||||
tryPlaceBlockSurvival(player, worldBlock, structureBlock);
|
||||
}
|
||||
}
|
||||
|
||||
function locationIsPlaceable(worldBlock) {
|
||||
return worldBlock.isAir;
|
||||
}
|
||||
|
||||
function isBannedBlock(player, structureBlock) {
|
||||
if (!structureBlock)
|
||||
return true;
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
if (bannedBlocks.includes(blockId))
|
||||
return true;
|
||||
if (bannedDimensionBlocks[player.dimension.id.replace('minecraft:', '')]?.includes(blockId))
|
||||
return true;
|
||||
const allowedStates = whitelistedBlockStates[blockId];
|
||||
if (allowedStates) {
|
||||
for (const [stateKey, stateValue] of Object.entries(allowedStates)) {
|
||||
if (structureBlock.getState(stateKey) !== stateValue)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function tryConvertBannedToValidBlock(structureBlock) {
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
if (Object.keys(bannedToValidBlockMap).includes(blockId))
|
||||
return BlockPermutation.resolve(bannedToValidBlockMap[blockId], structureBlock.getAllStates());
|
||||
return structureBlock;
|
||||
}
|
||||
|
||||
function tryConvertToDefaultState(structureBlock) {
|
||||
const newStates = {};
|
||||
for (const [stateKey, stateValue] of Object.entries(structureBlock.getAllStates())) {
|
||||
if (resetToBlockStates[stateKey] !== void 0 && stateValue !== resetToBlockStates[stateKey])
|
||||
newStates[stateKey] = resetToBlockStates[stateKey];
|
||||
else
|
||||
newStates[stateKey] = stateValue;
|
||||
}
|
||||
return BlockPermutation.resolve(structureBlock.type.id, newStates);
|
||||
}
|
||||
|
||||
function tryPlaceBlockSurvival(player, block, structureBlock) {
|
||||
const placeableItemStack = getPlaceableItemStack(structureBlock);
|
||||
const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId);
|
||||
if (itemSlotToUse)
|
||||
placeBlock(player, block, structureBlock, itemSlotToUse);
|
||||
}
|
||||
|
||||
function getPlaceableItemStack(structureBlock) {
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
const newItemId = blockIdToItemStackMap[blockId];
|
||||
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
|
||||
}
|
||||
|
||||
function fetchMatchingItemSlot(player, itemToMatchId) {
|
||||
if (!itemToMatchId)
|
||||
return void 0;
|
||||
const inventory = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
if (!inventory)
|
||||
return void 0;
|
||||
for (let index = 0; index < inventory.size; index++) {
|
||||
const itemSlot = inventory.getSlot(index);
|
||||
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId)
|
||||
return itemSlot;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
||||
import { EntityComponentTypes, ItemStack, Player, world, system, EquipmentSlot } from '@minecraft/server';
|
||||
import { MaterialGrabberForm } from '../classes/Materials/MaterialGrabberForm';
|
||||
import { Builders } from '../classes/Builder/Builders';
|
||||
import { structureCollection } from '../classes/Structure/StructureCollection';
|
||||
|
||||
const builderOption = new BuilderOption({
|
||||
identifier: 'materialGrabber',
|
||||
displayName: 'Material Grabber',
|
||||
description: 'Pulls structure items from inventories.',
|
||||
howToUse: "Interact with inventories using the Material Grabber item to pull structure items from them.",
|
||||
onEnableCallback: (playerId) => giveActionItem(playerId),
|
||||
onDisableCallback: (playerId) => removeActionItem(playerId)
|
||||
});
|
||||
|
||||
function giveActionItem(playerId) {
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
const itemStack = new ItemStack('construct:material_grabber');
|
||||
if (!container.contains(itemStack)) {
|
||||
const remainingItemStack = container.addItem(itemStack);
|
||||
if (remainingItemStack)
|
||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||
}
|
||||
}
|
||||
|
||||
function removeActionItem(playerId) {
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
for (let i = 0; i < container.size; i++) {
|
||||
const itemStack = container.getItem(i);
|
||||
if (itemStack?.typeId === 'construct:material_grabber')
|
||||
container.setItem(i, void 0);
|
||||
}
|
||||
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
||||
const offhandItemStack = equipment?.getEquipment(EquipmentSlot.Offhand);
|
||||
if (offhandItemStack?.typeId === 'construct:material_grabber') {
|
||||
equipment.setEquipment(EquipmentSlot.Offhand, void 0);
|
||||
}
|
||||
}
|
||||
|
||||
world.beforeEvents.itemUse.subscribe(onItemUse);
|
||||
world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteract);
|
||||
world.beforeEvents.playerInteractWithEntity.subscribe(onPlayerInteract);
|
||||
|
||||
function onItemUse(event) {
|
||||
if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.source?.id))
|
||||
return;
|
||||
openInstanceSelectionForm(event.source, event);
|
||||
}
|
||||
|
||||
function onPlayerInteract(event) {
|
||||
if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.player?.id))
|
||||
return;
|
||||
const player = event.player;
|
||||
const target = event.block || event.target;
|
||||
const focusedInstanceName = Builders.get(player.id).materialInstanceName;
|
||||
if (!focusedInstanceName) {
|
||||
openInstanceSelectionForm(player, event);
|
||||
} else {
|
||||
tryGrabMaterials(player, target, focusedInstanceName, event);
|
||||
}
|
||||
}
|
||||
|
||||
function isActionItem(itemStack) {
|
||||
return itemStack?.typeId === 'construct:material_grabber';
|
||||
}
|
||||
|
||||
function openInstanceSelectionForm(player, event) {
|
||||
event.cancel = true;
|
||||
system.run(() => new MaterialGrabberForm(player));
|
||||
}
|
||||
|
||||
function tryGrabMaterials(player, target, focusedInstanceName, event) {
|
||||
if (target instanceof Player)
|
||||
return;
|
||||
const materials = getActiveMaterials(focusedInstanceName);
|
||||
if (!materials)
|
||||
return;
|
||||
const targetContainer = target.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
if (!targetContainer || materials.isEmpty())
|
||||
return;
|
||||
event.cancel = true;
|
||||
system.run(() => transferMaterialsToPlayer(player, targetContainer, materials));
|
||||
}
|
||||
|
||||
function getActiveMaterials(focusedInstanceName) {
|
||||
const instance = structureCollection.get(focusedInstanceName);
|
||||
return instance?.getActiveMaterials();
|
||||
}
|
||||
|
||||
function transferMaterialsToPlayer(player, targetContainer, materials) {
|
||||
const playerContainer = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
if (!playerContainer)
|
||||
return;
|
||||
ignoreAlreadyGathered(materials, playerContainer);
|
||||
let transferCount = 0;
|
||||
for (let slotIndex = 0; slotIndex < targetContainer.size; slotIndex++) {
|
||||
const slot = targetContainer.getSlot(slotIndex);
|
||||
transferCount += tryTransferToPlayer(slot, playerContainer, materials);
|
||||
}
|
||||
playSoundEffect(player, transferCount);
|
||||
sendTransferMessage(player, transferCount);
|
||||
materials.refresh();
|
||||
}
|
||||
|
||||
function ignoreAlreadyGathered(materials, playerContainer) {
|
||||
for (let slotIndex = 0; slotIndex < playerContainer.size; slotIndex++) {
|
||||
const slot = playerContainer.getSlot(slotIndex);
|
||||
if (slot.hasItem()) {
|
||||
materials.remove(slot.typeId, slot.amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendTransferMessage(player, transferCount) {
|
||||
if (transferCount === 0) {
|
||||
player.onScreenDisplay.setActionBar('§7Grabbed 0 items.');
|
||||
} else if (transferCount === 1) {
|
||||
player.onScreenDisplay.setActionBar('§aGrabbed 1 item.');
|
||||
} else {
|
||||
player.onScreenDisplay.setActionBar(`§aGrabbed ${transferCount} item(s).`);
|
||||
}
|
||||
}
|
||||
|
||||
function tryTransferToPlayer(slot, playerContainer, materials) {
|
||||
if (slot.hasItem() && materials.has(slot.typeId)) {
|
||||
const grabAmount = Math.min(slot.amount, materials.get(slot.typeId).count);
|
||||
if (grabAmount > 0)
|
||||
return tryTransferAmountToPlayer(slot, playerContainer, materials, grabAmount);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function playSoundEffect(player, transferCount) {
|
||||
if (transferCount !== 0)
|
||||
player.dimension.playSound('block.itemframe.remove_item', player.location, { pitch: 1.2 });
|
||||
}
|
||||
|
||||
function tryTransferAmountToPlayer(slot, playerContainer, materials, grabAmount) {
|
||||
const itemStack = slot.getItem();
|
||||
if (canAddItem(playerContainer, itemStack)) {
|
||||
const itemStackToAdd = new ItemStack(itemStack.typeId, grabAmount);
|
||||
addItem(playerContainer, itemStackToAdd);
|
||||
materials.remove(itemStack.typeId, grabAmount);
|
||||
removeAmount(slot, grabAmount);
|
||||
return grabAmount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function removeAmount(slot, amount) {
|
||||
if (amount === slot.amount) {
|
||||
slot.setItem(void 0);
|
||||
} else {
|
||||
slot.amount -= amount;
|
||||
slot.setItem(slot.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
function canAddItem(inventory, itemStack) {
|
||||
if (inventory.emptySlotsCount !== 0) return true;
|
||||
for (let i = 0; i < inventory.size; i++) {
|
||||
const slot = inventory.getSlot(i);
|
||||
if (itemFitsInPartiallyFilledSlot(slot, itemStack)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function itemFitsInPartiallyFilledSlot(slot, itemStack) {
|
||||
return slot.hasItem() && slot.isStackableWith(itemStack) && slot.amount + itemStack.amount <= slot.maxAmount;
|
||||
}
|
||||
|
||||
function addItem(inventory, itemStack) {
|
||||
const isItemDeposited = partiallyFilledSlotPass(inventory, itemStack);
|
||||
if (!isItemDeposited)
|
||||
emptySlotPass(inventory, itemStack);
|
||||
|
||||
}
|
||||
|
||||
function partiallyFilledSlotPass(inventory, itemStack) {
|
||||
for (let slotNum = 0; slotNum < inventory.size; slotNum++) {
|
||||
const slot = inventory.getSlot(slotNum);
|
||||
if (isSlotAvailableForStacking(slot, itemStack)) {
|
||||
const remainderAmount = Math.max(0, (slot.amount + itemStack.amount) - slot.maxAmount);
|
||||
slot.amount += itemStack.amount - remainderAmount;
|
||||
if (remainderAmount > 0) {
|
||||
const remainderStack = new ItemStack(itemStack.typeId, remainderAmount);
|
||||
addItem(inventory, remainderStack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function emptySlotPass(inventory, itemStack) {
|
||||
for (let slotNum = 0; slotNum < inventory.size; slotNum++) {
|
||||
const slot = inventory.getSlot(slotNum);
|
||||
if (!slot.hasItem()) {
|
||||
slot.setItem(itemStack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSlotAvailableForStacking(slot, itemStack) {
|
||||
return slot.hasItem() && slot.isStackableWith(itemStack) && slot.amount !== slot.maxAmount;
|
||||
}
|
||||
Reference in New Issue
Block a user