mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Also made liquifaces and transfer work again
This commit is contained in:
parent
19d764688f
commit
e0d290a330
2 changed files with 77 additions and 8 deletions
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue