Fixed pipes not dropping their contents when removed with a pipe wrench

Closes #69
This commit is contained in:
Ell 2021-01-06 22:31:37 +01:00
parent 3a0be16891
commit b12a62fa4a
2 changed files with 14 additions and 15 deletions

View file

@ -2,19 +2,16 @@ package de.ellpeck.prettypipes.items;
import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.pipe.PipeBlock;
import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.PipeBlock;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.loot.LootContext;
import net.minecraft.state.EnumProperty; import net.minecraft.state.EnumProperty;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; 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.math.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -56,6 +52,7 @@ public class WrenchItem extends Item {
Utility.sendTileEntityToClients(tile); Utility.sendTileEntityToClients(tile);
} else { } else {
// remove the pipe // remove the pipe
PipeBlock.dropItems(world, pos, player);
Block.spawnDrops(state, world, pos, tile, null, ItemStack.EMPTY); Block.spawnDrops(state, world, pos, tile, null, ItemStack.EMPTY);
world.removeBlock(pos, false); world.removeBlock(pos, false);
} }

View file

@ -1,11 +1,9 @@
package de.ellpeck.prettypipes.pipe; package de.ellpeck.prettypipes.pipe;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.types.Func;
import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.network.PipeItem;
import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.network.PipeNetwork;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -271,14 +269,7 @@ public class PipeBlock extends ContainerBlock {
@Override @Override
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); dropItems(worldIn, pos, player);
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); super.onBlockHarvested(worldIn, pos, state, player);
} }
@ -305,4 +296,15 @@ public class PipeBlock extends ContainerBlock {
public BlockRenderType getRenderType(BlockState state) { public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL; 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);
}
}
} }