Small procedure block request for plugin or Mcreator (+code snippet)

Started by Sir_sassypants on

Topic category: Feature requests and ideas for MCreator

Last seen on 05:50, 2. Jun 2023
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Small procedure block request for plugin or Mcreator (+code snippet)

I have been using a piece of code for a while, and I'm starting to get a lot of locked code elements, making me worried for when Mcreator moves to 1.16 or 1.17 that I will have to re-do everything.

Could you add a 'choose random number from _ to _' procedure block?

Code looks like this:

import java.util.concurrent.ThreadLocalRandom;

ThreadLocalRandom var1 = ThreadLocalRandom.current();

var2 = (int) var1.nextInt(3, 6); //pick random number from 3 to 5

I have used this code in so many different things. Like item spawning amount, structure height offset (I don't expect this one to be added), Spawning location, picking a random block to place, etc... I feel as if this would be very useful for modders. We already have the Math.random() function but we have to use a lot of if/else if statements, and are restricted to 0 - 1.

There is also the other random.nextInt() function, but that always starts at 0 to set number. (We can't set negatives with this)

 

Along with this, can we decide when creating a NUMBER variable to choose whether it is an Integer or a Double?

You can use existing random…
Sun, 02/28/2021 - 10:27

You can use existing random block for this.

 

RANDOM * A + B

Where B = min. value and A = max. value - min. value

Last seen on 05:50, 2. Jun 2023
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you! I didn't think of…
Sun, 02/28/2021 - 19:07

Thank you! I didn't think of that

Last seen on 05:50, 2. Jun 2023
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Actually ignore that last…
Sun, 02/28/2021 - 20:37

Actually ignore that last post, I did some testing and just did RANDOM * Number then rounded it to remove the decimals.

Last seen on 05:50, 2. Jun 2023
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(omg, I'm spamming now)…
Sun, 02/28/2021 - 20:41

(omg, I'm spamming now)

Every time I post I run into a problem and have to post again

When I do RANDOM * min + (max - min) I still get values like 0 or 1 even when min is set to 2.

Last seen on 05:50, 2. Jun 2023
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
FINAL POST I SWEAR I fixed…
Sun, 02/28/2021 - 22:36

FINAL POST I SWEAR

I fixed it after extensive testing and a little bit of researching. Initially I had trouble getting the values in the range I wanted. I did that but they were unbalanced. I then fixed that and ta-da! A probably inefficient but working piece of code!

Here it is for any future people in need