Also made liquifaces and transfer work again

This commit is contained in:
Ellpeck 2016-06-10 22:00:30 +02:00
parent 19d764688f
commit e0d290a330
2 changed files with 77 additions and 8 deletions

View file

@ -14,9 +14,13 @@ import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; 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; import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
public class TileEntityPhantomLiquiface extends TileEntityPhantomface{ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{
public TileEntityPhantomLiquiface(){ public TileEntityPhantomLiquiface(){
super("liquiface"); super("liquiface");
@ -41,9 +45,61 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface{
if(super.isBoundThingInRange()){ if(super.isBoundThingInRange()){
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition); TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
if(tile != null){ if(tile != null){
return tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); return tile instanceof IFluidHandler || tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
} }
} }
return false; 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;
}
} }

View file

@ -108,13 +108,26 @@ public class WorldUtil{
public static void pushFluid(TileEntity tileFrom, EnumFacing side){ public static void pushFluid(TileEntity tileFrom, EnumFacing side){
TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos()); TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos());
if(tileTo != null){ if(tileTo != null){
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo;
if(handlerFrom != null && handlerTo != null){ net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom;
FluidStack drain = handlerFrom.drain(Integer.MAX_VALUE, false); FluidStack drain = handlerFrom.drain(side, Integer.MAX_VALUE, false);
if(drain != null){ if(drain != null){
int filled = handlerTo.fill(drain.copy(), true); if(handlerTo.canFill(side.getOpposite(), drain.getFluid())){
handlerFrom.drain(filled, true); 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);
}
} }
} }
} }