mojira.dev
MC-2788

Sheep wool color doesn't generate/randomize properly; generating villages resets world RNG

Sheep groups spawning at world generation or otherwise when structures are generated at the same time will spawn the same sheep colors.

Steps to reproduce:

  • Find a world where a lot of sheep spawn at world generation. Ideally spawn near a plains biome. Example seeds are "136" and "quarry" (default biomes)

  • Observe sheep

Actual results:

  • The sheep spawning in groups of 4 always spawn with the same color. In the "quarry" seed, sheep will always spawn as three white sheep and one brown sheep. In the "136" seed, sheep will always spawn as three white sheep and one dark grey sheep.

Expected result:

  • Sheep should be randomized so you get different sheep per group per world.

The code that generates groups of sheep (and possibly other mobs) doesn't seem to use the random generator properly so all the sheep groups are generated the same. See comments for details and attachments for debug output.

Note: This bug probably applies only to mobs spawning while structures are generated at the same time, if you search long enough, you may/will find different sheep groups.

PS: Additionally, some seeds like "135" spawn huge amounts of pigs but no sheep, so it may be possible that the random generator fails to be random even earlier: At determining which mobs to spawn.

Code analysis

See this comment by @unknown

Related issues

Attachments

Comments

migrated
[media][media][media][media][media][media][media][media][media]
kumasasa

The spawning rates of the colours are not equally distributed:
According to http://www.minecraftwiki.net/wiki/Sheep the spawning rates are White Sheep 81.836%, Light Gray Sheep 5%, Gray Sheep 5%, Black Sheep 5%, Brown Sheep 3% (50% in extreme Hills biome), Pink Sheep 0.164%

For doing a real statistics a sample of 6 groups á 4 sheep is way too less.

Jonathan Haas

Yes, I know, but try to calculate the probablity of of 6 sheep groups with each 1 pink sheep and 3 brown sheep in it. (In plains biome)

I'm no expert in statistics, but the probablity for that is extremely low, around 1×10^-50, so I'm pretty sure this is an issue in the game. At least the devs should take a look at the code.

GrygrFlzr

Are you saying that the issue is that supposedly rare sheep (brown and pink) are spawning a bit too frequently? I don't really understand the issue from the description.

kumasasa

Random is random. The probability for a pink sheep to spawn is always 0.164%, regardless how many pink sheep are running around yet.
(Question: How is the probability to roll a dice to "6" when you draw the last three rolls also "6" ?)

Jonathan Haas

Just a quick example: generate a new world with seed "quarry" in creative mode. Go/Fly to the plains biome x=0, z=190, observe sheep groups. All groups consist of 1 brown sheep and 3 white ones. This is just a completely random seed I use and is not specially choosen to spawn exactly these sheep.

If I find a way/screenshot to reprocude the pink sheeps, I will post it here, but this should do for now.

Jonathan Haas

@Kumasasa 1/6 obviously, but if you roll a 6 thousand times in a row, you might question if the dice is working correctly, although it could still be random of course. The probablillity for that is just incredibly low.

GrygrFlzr

I don't think anything with randomness in it can be categorized as a bug. We can only calculate the chance of a certain result appearing, so the actual results can be quite different. For example, I can roll 6 dice simultaneously and end up with six 6s. Probability states that it should only have a 1/46656 chance of happening, and yet it can happen. If you ended up with the expected results (nearly no dice having the same number, or in this case mostly white sheep with barely any brown sheep) all the time, it would mean the random number generator is too predictable. This is a sign the randomizer is working.
However, if you had used a larger sample and it generated mostly brown sheep, that might be a problem with the random number generator. I will try an experiment and spawn several thousand sheep to see if the probability evens out.

Jonathan Haas

Martin: I'm not categorizing randomness as a bug, but I ended up having several completely improbable results, so I'm just asking if the random generator is working correctly. While it could be possible that these events were all random, the devs could and probably should just check the internal seeds of each sheep group generator and make sure that they are indeed random. If they are, I'm happy with it, but I strongly suspect a bug here.

