diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java index ee8ae4c..dc3da6b 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java @@ -2,7 +2,11 @@ package de.ellpeck.prettypipes.network; import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import net.minecraft.block.BlockState; +import net.minecraft.block.ILiquidContainer; import net.minecraft.entity.item.ItemEntity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.IFluidState; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; @@ -12,6 +16,8 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.INBTSerializable; @@ -26,7 +32,7 @@ import java.util.Collection; import java.util.List; import java.util.function.Consumer; -public class PipeItem implements INBTSerializable { +public class PipeItem implements INBTSerializable, ILiquidContainer { public ItemStack stack; public float speed; @@ -80,13 +86,13 @@ public class PipeItem implements INBTSerializable { float currSpeed = this.speed; BlockPos myPos = new BlockPos(this.x, this.y, this.z); - if (!myPos.equals(currPipe.getPos()) && (this.reachedDestination() || !myPos.equals(this.startInventory))) { + if (!myPos.equals(currPipe.getPos()) && (currPipe.getPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) { // we're done with the current pipe, so switch to the next one currPipe.getItems().remove(this); PipeTileEntity next = this.getNextTile(currPipe, true); if (next == null) { if (!currPipe.getWorld().isRemote) { - if (this.reachedDestination()) { + if (currPipe.getPos().equals(this.getDestPipe())) { // ..or store in our destination container if we reached our destination this.stack = this.store(currPipe); if (!this.stack.isEmpty()) @@ -106,7 +112,7 @@ public class PipeItem implements INBTSerializable { BlockPos nextPos; PipeTileEntity next = this.getNextTile(currPipe, false); if (next == null) { - if (this.reachedDestination()) { + if (currPipe.getPos().equals(this.getDestPipe())) { nextPos = this.destInventory; } else { currPipe.getItems().remove(this); @@ -173,10 +179,6 @@ public class PipeItem implements INBTSerializable { return ItemHandlerHelper.insertItemStacked(handler, this.stack, false); } - private boolean reachedDestination() { - return this.currentTile >= this.path.size() - 1; - } - private PipeTileEntity getNextTile(PipeTileEntity currPipe, boolean progress) { if (this.path.size() <= this.currentTile + 1) return null; @@ -276,4 +278,14 @@ public class PipeItem implements INBTSerializable { items.add(new PipeItem(list.getCompound(i))); return items; } + + @Override + public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) { + return true; + } + + @Override + public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) { + return false; + } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 37f6734..aed122c 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -9,10 +9,14 @@ import net.minecraft.block.material.Material; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.EnumProperty; import net.minecraft.state.StateContainer; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tags.FluidTags; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; @@ -55,7 +59,7 @@ public class PipeBlock extends ContainerBlock { public PipeBlock() { super(Block.Properties.create(Material.ROCK).hardnessAndResistance(2).sound(SoundType.STONE).notSolid()); - BlockState state = this.getDefaultState(); + BlockState state = this.getDefaultState().with(BlockStateProperties.WATERLOGGED, false); for (EnumProperty prop : DIRECTIONS.values()) state = state.with(prop, ConnectionType.DISCONNECTED); this.setDefaultState(state); @@ -78,6 +82,12 @@ public class PipeBlock extends ContainerBlock { @Override protected void fillStateContainer(StateContainer.Builder builder) { builder.add(DIRECTIONS.values().toArray(new EnumProperty[0])); + builder.add(BlockStateProperties.WATERLOGGED); + } + + @Override + public IFluidState getFluidState(BlockState state) { + return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); } @Override @@ -95,6 +105,13 @@ public class PipeBlock extends ContainerBlock { return this.createState(context.getWorld(), context.getPos(), this.getDefaultState()); } + @Override + public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { + if (stateIn.get(BlockStateProperties.WATERLOGGED)) + worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); + return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + } + @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { onStateChanged(worldIn, pos, state); @@ -122,6 +139,10 @@ public class PipeBlock extends ContainerBlock { private BlockState createState(World world, BlockPos pos, BlockState curr) { BlockState state = this.getDefaultState(); + IFluidState fluid = world.getFluidState(pos); + if (fluid.isTagged(FluidTags.WATER) && fluid.getLevel() == 8) + state = state.with(BlockStateProperties.WATERLOGGED, true); + for (Direction dir : Direction.values()) { EnumProperty prop = DIRECTIONS.get(dir); ConnectionType type = getConnectionType(world, pos, dir, state); @@ -201,7 +222,6 @@ public class PipeBlock extends ContainerBlock { PipeNetwork network = PipeNetwork.get(worldIn); network.removeNode(pos); network.onPipeChanged(pos, state); - network.getItemsInPipe(pos).clear(); super.onReplaced(state, worldIn, pos, newState, isMoving); } } diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index 2e6695d..ac78093 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -196,6 +196,12 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide return builder.build(); } + @Override + public void remove() { + super.remove(); + this.getItems().clear(); + } + @Override public ITextComponent getDisplayName() { return new TranslationTextComponent("container." + PrettyPipes.ID + ".pipe");