Started by
kolokythi
on
Topic category: Help with Minecraft modding (Java Edition)
So as the title suggests I want to know if theres a way to take a players items when they enter a custom dimension and give them back when they leave with any items picked up in the custom dimension being taken when they leave and given back when they join
Hi!
I know two ways to do this, although there are probably more optimized methods.
First Method:
Create an
ItemStack
variable and aNumber
variable for each slot in the player's inventory (as player lifetime variables). When the player enters the dimension, these variables store the item's ID and quantity for each slot, then clear the inventory.And conversely, when the player leaves the dimension, each variable is copied back into its respective slot and reset to 0—or directly set to the value of the item in the player's inventory in the other dimension.
(To do this, you can use an empty variable as a temporary storage: it takes the value of the item in slot 1, the item in slot 1 is changed, then the variable assigned to slot 1 copies this temporary variable, and so on for the other slots.)
Second Method:
Create a GUI with the same number of slots as an inventory, linked to the player but not openable. When the player enters the dimension, transfer all items to this "alternative inventory" and give them back when they return to the normal world.
Sorry if it's not very clear, I'm not a native English speaker. Feel free to ask if you don’t understand certain points or need more details! :)
discord : npcsacha
thanks