From e91c1569eef465407cd92afb113bdfd93be7754c Mon Sep 17 00:00:00 2001 From: Mrbysco Date: Tue, 22 Oct 2024 22:33:33 +0200 Subject: [PATCH] Fix tool check (Fixes #1421) --- .../actuallyadditions/mod/tile/TileEntityBreaker.java | 5 ++++- .../mod/tile/TileEntityLongRangeBreaker.java | 2 +- .../actuallyadditions/mod/tile/TileEntityVerticalDigger.java | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java index d9c0fbee2..ac659b79c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBreaker.java @@ -21,11 +21,13 @@ import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -102,7 +104,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase implements MenuPr } private void doWork() { - Direction side = WorldUtil.getDirectionByPistonRotation(this.level.getBlockState(this.worldPosition)); + Direction side = WorldUtil.getDirectionByPistonRotation(getBlockState()); BlockPos breakCoords = this.worldPosition.relative(side); BlockState stateToBreak = this.level.getBlockState(breakCoords); Block blockToBreak = stateToBreak.getBlock(); @@ -110,6 +112,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase implements MenuPr if (!this.isPlacer && blockToBreak != Blocks.AIR && stateToBreak.getDestroySpeed(this.level, breakCoords) >= 0.0F) { List drops = Block.getDrops(stateToBreak, (ServerLevel) this.level, breakCoords, this.level.getBlockEntity(breakCoords)); FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); + fake.getInventory().items.set(fake.getInventory().selected, Items.NETHERITE_PICKAXE.getDefaultInstance()); if (stateToBreak.canHarvestBlock(this.level, breakCoords, fake)) { //TODO might double check this is right mikey if (StackUtil.canAddAll(this.inv, drops, false)) { this.level.destroyBlock(breakCoords, false); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java index 3f99c9532..8429e02d0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java @@ -95,7 +95,7 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen private void doWork() { if (this.storage.getEnergyStored() >= ENERGY_USE * RANGE) { - BlockState state = this.level.getBlockState(this.worldPosition); + BlockState state = getBlockState(); Direction sideToManipulate = WorldUtil.getDirectionByPistonRotation(state); for (int i = 0; i < RANGE; i++) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java index ae92ba1e7..c1c3df6e2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java @@ -30,6 +30,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -138,13 +139,13 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements : 1); if (this.storage.getEnergyStored() >= actualUse) { BlockPos pos = new BlockPos(this.worldPosition.getX() + this.checkX, this.checkY, this.worldPosition.getZ() + this.checkZ); + ItemStack fakePickaxe = Items.NETHERITE_PICKAXE.getDefaultInstance(); BlockState state = this.level.getBlockState(pos); Block block = state.getBlock(); ItemStack stack = block.getCloneItemStack(state, new BlockHitResult(new Vec3(0, 0, 0), Direction.DOWN, pos, false), this.level, pos, FakePlayerFactory.getMinecraft((ServerLevel) this.level)); if (!state.isAir()) { - //block.getHarvestLevel(state) <= DrillItem.HARVEST_LEVEL - if (stack.isCorrectToolForDrops(state) && state.getDestroySpeed(this.level, pos) >= 0F && this.isMinable(state, stack)) { + if (fakePickaxe.isCorrectToolForDrops(state) && state.getDestroySpeed(this.level, pos) >= 0F && this.isMinable(state, stack)) { List drops = Block.getDrops(state, (ServerLevel) this.level, pos, this.level.getBlockEntity(pos)); float chance = WorldUtil.fireFakeHarvestEventsForDropChance(this, drops, this.level, pos);