2015-01-08 06:26:53 +01:00
|
|
|
package mekanism.common.tile;
|
|
|
|
|
2016-03-01 19:37:19 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2015-01-08 06:26:53 +01:00
|
|
|
import mekanism.common.content.boiler.BoilerSteamTank;
|
|
|
|
import mekanism.common.content.boiler.BoilerTank;
|
|
|
|
import mekanism.common.content.boiler.BoilerWaterTank;
|
|
|
|
import mekanism.common.util.PipeUtils;
|
2016-03-01 19:37:19 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-01-08 06:26:53 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
|
|
|
|
2016-02-11 00:30:16 +01:00
|
|
|
public class TileEntityBoilerValve extends TileEntityBoilerCasing implements IFluidHandler
|
2015-01-08 06:26:53 +01:00
|
|
|
{
|
|
|
|
public BoilerTank waterTank;
|
|
|
|
public BoilerTank steamTank;
|
|
|
|
|
2016-02-11 00:30:16 +01:00
|
|
|
public TileEntityBoilerValve()
|
2015-01-08 06:26:53 +01:00
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
super("BoilerValve");
|
|
|
|
|
2015-01-08 06:26:53 +01:00
|
|
|
waterTank = new BoilerWaterTank(this);
|
|
|
|
steamTank = new BoilerSteamTank(this);
|
|
|
|
}
|
2016-03-01 19:37:19 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
super.onUpdate();
|
|
|
|
|
|
|
|
if(!worldObj.isRemote)
|
|
|
|
{
|
|
|
|
if(structure != null && structure.upperRenderLocation != null && yCoord >= structure.upperRenderLocation.yCoord)
|
|
|
|
{
|
|
|
|
if(structure.steamStored != null && structure.steamStored.amount > 0)
|
|
|
|
{
|
|
|
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
TileEntity tile = Coord4D.get(this).getFromSide(side).getTileEntity(worldObj);
|
|
|
|
|
|
|
|
if(tile instanceof IFluidHandler && !(tile instanceof TileEntityBoilerValve))
|
|
|
|
{
|
|
|
|
if(((IFluidHandler)tile).canFill(side.getOpposite(), structure.steamStored.getFluid()))
|
|
|
|
{
|
|
|
|
structure.steamStored.amount -= ((IFluidHandler)tile).fill(side.getOpposite(), structure.steamStored, true);
|
|
|
|
|
|
|
|
if(structure.steamStored.amount <= 0)
|
|
|
|
{
|
|
|
|
structure.steamStored = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-08 06:26:53 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure))
|
|
|
|
{
|
|
|
|
if(structure.upperRenderLocation != null && yCoord >= structure.upperRenderLocation.yCoord)
|
|
|
|
{
|
|
|
|
return new FluidTankInfo[] {steamTank.getInfo()};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return new FluidTankInfo[] {waterTank.getInfo()};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PipeUtils.EMPTY;
|
2015-01-08 06:26:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if(structure != null && structure.upperRenderLocation != null && yCoord < structure.upperRenderLocation.yCoord)
|
|
|
|
{
|
|
|
|
return waterTank.fill(resource, doFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-01-08 06:26:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if(structure != null && structure.upperRenderLocation != null && yCoord >= structure.upperRenderLocation.yCoord)
|
2015-01-08 06:26:53 +01:00
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if(structure.steamStored != null)
|
2015-01-08 06:26:53 +01:00
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if(resource.getFluid() == structure.steamStored.getFluid())
|
|
|
|
{
|
|
|
|
return steamTank.drain(resource.amount, doDrain);
|
|
|
|
}
|
2015-01-08 06:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if(structure != null && structure.upperRenderLocation != null && yCoord >= structure.upperRenderLocation.yCoord)
|
2015-01-08 06:26:53 +01:00
|
|
|
{
|
|
|
|
return steamTank.drain(maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid)
|
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure))
|
|
|
|
{
|
|
|
|
return structure.upperRenderLocation != null && yCoord < structure.upperRenderLocation.yCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-01-08 06:26:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
|
|
|
{
|
2016-03-01 19:37:19 +01:00
|
|
|
if((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure))
|
|
|
|
{
|
|
|
|
return structure.upperRenderLocation != null && yCoord >= structure.upperRenderLocation.yCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-01-08 06:26:53 +01:00
|
|
|
}
|
|
|
|
}
|