From c1100b02fefa72781bc0a7617ad4e44d26d97270 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 20 Oct 2020 16:09:38 +0200 Subject: [PATCH] fixed the pipe not dropping its cover on break --- .../ellpeck/prettypipes/items/WrenchItem.java | 6 +----- .../ellpeck/prettypipes/pipe/PipeBlock.java | 19 +++++++++++++------ .../prettypipes/pipe/PipeTileEntity.java | 12 ++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java index f1baca8..06e4d1a 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java @@ -52,11 +52,7 @@ public class WrenchItem extends Item { if (!world.isRemote) { if (tile.cover != null) { // remove the cover - List drops = Block.getDrops(tile.cover, (ServerWorld) world, pos, null, player, player.getHeldItem(context.getHand())); - for (ItemStack drop : drops) - Block.spawnAsEntity(world, pos, drop); - - tile.cover = null; + tile.removeCover(player, context.getHand()); Utility.sendTileEntityToClients(tile); } else { // remove the pipe diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 8d2a1a6..fa9c653 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -258,12 +258,6 @@ public class PipeBlock extends ContainerBlock { @Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { - PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); - if (tile != null) { - Utility.dropInventory(tile, tile.modules); - for (IPipeItem item : tile.getItems()) - item.drop(worldIn, item.getContent()); - } PipeNetwork network = PipeNetwork.get(worldIn); network.removeNode(pos); network.onPipeChanged(pos, state); @@ -271,6 +265,19 @@ public class PipeBlock extends ContainerBlock { } } + @Override + public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { + PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); + if (tile != null) { + Utility.dropInventory(tile, tile.modules); + for (IPipeItem item : tile.getItems()) + item.drop(worldIn, item.getContent()); + if (tile.cover != null) + tile.removeCover(player, Hand.MAIN_HAND); + } + super.onBlockHarvested(worldIn, pos, state, player); + } + @Override public boolean hasComparatorInputOverride(BlockState state) { return true; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index b9a8f99..2c4038d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -9,6 +9,7 @@ import de.ellpeck.prettypipes.network.PipeItem; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer; import de.ellpeck.prettypipes.pressurizer.PressurizerTileEntity; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -26,10 +27,12 @@ import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.Capability; @@ -351,6 +354,15 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide return builder.build(); } + public void removeCover(PlayerEntity player, Hand hand) { + if (this.world.isRemote) + return; + List drops = Block.getDrops(this.cover, (ServerWorld) this.world, this.pos, null, player, player.getHeldItem(hand)); + for (ItemStack drop : drops) + Block.spawnAsEntity(this.world, this.pos, drop); + this.cover = null; + } + @Override public void remove() { super.remove();