Skip to content

Anchor golem/snowman block removal on the pumpkin, not the spawn block (#127)#266

Merged
tastybento merged 1 commit into
developfrom
fix/127-golem-block-removal
Jun 13, 2026
Merged

Anchor golem/snowman block removal on the pumpkin, not the spawn block (#127)#266
tastybento merged 1 commit into
developfrom
fix/127-golem-block-removal

Conversation

@tastybento

Copy link
Copy Markdown
Member

Fixes #127.

The bug

With Limits installed, building an iron golem left the iron blocks and the jack o'lantern in the world instead of consuming them (reported with video; confirmed by multiple users that it only happens with Limits installed).

Root cause

Built golems/snowmen are spawned via the async path (the CreatureSpawnEvent is cancelled and the mob is re-spawned), so Limits has to clear the building blocks itself in detectIronGolem(). That method assumed the spawn location was the base iron block and only searched upward:

Block legs = location.getBlock();   // assumed BASE
...
for (BlockFace bf : CARDINALS) { Block body = legs.getRelative(bf); ... }

A built mob's CreatureSpawnEvent location is not guaranteed to be a particular block of the structure. When it's the body block, the upward search matches nothing — so only the spawn block was removed and the base, both arms, and the pumpkin were left behind. (The old code also unconditionally setType(AIR)'d the spawn block before matching anything.)

Fix

Anchor detection on the carved pumpkin / jack o'lantern, which is unambiguous:

  1. Scan the spawn block and the two blocks above it for the head sitting on the expected body material.
  2. Verify body + base below it, and two opposite iron arms beside the body.
  3. Erase the full set — only if a complete valid pattern matches (safer than the old unconditional removal).

This works whether the spawn anchors on the base, body, or head. Snowman detection is anchored the same way.

Tests

A coordinate-keyed mock block grid drives four tests:

The first three fail on the current code and pass with the fix. Full suite: 237 tests, 0 failures.

Scope note

This PR fixes the iron golem and snowman (both pumpkin-topped). detectWither() has the same base-anchored assumption and could be given the same treatment in a follow-up, but withers weren't part of this report and the rewrite is more involved, so it's left unchanged here.

🤖 Generated with Claude Code

#127)

When a player built an iron golem, detectIronGolem() assumed the
CreatureSpawnEvent location was the BASE iron block and only searched
upward. The built-mob spawn location is not guaranteed to be a specific
block of the structure — when it is the body block, the old search matched
nothing and removed only the spawn block, leaving the base, both arms and
the pumpkin behind. Vanilla consumes those blocks, so Limits left a
half-built golem's worth of blocks in the world (and uncounted).

Anchor detection on the carved pumpkin / jack o'lantern instead, which is
unambiguous: scan the spawn block and the two above it for the head, then
verify and erase the body, base and arms relative to it. This works whether
the spawn anchors on the base, body or head, and — unlike the old code,
which unconditionally aired the spawn block — erases nothing unless a full
valid pattern matches. Snowman detection is anchored the same way.

Tests build a coordinate-keyed mock block grid and verify every structure
block is removed for both spawn anchors, that a snowman is cleared, and
that a lone iron block is left untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@tastybento tastybento merged commit e794fd7 into develop Jun 13, 2026
3 checks passed
@tastybento tastybento deleted the fix/127-golem-block-removal branch June 13, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug when spawning IronGolem using Jack 'o lantern

1 participant