From ccbf295de0eb9a230adba573e4516c03c765db8a Mon Sep 17 00:00:00 2001 From: mattlawliet0000 Date: Wed, 9 Sep 2026 02:05:13 -0500 Subject: [PATCH] fix: place villagers from off-hand when main hand is occupied 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 #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 Claude-Session: https://claude.ai/code/session_01FGCvEm7XDj8rS2YefvQPVT --- .../event/PlaceVillagerListener.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/mod/src/main/java/de/clickism/clickvillagers/event/PlaceVillagerListener.java b/mod/src/main/java/de/clickism/clickvillagers/event/PlaceVillagerListener.java index 33bdc30..830eb9d 100644 --- a/mod/src/main/java/de/clickism/clickvillagers/event/PlaceVillagerListener.java +++ b/mod/src/main/java/de/clickism/clickvillagers/event/PlaceVillagerListener.java @@ -19,7 +19,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; @@ -30,8 +29,6 @@ public InteractionResult event( InteractionHand hand, BlockHitResult hitResult ) { - InteractionHand usedHand = getUsedHand(player); - if (!hand.equals(usedHand)) return InteractionResult.PASS; if (hitResult == null) return InteractionResult.PASS; if (world.isClientSide()) return InteractionResult.PASS; if (player.isSpectator()) return InteractionResult.PASS; @@ -51,10 +48,10 @@ public InteractionResult event( BlockPos pos = clickedPos.relative(hitResult.getDirection()); de.clickism.clickvillagers.util.VersionHelper.moveEntity(entity, pos); world.addFreshEntity(entity); + // ponytail: shrink the stack in the hand that was actually used, not the selected hotbar slot itemStack.shrink(1); - if (itemStack.getCount() <= 0) { - int slot = de.clickism.clickvillagers.util.VersionHelper.getSelectedSlot(player.getInventory()); - player.getInventory().setItem(slot, Items.AIR.getDefaultInstance()); + if (itemStack.isEmpty()) { + player.setItemInHand(hand, ItemStack.EMPTY); } BlockPos posBelow = pos.below(); de.clickism.clickvillagers.util.VersionHelper.playSound(player, SoundEvents.PLAYER_ATTACK_WEAK, SoundSource.NEUTRAL, 1, .5f); @@ -66,15 +63,4 @@ public InteractionResult event( return InteractionResult.SUCCESS; } - private static InteractionHand getUsedHand(Player player) { - ItemStack mainHandItem = player.getMainHandItem(); - if (!mainHandItem.isEmpty()) { - return InteractionHand.MAIN_HAND; - } - ItemStack offHandItem = player.getOffhandItem(); - if (!offHandItem.isEmpty()) { - return InteractionHand.OFF_HAND; - } - return InteractionHand.MAIN_HAND; // Default to main hand - } }