Generating random item from item on right click

Started by titanicslimeocean on

Topic category: Help with Minecraft modding (Java Edition)

Active 2 years ago
Joined May 2022
Points:
367

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 0
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

Active 15 hours ago
Joined Jan 2022
Points:
491

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 33
bump
Mon, 03/24/2025 - 21:24

bump

Active 1 month ago
Joined Mar 2025
Points:
12

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 10
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