fix: place villagers from off-hand when the main hand is occupied (#109) - #110
Open
mattlawliet wants to merge 1 commit into
Open
mattlawliet wants to merge 1 commit into
mattlawliet wants to merge 1 commit into
Conversation
getUsedHand() picked the hand by "which one is non-empty" rather than "which one holds a villager". With any non-empty main hand (a totem, a sword, anything not placeable), the off-hand event was skipped and the main-hand event failed the isVillager check, so the mod never ran and vanilla placed the villager head as a block instead. Closes Clickism#109. The isVillager check on getItemInHand(hand) already selects the correct hand, so the extra gate is dropped entirely. Vanilla runs the main hand first and only falls through to the off-hand when the main hand did nothing, so main-hand behaviour is unchanged. Also shrink the stack in the hand that was actually used instead of clearing the selected hotbar slot, which deleted the main-hand item when placing from the off-hand. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FGCvEm7XDj8rS2YefvQPVT
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 #109.
The bug
Pick up a villager, move the head to your off-hand, hold anything non-placeable in your main hand (a totem, a sword), right-click the ground: the head is placed as a block and the villager is gone.
Cause
PlaceVillagerListener.getUsedHand()picked the hand by which one is non-empty, not which one holds a villager:With a totem in the main hand that returns
MAIN_HAND, so:OFF_HANDevent (holding the head) failshand.equals(usedHand)and passes;MAIN_HANDevent (holding the totem) failsisVillagerand passes.The mod never runs and vanilla places the head block. Introduced in 5c46fc0, which fixed #87 only for the case where the main hand is empty.
Fix
Drop the hand gate.
isVillager(player.getItemInHand(hand))already selects the correct hand, and vanilla runs the main hand first and only falls through to the off-hand when the main hand consumed nothing — so main-hand behaviour is untouched.Second change in the same method: the stack was shrunk, then the selected hotbar slot was cleared. Once off-hand placement works, that deletes whatever is in the main hand — the totem in the repro above. Now it clears the hand that was actually used.
Testing
Fabric server, MC 26.2, loader 0.19.5, fabric-api 0.160.0, ClickVillagers 1.6.7. Reproduced with a build of
master, then verified against a build of this branch. Manual matrix, survival mode, all passing:PlaceVillagerInVehicleListenergatesMAIN_HANDexplicitly and is untouched — placing into a boat from the off-hand is still unsupported, same as before.Builds clean on every stonecutter target:
1.21.1-fabric,1.21.1-neoforge,1.21.11-fabric,1.21.11-neoforge,26.1-fabric,26.2-fabric. NeoForge shares this listener viaNeoforgeEventListener, so it gets the fix too. The Paper module is unaffected.🤖 Generated with Claude Code
https://claude.ai/code/session_01FGCvEm7XDj8rS2YefvQPVT