Started by
inferno
on
Topic category: Help with Minecraft modding (Java Edition)
I'm making a mod that adds tcg packs and I want to make it when the player right clicks with the pack in hand it gives a random card from the packs loot pool and I can't figure out how to do that
You can create a custom lootable with custom rarities in the "Add new mod element" menu.
After that you can access and pull random items from it in procedures using the registry name which is given you when creating a custom loot table.
For example, create a new loot table and make sure to use 1 roll max. In the "Triggers" tab in your pack item menu you can create a "When item rightclicked from entity pos" procedure. In this procedure you can use the following structure:
For every item in loot table (your loot table) as itemstack iterator:
Spawn/Give item (itemstack iterator) at (x pos of target entity) (y pos of target entity) (z pos of target entity)
I did not test this but it might just spawn every item in the loot table.
Soooo, here is a variant which should be functional but is a lot more work:
(This is a "When Item rightclick from entity pos" procedure too)
(Create a local number variable, I will call it "var" from now on)
Set var to random number from 1 to (your amount of card in the loot pool)
If var = 1 then spawn/give item (card 1)
else if var = 2 then spawn/give item (card 2)
else if var = 3 then spawn/give item (card 3)
etc.
It is a lot of copy-pasting but until now, this might be the safest option...
Of course you can change any part of these scripts or add sounds and stuff like that.
If the first solution does not help and you are not satisfied with the second one, I am pretty sure you would have to go with custom java code by locking the element and then editing the source code itself which is the most difficult but most promising solution unfortunately.
Hope that I could help ya :D