Worked on Inf Fluid debug block

This commit is contained in:
DarkGuardsman 2013-09-23 13:34:24 -04:00
parent 91cb7c22a2
commit 2a1b375597

View file

@ -1,8 +1,99 @@
package dark.core.common.debug;
import dark.core.prefab.helpers.FluidHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
public class TileEntityInfFluid extends TileEntity
public class TileEntityInfFluid extends TileEntity implements IFluidHandler, IDebugTile
{
FluidTank tank = new FluidTank(Integer.MAX_VALUE);
boolean autoEmpty = false;
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return 0;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
if (resource != null)
{
if (tank == null || tank.getFluid() == null)
{
tank = new FluidTank(Integer.MAX_VALUE);
tank.setFluid(new FluidStack(FluidRegistry.WATER, Integer.MAX_VALUE));
}
if (tank != null && tank.getFluid() != null && tank.getFluid().containsFluid(resource))
{
return resource.copy();
}
}
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return this.tank != null && this.tank.getFluid() != null ? this.drain(from, FluidHelper.getStack(this.tank.getFluid(), maxDrain), doDrain) : null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return false;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return fluid != null && this.tank != null && this.tank.getFluid() != null && this.tank.getFluid().getFluid().equals(fluid);
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return new FluidTankInfo[] { this.tank.getInfo() };
}
@Override
public boolean onActivated(EntityPlayer entityPlayer)
{
if (entityPlayer != null && entityPlayer.getHeldItem() != null)
{
ItemStack held = entityPlayer.getHeldItem();
if (held.itemID == Item.stick.itemID)
{
if (!this.worldObj.isRemote)
{
this.autoEmpty = !autoEmpty;
}
return true;
}
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(held);
if (fluidStack != null)
{
if (!this.worldObj.isRemote)
{
fluidStack = fluidStack.copy();
fluidStack.amount = Integer.MAX_VALUE;
this.tank.setFluid(fluidStack);
}
return true;
}
}
return false;
}
}