From e0d290a330164b04e86d3a352856484ae156349b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 10 Jun 2016 22:00:30 +0200 Subject: [PATCH] Also made liquifaces and transfer work again --- .../mod/tile/TileEntityPhantomLiquiface.java | 60 ++++++++++++++++++- .../actuallyadditions/mod/util/WorldUtil.java | 25 ++++++-- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java index f5d968757..258c93de6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java @@ -14,9 +14,13 @@ import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -public class TileEntityPhantomLiquiface extends TileEntityPhantomface{ +public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{ public TileEntityPhantomLiquiface(){ super("liquiface"); @@ -41,9 +45,61 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface{ if(super.isBoundThingInRange()){ TileEntity tile = this.worldObj.getTileEntity(this.boundPosition); if(tile != null){ - return tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); + return tile instanceof IFluidHandler || tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); } } return false; } + + @Override + public int fill(EnumFacing from, FluidStack resource, boolean doFill){ + if(this.isBoundThingInRange()){ + return this.getHandler().fill(from, resource, doFill); + } + return 0; + } + + @Override + public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){ + if(this.isBoundThingInRange()){ + return this.getHandler().drain(from, resource, doDrain); + } + return null; + } + + @Override + public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){ + if(this.isBoundThingInRange()){ + return this.getHandler().drain(from, maxDrain, doDrain); + } + return null; + } + + @Override + public boolean canFill(EnumFacing from, Fluid fluid){ + return this.isBoundThingInRange() && this.getHandler().canFill(from, fluid); + } + + @Override + public boolean canDrain(EnumFacing from, Fluid fluid){ + return this.isBoundThingInRange() && this.getHandler().canDrain(from, fluid); + } + + @Override + public FluidTankInfo[] getTankInfo(EnumFacing from){ + if(this.isBoundThingInRange()){ + return this.getHandler().getTankInfo(from); + } + return new FluidTankInfo[0]; + } + + public IFluidHandler getHandler(){ + if(this.boundPosition != null){ + TileEntity tile = this.worldObj.getTileEntity(this.boundPosition); + if(tile instanceof IFluidHandler){ + return (IFluidHandler)tile; + } + } + return null; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index 63653a285..9fe929c89 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -108,13 +108,26 @@ public class WorldUtil{ public static void pushFluid(TileEntity tileFrom, EnumFacing side){ TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos()); if(tileTo != null){ - IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); - IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); - if(handlerFrom != null && handlerTo != null){ - FluidStack drain = handlerFrom.drain(Integer.MAX_VALUE, false); + if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){ + net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo; + net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom; + FluidStack drain = handlerFrom.drain(side, Integer.MAX_VALUE, false); if(drain != null){ - int filled = handlerTo.fill(drain.copy(), true); - handlerFrom.drain(filled, true); + if(handlerTo.canFill(side.getOpposite(), drain.getFluid())){ + int filled = handlerTo.fill(side.getOpposite(), drain.copy(), true); + handlerFrom.drain(side, filled, true); + } + } + } + else{ + IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); + IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); + if(handlerFrom != null && handlerTo != null){ + FluidStack drain = handlerFrom.drain(Integer.MAX_VALUE, false); + if(drain != null){ + int filled = handlerTo.fill(drain.copy(), true); + handlerFrom.drain(filled, true); + } } } }