use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
the class FluidTankList method drain.
@Nullable
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
if (resource == null || resource.amount <= 0) {
return null;
}
resource = resource.copy();
FluidStack totalDrained = null;
for (IFluidTank handler : fluidTanks) {
if (!resource.isFluidEqual(handler.getFluid())) {
continue;
}
FluidStack drain = handler.drain(resource.amount, doDrain);
if (drain == null) {
continue;
}
if (totalDrained == null) {
totalDrained = drain;
} else
totalDrained.amount += drain.amount;
resource.amount -= drain.amount;
if (resource.amount == 0)
break;
}
return totalDrained;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
the class FuelRecipeLogic method getFuels.
@Override
public Collection<IFuelInfo> getFuels() {
if (!isReadyForRecipes())
return Collections.emptySet();
final IMultipleTankHandler fluidTanks = this.fluidTank.get();
if (fluidTanks == null)
return Collections.emptySet();
final LinkedHashMap<String, IFuelInfo> fuels = new LinkedHashMap<>();
// Fuel capacity is all tanks
int fuelCapacity = 0;
for (IFluidTank fluidTank : fluidTanks) {
fuelCapacity += fluidTank.getCapacity();
}
for (IFluidTank fluidTank : fluidTanks) {
final FluidStack tankContents = fluidTank.drain(Integer.MAX_VALUE, false);
if (tankContents == null || tankContents.amount <= 0)
continue;
int fuelRemaining = tankContents.amount;
FuelRecipe recipe = findRecipe(tankContents);
if (recipe == null)
continue;
int amountPerRecipe = calculateFuelAmount(recipe);
int duration = calculateRecipeDuration(recipe);
long fuelBurnTime = (duration * fuelRemaining) / amountPerRecipe;
FluidFuelInfo fuelInfo = (FluidFuelInfo) fuels.get(tankContents.getUnlocalizedName());
if (fuelInfo == null) {
fuelInfo = new FluidFuelInfo(tankContents, fuelRemaining, fuelCapacity, amountPerRecipe, fuelBurnTime);
fuels.put(tankContents.getUnlocalizedName(), fuelInfo);
} else {
fuelInfo.addFuelRemaining(fuelRemaining);
fuelInfo.addFuelBurnTime(fuelBurnTime);
}
}
return fuels.values();
}
use of net.minecraftforge.fluids.IFluidTank in project pnc-repressurized by TeamPneumatic.
the class RenderPlasticMixer method render.
@Override
public void render(TileEntityPlasticMixer te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
IFluidTank tank = te.getTank();
if (tank.getFluidAmount() == 0)
return;
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
AxisAlignedBB bounds = getRenderBounds(tank);
PneumaticCraftUtils.renderFluid(tank.getFluid().getFluid(), bounds);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.popMatrix();
}
use of net.minecraftforge.fluids.IFluidTank in project ForestryMC by ForestryMC.
the class BiogasSlot method getToolTip.
@Override
public ToolTip getToolTip(int mouseX, int mouseY) {
ToolTip toolTip = new ToolTip();
IFluidTank tank = getTank();
if (tank != null) {
FluidStack fluid = tank.getFluid();
if (fluid == null) {
toolTip.add(Translator.translateToLocal("for.gui.empty"));
} else {
toolTip.add(fluid.getLocalizedName());
}
}
return toolTip;
}
use of net.minecraftforge.fluids.IFluidTank in project ForestryMC by ForestryMC.
the class ContainerLiquidTanksHelper method handlePipetteClick.
@Override
public void handlePipetteClick(int slot, EntityPlayerMP player) {
ItemStack itemstack = player.inventory.getItemStack();
Item held = itemstack.getItem();
if (!(held instanceof IToolPipette)) {
return;
}
IToolPipette pipette = (IToolPipette) held;
IFluidTank tank = tile.getTankManager().getTank(slot);
int liquidAmount = tank.getFluidAmount();
IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(itemstack);
if (fluidHandlerItem != null) {
if (pipette.canPipette(itemstack) && liquidAmount > 0) {
if (liquidAmount > 0) {
if (tank instanceof FluidTank) {
FluidStack fillAmount = ((FluidTank) tank).drainInternal(Fluid.BUCKET_VOLUME, false);
int filled = fluidHandlerItem.fill(fillAmount, true);
tank.drain(filled, true);
player.inventory.setItemStack(fluidHandlerItem.getContainer());
player.updateHeldItem();
}
}
} else {
FluidStack potential = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
if (potential != null) {
if (tank instanceof FluidTank) {
int fill = ((FluidTank) tank).fillInternal(potential, true);
fluidHandlerItem.drain(fill, true);
player.inventory.setItemStack(fluidHandlerItem.getContainer());
player.updateHeldItem();
}
}
}
}
}
Aggregations