kumasasa

Have attached the screenshot of seed "quarry". Seeing white and brown sheep at given coordinates.

GrygrFlzr

Ah, yeah, the seed quarry seems to generate groups of 3 white and 1 brown sheep. In fact looking around it's all 3 white and 1 brown sheep. That's definitely not random enough, but is this the only seed that does this? Using a seed removes the randomness, after all. Spawning during world generation is controlled by the world seed, not sure about post-worldgen spawning.

Jonathan Haas

No, all seeds do this, this is just a random example. Other seeds just spawn different sheep groups; there are seeds that spawn only white sheep and there is the other seed that spawns groups of one pink sheep and three brown sheep, although I don't know if I have the save file/seed still.

Jonathan Haas

Some more screenshots of quarry seed with spawn groups highlighted

Mustek

Seems like the colored sheep spawning rates have increased, I see more pink, brown and grey sheep now.

Is this still an issue for you or can this be resolved?

Jonathan Haas

The issue is still present in 1.4.6. Sheep spawning is unchanged.

The problem is not that sheeps spawn more in pink, grey and and brown colors, the issue is that all sheep groups spawn the same.

Jonathan Haas

I decompiled minecraft using MCP and modified the function generating sheep color like this:

EntitySheep.java

public static int getRandomFleeceColor(Random par0Random)
    {
        int var1 = par0Random.nextInt(100);
        System.out.println("Random " + var1);
        return var1 < 5 ? 15 : (var1 < 10 ? 7 : (var1 < 15 ? 8 : (var1 < 18 ? 12 : (par0Random.nextInt(500) == 0 ? 6 : 0))));
    }

so it prints the generated "random" value to the console. As you can see by looking at the attached file, the values are not random at all and instead repeat every 4 values, so the color repeats for every 4 sheep generated.

bugi74

Fix

World

public Random setRandomSeed(int par1, int par2, int par3) {
        long var4 = (long)par1 * 341873128712L + (long)par2 * 132897987541L + this.getWorldInfo().getSeed() + (long)par3;
        //this.rand.setSeed(var4);
        //return this.rand;
        return new Random(var4); // <-- Makes things better?
    }

That is, instead of resetting the world random generator, just return a new generator with the same end state.

There are two callers to this method. I didn't study their behaviour thoroughly after this change, but at least the other caller (village generator) seemed to still generate a valid looking village in a place where I knew a village was supposed to be. I leave the rest as an exercise to Mojang (or anyone else with interest).

After fix, sheep colors are random, even when regenerating the world with the same seed. (There is a way to get same random sequence of colors each time the world is generated, but if Mojang wants that, they need to implement that separately.)

(Edit: the proposed fix is "bad coding", at least if keep using that method name; that method name indicates that the seed is indeed being set, and since it is aimed at the world instance, natural interpretation would be that the seed of the RNG of the world is to be set, which is not happening after the fix. Perhaps change the method name to something like "getRNGWithState"?)

Bug
The reason is that couple map feature generators (villages and temples/huts) reset the world random generator (its seed), even if they are called just to check whether such feature is to be generated or not. They always reset the seed to the same value (though different value for each generator), and these resets are very common during generation. The animal/sheep generation uses the world RNG, too, but almost always at a time when that generator is still in predictable state after these resets, and thus gets the same values every time.

There are other things resetting the world RNG (sets its seed), too, but the other calls are very few, like 4 resets in the same span the two feature generators make hundres of resets.

Sample data
I've attached a text file including some example console debug spam with values before and after fix. The seed was always that familiar "quarry". The first section is without the fix - notice the exact same sequences of values most of the time. Other sections are three different generations with the fix enabled.

Jonathan Haas

Thanks for your fix, Markku. Makes sense to me. I hope the developers will include this in the main source.

bugi74

Affects 13w09b.

bugi74

Affects 1.5.1.
The duplicate MC-12281 has a very nice seed to check this; pink sheeps are so rare that when you get 1 in every group of 4, things get obvious. (Seed 110122358, coords x=0 z=1660.)

