i need help making an entity that swpas the position of the items in the inventory

Started by Redtrakinas1 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i need help making an entity that swpas the position of the items in the inventory

resuming i need help with an entity that if you collide with it the items change gui in the inventory example: the sword in slot 1 and if i collide with the mob the sword will change to slot 9 or something like that but the slot that it will change is random does somebody have some advise of how to make an procedure like that in mcreator?

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I did something similar for…
Fri, 09/22/2023 - 03:52

I did something similar for shulker-items that spring to your hand when you need them. It'd be a bit trickier to randomize inventory slots, but hardly impossible. Try something like this:

  • Create a procedure with two local itemstack variables and two local number variables; one for the item slot you're swapping, and one for the slot that it's going to be moved to. (Which might already have an item in it.) 
  • Set the first local number variable to a random number 0 through 35, (the amount of player inventory slots). Set the first itemstack variable to whatever's in this slot number. ("Get item from slot... of target entity").
  • Then, set the second local number variable to another random number 0 through 35. This'll be the slot the thing's getting swapped with. If it's equal to the first number variable, you'll probably want to reroll it. 
  • Set the second itemstack variable to whatever's in the second slot number.
  • Then set 1 instance of the first itemstack in the second itemstack's slot number, and 1 instance of the second itemstack in the first itemstack's slot number. (If the second slot was air, this'll just empty the slot.) 
  • You can nest this in a 'repeat' function if you want it to do this multiple times.

...Also keep in mind that the number of items in a stack is independent of all the other attributes. (Name, enchantments, etc.) Meaning if you're swapping stackable items, you'll want to add two more number variables to keep track of the amount of items in each stack, otherwise it'll default to 1.