From b12a62fa4abb28ed191b32c62eea335f6022518f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 6 Jan 2021 22:31:37 +0100 Subject: [PATCH] Fixed pipes not dropping their contents when removed with a pipe wrench Closes #69 --- .../ellpeck/prettypipes/items/WrenchItem.java | 7 ++---- .../ellpeck/prettypipes/pipe/PipeBlock.java | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java index 06e4d1a..e2ac6a1 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java @@ -2,19 +2,16 @@ package de.ellpeck.prettypipes.items; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.ConnectionType; +import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeTileEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; -import net.minecraft.loot.LootContext; import net.minecraft.state.EnumProperty; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; @@ -25,7 +22,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.text.ITextComponent; import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; import java.util.List; import java.util.Map; @@ -56,6 +52,7 @@ public class WrenchItem extends Item { Utility.sendTileEntityToClients(tile); } else { // remove the pipe + PipeBlock.dropItems(world, pos, player); Block.spawnDrops(state, world, pos, tile, null, ItemStack.EMPTY); world.removeBlock(pos, false); } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 5255e4e..df5425e 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -1,11 +1,9 @@ package de.ellpeck.prettypipes.pipe; import com.google.common.collect.ImmutableMap; -import com.mojang.datafixers.types.Func; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.items.IModule; -import de.ellpeck.prettypipes.network.PipeItem; import de.ellpeck.prettypipes.network.PipeNetwork; import net.minecraft.block.*; import net.minecraft.block.material.Material; @@ -271,14 +269,7 @@ 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); - } + dropItems(worldIn, pos, player); super.onBlockHarvested(worldIn, pos, state, player); } @@ -305,4 +296,15 @@ public class PipeBlock extends ContainerBlock { public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.MODEL; } + + public static void dropItems(World worldIn, BlockPos pos, 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); + } + } }