Spawning entity based upon item in GUI slot

Started by thunderingstatic on

Topic category: Help with MCreator software

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Spawning entity based upon item in GUI slot

Hi! First time posting here, so feel free to redirect me to a different forum section if I put it in the wrong place.

I’m currently working on a party system for a mod of mine, where it spawns in a tamed “party member” (pet) in when an item is in a specific slot of a new GUI. I’ve gotten everything to work up until this point (entity showing up in the GUI for the first party member, GUI keybind) but I am honestly stuck on this. If anyone has any ideas for alternatives, please let me know- I’d love to fix this and get my mod working properly!

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The problem you're likely…
Wed, 10/25/2023 - 02:31

The problem you're likely running into is that GUIs don't actually have permanent storage slots unless they're bound to something- meaning that unless you have to interact with some sort of storage block that can save the GUI's contents as NBT data, the item will be destroyed or returned to your inventory as soon as the GUI closes.

If you're not too attatched to the GUI system, you might consider making an item that spawns the entity, and then some sort of system to despawn the entity and put the item back in your inventory, which would be much easier to manage. ...But if you really want it to work this way, that could probably work too. You could also try making an item with inventory slots that manages the party system, (items like shulker boxes and bundles can also save contents). I haven't personally worked with storage items before, but this could probably work. 

If you really, really want a GUI that can save contents, you could create a player persistant itemstack variable for each slot of your GUI, and, whenever an item is added or removed from a slot of the GUI, updated the variables to the itemstack currently there. (Including air, or no itemstack.) Then, whenever the GUI is closed, be sure to destroy its contents instead of returning them, and whenever the GUI is opened, use the itemstack variables to place the correct saved item in each slot. You can then reference these variables even when the GUI is closed, and differentiate between which player they're assigned to. If you want these to be persistant even upon death, use persistant variables- conversely, if you want it to reset on death, use lifetime variables instead. This is a bit more complicated, but should be manageable if you've got a basic background on how to work with variables and stuff.