Jonathan Haas

Still reproducible in the latest version (1.6.2 prerelease). The seed is indeed very nice, one pink sheep in every group.

Jonathan Haas

Still reproducible in latest snapshot. Example Seed: 12. Will only spawn groups of 3 white and one brown sheep.

Tails

Example with pink sheep: 8807133522892241494 at X=75, Z=320
Every group contains exactly 1 pink sheep.

Ezekiel

Is this still a concern in the latest Minecraft version 14w08a? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Jonathan Haas

Still reproducible in 14w08a using the seed Tails posted above.

galaxy_2alex

Is this still a concern in the current Minecraft version 1.8.1 Prerelease 3 / Launcher version 1.5.3 or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Jonathan Haas

It's difficult to find good seeds to reproduce this, bit it seems to be still present in 1.8.1-pre3. Seed 8807133522892241494 at X=75, Z=320 seems to spawn purely white sheeps for example now.

galaxy_2alex

Reopened, thanks.

clamlol

Still in 15w47b, I spawned next to a village and half the sheep nearby were pink...

Vitold Chernatinski

Still Reproducible in 1.9.4
Seed: 2368284
x: 1941
z: 5825
Look for pink sheep.

FaRo1

Just opened seed 136 in 1.10.2. First group of 4 sheep I found was two white, one light grey, one dark grey. Second group of 4 sheep I found was three white and one light grey. These groups were far away from each other and I made sure (with glowing effect) that I didn't confuse sheep of different groups. Does that mean fixed for 1.10.2?

Jonathan Haas

Try a more recent seed and try to find sheep groups that are near each other (ie generate at the same time). I'd try the seed and coordinates by Vitold but I'm curently away from home so I can't try reproducing this.

jonathan2520
[media]

This is seed 136 in 1.10.2. At spawn I didn't immediately discern a pattern although many groups were the same. Near a village ALL groups were 2 white + 2 black. The debug screen shows these coordinates: 634, 118, 112. Generating a new world and teleporting there reproduces it.

I also disassembled the game using javap and found the mechanism is still in place. Village generator sets the world's RNG to a particular value. Sheep uses the world's RNG to pick a color. ??? Profit!

qwerty23495

Is this still an issue in 1.13-pre5?

Please keep the ticket updated.

FaRo1

I'm not too familiar with this bug, but I just found a pack of four white sheep in the "136" seed. Does that mean it's fixed?

bugi74

White is too common color, so that can not be used to check this one. It is best to check the seeds and locations already mentioned, but also note that world generation changes can make the earlier seeds/locations to no longer give the same results.

The best indication is to find a group with sheep(s) of rarer color(s), and see if the same color distribution is found in other groups nearby. E.g. if multiple groups all have 3 whites and one black, it could be an indication of this bug still being in effect. Typically, one would first find a world with a nice amount of sheep groups close together, then recreate the world with the same seed, but teleport right in the middle of those sheep groups (so they get generated in the same generation "run"). But just flying around in creative might do the trick, too.

FaRo1

You don't have to find the sheep, just give them the glowing effect. I found one group with a dark grey sheep, like in the report, and another one without a grey sheep.

slicedlime

Is this still an issue in 1.14.4 or above?

Arisa Bot

This report is currently missing crucial information. Please take a look at the other comments to find out what we are looking for.
If you added the required information and a moderator sees your comment, they will reopen and update the report. However, if you think your update to this report has been overlooked or you want to make sure that this report is reopened, you can contact the Mojira staff on Discord or Reddit.
-- I am a bot. This action was performed automatically! Please report any issues on Discord or Reddit

Jonathan Haas

(Unassigned)

Confirmed

World generation

color, group, mob, sheep, wool, world-generation

Minecraft 1.4.2, Minecraft 1.4.4, Minecraft 1.4.6, Minecraft 1.4.7, Snapshot 13w02a, ..., Minecraft 15w41b, Minecraft 15w47b, Minecraft 1.9.4, Minecraft 1.10.2, Minecraft 1.11.2

Retrieved