Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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
}
}