#Removing the item on inventory and adding another item

1 messages · Page 1 of 1 (latest)

paper falcon
#

🤔

#

You will need to use the interact with entity event

#

And obtain the inventory of both entities

paper falcon
#

Actually you may be able to avoid using scripts for this

#

Could be directly in the entity behavior

lucid niche
#
world.afterEvents.playerInteractWithEntity.subscribe(({ player, target: entity, itemStack }) => {

if (itemStack?.typeId === "item:test1" && entity?.typeId === "entity:test") {
const inv = player.getComponent("inventory").container;
//clears the item from slot
inv.setItem(player.selectedSlotIndex, undefined);
//give item
player.runCommand("give @s item:test2");
};
});```
#

this might be not the optimized way

#

bcoz i forgot how to create new ItemStack instance and put typeId

#

so i used commands