pull supply from smallest stack
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
import { BuilderOption } from '../classes/Builder/BuilderOption';
|
||||||
import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, InputMode, ItemStack, system, world } from '@minecraft/server';
|
import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, ItemStack, system, world } from '@minecraft/server';
|
||||||
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks,
|
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks,
|
||||||
blockIdToItemStackMap } from '../data';
|
blockIdToItemStackMap } from '../data';
|
||||||
import { placeBlock } from '../utils';
|
import { placeBlock, fetchMatchingItemSlot } from '../utils';
|
||||||
import { Raycaster } from '../classes/Raycaster';
|
import { Raycaster } from '../classes/Raycaster';
|
||||||
import { Builders } from '../classes/Builder/Builders';
|
import { Builders } from '../classes/Builder/Builders';
|
||||||
|
|
||||||
@@ -148,16 +148,3 @@ function getPlaceableItemStack(structureBlock) {
|
|||||||
const newItemId = blockIdToItemStackMap[blockId];
|
const newItemId = blockIdToItemStackMap[blockId];
|
||||||
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,11 +21,15 @@ export function fetchMatchingItemSlot(entity, itemToMatchId) {
|
|||||||
const inventory = entity.getComponent(EntityComponentTypes.Inventory)?.container;
|
const inventory = entity.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||||
if (!inventory)
|
if (!inventory)
|
||||||
return void 0;
|
return void 0;
|
||||||
|
let smallestItemSlot;
|
||||||
for (let index = 0; index < inventory.size; index++) {
|
for (let index = 0; index < inventory.size; index++) {
|
||||||
const itemSlot = inventory.getSlot(index);
|
const itemSlot = inventory.getSlot(index);
|
||||||
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId)
|
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId) {
|
||||||
return itemSlot;
|
if (!smallestItemSlot || itemSlot.amount < smallestItemSlot.amount)
|
||||||
|
smallestItemSlot = itemSlot;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return smallestItemSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume = void 0) {
|
export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume = void 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user