Fix the block placing drill upgrade

This commit is contained in:
Mrbysco 2024-04-28 22:07:31 +02:00
parent 786d9d3302
commit 7e7fd0d8e2

View file

@ -111,6 +111,7 @@ public class DrillItem extends ItemEnergy {
@Nonnull @Nonnull
@Override @Override
public InteractionResult useOn(UseOnContext context) { public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
Player player = context.getPlayer(); Player player = context.getPlayer();
InteractionHand hand = context.getHand(); InteractionHand hand = context.getHand();
@ -121,16 +122,17 @@ public class DrillItem extends ItemEnergy {
if (slot >= 0 && slot < 9) { // TODO: validate... old = PlayerInventory.getHotbarSize(); new = 9 if (slot >= 0 && slot < 9) { // TODO: validate... old = PlayerInventory.getHotbarSize(); new = 9
ItemStack equip = player.getInventory().getItem(slot); ItemStack equip = player.getInventory().getItem(slot);
if (!equip.isEmpty() && equip != stack) { if (!equip.isEmpty() && equip != stack) {
ItemStack toPlaceStack = equip.copy(); ItemStack toPlaceStack = equip;
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack); // WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack);
//tryPlaceItemIntoWorld could throw an Exception //tryPlaceItemIntoWorld could throw an Exception
try { try {
//Places the Block into the World //Places the Block into the World
if (toPlaceStack.useOn(context) != InteractionResult.FAIL) { BlockHitResult result = new BlockHitResult(context.getClickLocation(), context.getClickedFace(), context.getClickedPos(), context.isInside());
if (toPlaceStack.useOn(new UseOnContext(level, player, hand, toPlaceStack, result)) != InteractionResult.FAIL) {
if (!player.isCreative()) { if (!player.isCreative()) {
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack.copy()); // WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack.copy());
} }
} }
} }
@ -139,8 +141,8 @@ public class DrillItem extends ItemEnergy {
ActuallyAdditions.LOGGER.error("Player " + player.getName() + " who should place a Block using a Drill at " + player.getX() + ", " + player.getY() + ", " + player.getZ() + " in World " + context.getLevel().dimension() + " threw an Exception! Don't let that happen again!"); ActuallyAdditions.LOGGER.error("Player " + player.getName() + " who should place a Block using a Drill at " + player.getX() + ", " + player.getY() + ", " + player.getZ() + " in World " + context.getLevel().dimension() + " threw an Exception! Don't let that happen again!");
} }
player.getInventory().setItem(slot, player.getItemInHand(hand)); // player.getInventory().setItem(slot, player.getItemInHand(hand));
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, stack); // WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, stack);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }