Changing floating item NBT

Started by Codmander on

Topic category: Advanced modding

Last seen on 05:05, 19. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Changing floating item NBT

Hi there, I'm trying to make a mod where certain items are binded to players, and when player dies, all the binded items lose their owner. I store an itemstack variable with "player persistent" scope, where i put the item that is supposed to bind, and when player dies, i simply change this itemstack's owner to an epmty string as well as the "owned" boolean to false. In fact, these values seem not to change. This may be caused by either the fact i use variables of an inalive player, the fact that while I am trying to change variables, the item is floating in air or something completely different.

Last seen on 10:38, 22. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The tricky part is knowing…
Wed, 01/17/2024 - 14:48

The tricky part is knowing when the correct player has died, since it's hard to save the player ID itself as NBT. When the player dies, make two procedures- the first one should just wait one or two ticks before executing the second procedure. The second procedure should run an entity iterator with a medium sized radius that checks if the entity iterator is an itemstack entity, and, if it is, sets a local itemstack variable to the item entity converted to an itemstack, (using the 'convert item entity to itemstack function.) It should then set the NBT tag of the local item variable to false, despawn the item entity, and drop an item at its position using the local item variable. (Essentially, for each item nearby, you despawn it and replace it with a copy of that item that has the NBT tag set to false.) 

This would, of course, cause problems if one player drops an item and a different player dies nearby, but saving player IDs is a little above my paygrade, and this will probably work in most cases.

Last seen on 05:05, 19. Apr 2024
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks very much for your…
Wed, 01/31/2024 - 19:40

Thanks very much for your help a lot! It's actually possible to save tha ovners nickname to make sure the item bleonged to him. Anyway, I found a way around by player knowing when he last died, and item knowing when it's owner used it. As an effect, when one tries to use this item, I can check If the ownership is still actual by comparing two values.