Anchor golem/snowman block removal on the pumpkin, not the spawn block (#127)#266
Merged
Merged
Conversation
#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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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
CreatureSpawnEventis cancelled and the mob is re-spawned), so Limits has to clear the building blocks itself indetectIronGolem(). That method assumed the spawn location was the base iron block and only searched upward:A built mob's
CreatureSpawnEventlocation 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 unconditionallysetType(AIR)'d the spawn block before matching anything.)Fix
Anchor detection on the carved pumpkin / jack o'lantern, which is unambiguous:
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