mojira.dev
MC-221864

Iron golems produce walking particles for light blocks

The bug

When walking on a light block (defined by the game as a light block being below an iron golem while it walks), iron golems produce particles of the light block, despite the fact that no such particles should be made here as the texture is only meant to be visible for mapmakers.

Related issues

Attachments

Comments

migrated
[media][media][media][media][media][media][media][media]
Avoma

Can confirm.

migrated

Related to MC-1133

Avoma

Can confirm in 21w14a.

Avoma

Can confirm in 21w15a.

Avoma

Can confirm in 21w16a.

Avoma

Can confirm in 21w17a.

migrated

Can confirm in 1.17 pre-release 3

Avoma

Can confirm in 1.17.

Avoma

Can confirm in 1.17.1.

Avoma

I can confirm this behavior in 1.18. Here's a code analysis of this issue.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.

net.minecraft.world.entity.animal.IronGolem.java

public class IronGolem extends AbstractGolem implements NeutralMob {
   ...
   public void aiStep() {
      super.aiStep();
      ...
      if (this.getDeltaMovement().horizontalDistanceSqr() > (double)2.5000003E-7F && this.random.nextInt(5) == 0) {
         int i = Mth.floor(this.getX());
         int j = Mth.floor(this.getY() - (double)0.2F);
         int k = Mth.floor(this.getZ());
         BlockState blockstate = this.level.getBlockState(new BlockPos(i, j, k));
         if (!blockstate.isAir()) {
            this.level.addParticle(new BlockParticleOption(ParticleTypes.BLOCK, blockstate), this.getX() + ((double)this.random.nextFloat() - 0.5D) * (double)this.getBbWidth(), this.getY() + 0.1D, this.getZ() + ((double)this.random.nextFloat() - 0.5D) * (double)this.getBbWidth(), 4.0D * ((double)this.random.nextFloat() - 0.5D), 0.5D, ((double)this.random.nextFloat() - 0.5D) * 4.0D);
         }
      }
      ...

If we look at the above class, we can see that there is only one necessary check that is carried out before allowing an iron golem to produce walking particles. This check is to see if the block below them is air, and if it is, walking particles won't be produced, but if it isn't, walking particles based on the block that the iron golem is standing on will be produced. The game doesn't check the RenderShape of the block that the iron golem standing on before allowing it to produce walking particles, therefore resulting in this problem occurring.

Fix:

Simply changing some lines of code to check the RenderShape of the block that the iron golem is standing on before allowing it to produce walking particles, will resolve this problem.

Current Code:

...
BlockState blockstate = this.level.getBlockState(new BlockPos(i, j, k));
if (!blockstate.isAir()) {
...

Fixed Code:

...
BlockPos blockpos = new BlockPos(i, j, k);
BlockState blockstate = this.level.getBlockState(blockpos);
if (blockstate.getRenderShape() != RenderShape.INVISIBLE) {
...
Avoma

Can confirm in 1.18.1.

Avoma

Can confirm in 1.18.2 and 22w14a.

Avoma

Can confirm in 1.19.

Avoma

Can confirm in 1.19.2.

Avoma

Following on from my code analysis, I've double-checked my proposed fix and I can confidently confirm that it's fully functioning and works as expected, so I've attached two screenshots to this report, one of which shows the current code and the other that shows the fixed code. I feel this information may be quite insightful hence my reasoning for providing it. 🙂

[media][media]
muzikbike

This does not seem to happen anymore as of 1.20-rc1. Can we find the exact fix version (possibly pre-release 3 as per MC-262505)?

Avoma

This issue was present in 1.20 Pre-release 2, but no longer occurs in versions above or equal to 1.20 Pre-release 3. This issue was fixed in 1.20 Pre-release 3.

muzikbike

I may need to re-test this with carpets on top of light blocks first.

[Mod] markderickson

Closing as Fixed in 1.20pr3 per @unknown's comment.

muzikbike

(Unassigned)

Confirmed

Low

Particles

invisible-blocks, invisible-blocks-not-invisible, iron_golem, light, unnecessary-particles

21w13a, 21w14a, 21w15a, 21w16a, 21w17a, ..., 1.19.2, 1.19.3, 23w06a, 1.19.4, 1.20 Pre-release 1

1.20 Pre-release 3

Retrieved