Fix fluids now flowing after being placed

Closes #5
This commit is contained in:
Shadowfacts 2016-12-10 13:48:57 -05:00
parent ed28182ba5
commit cb91c531e4
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 24 additions and 23 deletions

View File

@ -1,6 +1,8 @@
package net.shadowfacts.funnels; package net.shadowfacts.funnels;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -63,33 +65,32 @@ public class TileEntityFunnel extends BaseTileEntity implements ITickable {
} }
} }
world: tick++;
{ if (tick % 40 == 0) {
tick++;
if (tick % 40 == 0) {
// pickup from world // pickup from world
if (FunnelsConfig.pickupWorldFluids && tank.getFluidAmount() <= tank.getCapacity() - Fluid.BUCKET_VOLUME) { if (FunnelsConfig.pickupWorldFluids && tank.getFluidAmount() <= tank.getCapacity() - Fluid.BUCKET_VOLUME) {
tick = 0; tick = 0;
if (FluidUtils.isFluidBlock(world, pos.up())) { if (FluidUtils.isFluidBlock(world, pos.up())) {
FluidStack toDrain = FluidUtils.drainFluidBlock(world, pos.up(), false); FluidStack toDrain = FluidUtils.drainFluidBlock(world, pos.up(), false);
if (toDrain.amount <= tank.getCapacity() - tank.getFluidAmount()) { if (toDrain.amount <= tank.getCapacity() - tank.getFluidAmount()) {
tank.fill(FluidUtils.drainFluidBlock(world, pos.up(), true), true); tank.fill(FluidUtils.drainFluidBlock(world, pos.up(), true), true);
save(); save();
break world; return;
}
} }
} }
}
// place in world // place in world
if (FunnelsConfig.placeFluidsInWorld && tank.getFluidAmount() >= Fluid.BUCKET_VOLUME) { if (FunnelsConfig.placeFluidsInWorld && tank.getFluidAmount() >= Fluid.BUCKET_VOLUME) {
FluidStack fluid = tank.getFluid(); FluidStack fluid = tank.getFluid();
if (fluid.getFluid().canBePlacedInWorld()) { if (fluid.getFluid().canBePlacedInWorld()) {
Block fluidBlock = fluid.getFluid().getBlock(); Block fluidBlock = fluid.getFluid().getBlock();
BlockPos newPos = pos.offset(world.getBlockState(pos).getValue(BlockFunnel.FACING)); if (fluidBlock instanceof BlockLiquid) fluidBlock = BlockLiquid.getFlowingBlock(fluidBlock.getMaterial(fluidBlock.getDefaultState()));
if (fluidBlock.canPlaceBlockAt(world, newPos)) {
tank.drain(Fluid.BUCKET_VOLUME, true); BlockPos newPos = pos.offset(world.getBlockState(pos).getValue(BlockFunnel.FACING));
save(); if (fluidBlock.canPlaceBlockAt(world, newPos)) {
world.setBlockState(newPos, fluidBlock.getDefaultState()); tank.drain(Fluid.BUCKET_VOLUME, true);
} save();
world.setBlockState(newPos, fluidBlock.getDefaultState());
} }
} }
} }