Generating random item from item on right click

Started by titanicslimeocean on

Topic category: Help with Minecraft modding (Java Edition)

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Generating random item from item on right click

Im trying to make a Pokemon Pack mod with you crafting packs and then opening them with a right click which gives you a random rare card but I don't know how to generate a random item (with probabilties) and I'm still fairly new so I would like a detailed explanation

Joined Mar 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Create a new procedure for…
Tue, 03/25/2025 - 11:10

Create a new procedure for your item with the "when right-clicked" trigger.

Check if the world is client-side. If it isn’t, the procedure continues. This check is necessary to prevent the procedure from triggering multiple times per right-click.

Perform the probability checks. The condition 'if random number between 0 and 1 < X' acts as our probability check, where X represents an X% chance of the player receiving the item.

  • You can add multiple checks, adjusting the target value between 0 and 1 to change the probability.
    (For example: 0.2 gives a 20% chance, 0.3 gives a 30% chance, 0.4 gives a 40% chance, and so on.)

EXAMPLE

In this example, I set the probability of the player receiving a copper ingot to 70%, by checking if the random number generated is less than 7.

Next, I set the probability of the player receiving an iron ingot to 50%, by checking if the number generated is less than 5.

The same goes for the gold ingot and diamond... Gold ingot has a 30%, and diamond has 10%.

 

ptpl file: https://www.mediafire.com/file/izibekncnp7tthi/GiveRandomItemWithProbabilties.ptpl/file