Started by
Ziadod
on
Topic category: Help with Minecraft modding (Java Edition)
So I have been 5 hours trying to figure out how to get a random slot in the player's inventory each time he breaks a block and apply the sharpness I enchantment on that randomly chosen slot if it has an item and not empty. It just won't work; no errors, but it won't work.
Can anyone tell me what is wrong with my code and how to fix it? Here is my code:

so, in mcreator when you set an item to a variable, it actually copies it.
so you're not modifying the item by modifying the variable,
try using this block at the end,
Thanks! This works, but I need help with something else, so here is my current code:
The issue right now is that if a player has a stack of items, like 64 of them, it gets replaced with just one enchanted item. I want the amount to stay the same and just get enchanted.
I also don’t want it to apply only Sharpness. I want it to pick from any enchantment available in Minecraft 1.21.1 and earlier. How can I make that work?
you can set OriginalAmount to
maybe you can use this to get a random enchantment,
if not you can use a custom snippet,
Alright, everything is working perfectly. Thank you for your help! I still have a few more questions about something else, but I’ll create a new post since this isn’t the right place for them.