How to set item in specific slot of entity

Started by Cancerous Cactus on

Topic category: Help with modding (Java Edition)

Last seen on 05:07, 20. Oct 2024
Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to set item in specific slot of entity

In my mod, I am making a container of magic energy as an item, called a magic battery. I will have many wands and such that will use this magic battery's energy from the user's inventory. I have come across a problem: I cannot directly set an NBT tag on an item from the player's inventory, only a copy of such item. I have thought of a workaround, in which I use a custom return-type procedure that uses an itemstack variable that I set to the already-existing magic battery. I apply changes to the magic level of the variable via NBT tags, then replace the existing battery with the variable. My problem with that is that I can't specify the slot the new battery is put in, so it just places it in the player's next available slot.