How to set item in specific slot of entity

Started by Cancerous Cactus on

Topic category: Help with Minecraft modding (Java Edition)

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.

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Huh? This worked for me...? …
Sun, 10/20/2024 - 14:09

Huh? This worked for me...?

It just updates the NBT doesn't return a copy or anything

Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
friyes... What trigger is…
Sun, 10/20/2024 - 17:42

friyes...

What trigger is this procedure under?

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
rightclick with item? or do…
Sun, 10/20/2024 - 17:44

rightclick with item? or do you mean category? I just search "data"

Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The problem is that I use a…
Sun, 10/20/2024 - 17:46

The problem is that I use a right-click-triggered procedure for a wand, then must change NBT data on a different item.

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, you should be able to…
Sun, 10/20/2024 - 17:57

Okay, you should be able to change Provided Itemstack to that then...

Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can create an itemstack…
Sun, 10/20/2024 - 18:27

I can create an itemstack variable and set it to a copy of the item from a certain slot (I have a method to find which slot the magic battery is in), then set an NBT variable on the variable. After that, I replace the old magic battery with the variable, but because there is no way to specify the slot that the variable goes in, it moves the battery to the next available slot. This annoyingly results in the magic battery appearing in the player's hotbar sometimes after using any wand.