#How to restrict item within inventory slot??
1 messages · Page 1 of 1 (latest)
inside a tick event track all players and their said slot
if the item is not what u want move it to any empty slot
const inventory = player.getComponent("inventory").container
for (let i = 0; i < inventory.size; i++) {
const item = inventory.getItem(i)
if (item?.typeId !== "minecraft:apple") {
inventory.setItem(i)
}
}
Thanks
Sorry if the question is obvious, but how could I do it for a specific slot?
Just delete the for loop and specify on the .getItem()
const inventory = player.getComponent("inventory").container
const item = inventory.getItem(0) // First slot of the inventory
if (item?.typeId !== "minecraft:apple") {
inventory.setItem(i)
}
Thanks
Inventory | How to restrict item within inventory slot??