mojira.dev
MC-122412

Some blockstates appear twice in a debug world

The bug

In a Debug world setting, where every block with every states generates. However, all blocks will appear a second time with the exact same states, if they are happen to generate ar the end of the z-axis (z=165). They will then appear again at the beginning of the next row (x-coordinate + 2, z=1).

How to reproduce

  1. When creating a new world, go to more world options click the world type button holding shift until it says "Debug Mode" to create a debug world

  2. Now look for example at the blocks at 3 70 165 and 5 70 1. Press F3 to displaay the state at the bottom right. In that case both blocks will be minecraft:dispenser[facing=west,triggered=false]

Code analysis

In (MCP 9.40 naming) the function net.minecraft.world.gen.ChunkGeneratorDebug.getBlockStateFor(int p_177461_0_, int p_177461_1_):

ChunkGeneratorDebug.java

if (p_177461_0_ > 0 && p_177461_1_ > 0 && p_177461_0_ % 2 != 0 && p_177461_1_ % 2 != 0)
{
	p_177461_0_ = p_177461_0_ / 2;
	p_177461_1_ = p_177461_1_ / 2;

	if (p_177461_0_ <= GRID_WIDTH && p_177461_1_ <= GRID_HEIGHT)
	{
		int i = MathHelper.abs(p_177461_0_ * GRID_WIDTH + p_177461_1_);

		if (i < ALL_VALID_STATES.size())
		{
			iblockstate = ALL_VALID_STATES.get(i);
		}
	}
}

The west-east grid size is used in a place that should be using the north-south grid size.
int i = MathHelper.abs(p_177461_0_ * {color:red}GRID_WIDTH{color} + p_177461_1_);
should be
int i = MathHelper.abs(p_177461_0_ * {color:green}GRID_HEIGHT{color} + p_177461_1_);

There is an off-by-one: a <= at the southern edge which should be a <.
if (p_177461_0_ {color:red}<={color} GRID_WIDTH && p_177461_1_ {color:red}<={color} GRID_HEIGHT)
should be
if (p_177461_0_ {color:green}<{color} GRID_WIDTH && p_177461_1_ {color:green}<{color} GRID_HEIGHT)

The off-by-one is what makes this bug visible; without it, you just have a slightly wrong grid size, and no-one would care or notice. It only causes it to show up when the two switched sizes are unequal, like in these snapshots or 1.10.2 for example, and not in 1.11.2 or 1.12.2 for example.

Linked issues

Attachments

Comments 13

this is only a guess but maybe one's the 'Entrance' and the others the 'Exit', as you yourself can make custom end gateways. another possibility is that there's a technical state for them that we the players cannot access and is purely for the game.

end_gateway and end_portal?

No, it's two end gateways, I checked.

So I guess reopen it?

Actually, looking at it again, it seems like all blockstates at the end of a Z-axis-row (z=165) appear again at the next higher x-coordinate at Z=1.

3 more comments

The same code problem exists in 1.15-pre6, although conditions are not favorable to actually reproduce (by my calculations, with the current 11337 states, GRID_WIDTH is 107 and GRID_HEIGHT is 106, which I think hides the actual problem. But I'm not 100% sure)

Affects 20w13b in-game without having to look at the code.

Can confirm in 21w16a.

@unknown, just to let you know, the bug tracker is not a discussion forum. If you'd like to talk about the outcome of a bug, please do so on either the Mojira Discord or Mojira Reddit.

NeunEinser

(Unassigned)

Confirmed

Low

Debug, World generation

Minecraft 1.12.2, Minecraft 17w47b, Minecraft 17w48a, Minecraft 17w49a, Minecraft 17w49b, ..., 1.16 Pre-release 8, 1.16.1, 1.16.4, 20w46a, 21w16a

Retrieved