How do I make a mob randomly replace itself with another?

Started by a guy called l… on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make a mob randomly replace itself with another?

The question is: I want to make a mod that adds skins to the mobs, every time a mob appears there a possibility that has a skin, I will use a pig as an example:
normal pig, gold pig, devil pig and ender pig
When a pig appears, you choose if it will be changed or not, if you choose that it will be changed, it will be changed
Here I have the first problem, the procedure "detect if there an entity in X Y Z in a cube 1 type pig" works?
The second and most important thing for me, how do I make the apparition work? you could use "if random 0.1 ≥ 0.5
do: despawn current entity spawn gold pig "
but that has a problem, I must put if that happens and also if not if, and that is the problem, the pig that is lower will be the least likely to appear, the simplest solution is to put that a variable is set to random 0 , 1 x 10 to be a complete number, the problem is that it will only be from 1 to 9 and when I have more than 9 pigs it will not work, any solution?

Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Instead of searching for the…
Mon, 02/22/2021 - 16:34

Instead of searching for the mob inside of the area, do it on the entity tick update. 

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I understand what you mean,…
Tue, 02/23/2021 - 19:50

I understand what you mean, but I can't edit a vanilla pig, my idea is that when one appears, the change happens
I guess you can use the procedure "when an entity is generated" and put that if a pig is detected in XYZ with a block of 1 make the change
my main problem is randomness