use of net.minecraftforge.fluids.IFluidTank in project pnc-repressurized by TeamPneumatic.
the class DroneAILiquidExport method fillTank.
private boolean fillTank(BlockPos pos, boolean simulate) {
IFluidTank droneTank = drone.getTank();
if (droneTank.getFluidAmount() == 0) {
drone.addDebugEntry("gui.progWidget.liquidExport.debug.emptyDroneTank");
abort();
return false;
} else {
TileEntity te = drone.world().getTileEntity(pos);
if (te != null) {
FluidStack exportedFluid = droneTank.drain(Integer.MAX_VALUE, false);
if (exportedFluid != null && ((ILiquidFiltered) widget).isFluidValid(exportedFluid.getFluid())) {
for (int i = 0; i < 6; i++) {
if (((ISidedWidget) widget).getSides()[i] && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.byIndex(i))) {
IFluidHandler tank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.byIndex(i));
int filledAmount = tank.fill(exportedFluid, false);
if (filledAmount > 0) {
if (((ICountWidget) widget).useCount()) {
filledAmount = Math.min(filledAmount, getRemainingCount());
}
if (!simulate) {
decreaseCount(tank.fill(droneTank.drain(filledAmount, true), true));
}
return true;
}
}
}
drone.addDebugEntry("gui.progWidget.liquidExport.debug.filledToMax", pos);
} else {
drone.addDebugEntry("gui.progWidget.liquidExport.debug.noValidFluid");
}
} else if (((ILiquidExport) widget).isPlacingFluidBlocks() && (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000)) {
Block fluidBlock = droneTank.getFluid().getFluid().getBlock();
World w = drone.world();
if (droneTank.getFluidAmount() >= 1000 && fluidBlock != null && isBlockSuitableForExport(w, pos)) {
if (!simulate) {
decreaseCount(1000);
droneTank.drain(1000, true);
w.setBlockState(pos, fluidBlock.getDefaultState());
}
return true;
}
}
return false;
}
}
use of net.minecraftforge.fluids.IFluidTank in project pnc-repressurized by TeamPneumatic.
the class FastFluidTESR method doRender.
private void doRender(T te, double x, double y, double z, BufferBuilder buffer, TankRenderInfo tankRenderInfo) {
IFluidTank tank = tankRenderInfo.tank;
if (tank.getFluidAmount() == 0)
return;
Fluid f = tank.getFluid().getFluid();
TextureAtlasSprite still = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(f.getStill().toString());
float u1 = still.getMinU(), v1 = still.getMinV(), u2 = still.getMaxU(), v2 = still.getMaxV();
buffer.setTranslation(x, y, z);
AxisAlignedBB bounds = getRenderBounds(tank, tankRenderInfo.bounds);
if (tankRenderInfo.shouldRender(EnumFacing.DOWN)) {
int downCombined = getWorld().getCombinedLight(te.getPos().down(), 0);
int downLMa = downCombined >> 16 & 65535;
int downLMb = downCombined & 65535;
buffer.pos(bounds.minX, bounds.minY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v2).lightmap(downLMa, downLMb).endVertex();
buffer.pos(bounds.minX, bounds.minY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v1).lightmap(downLMa, downLMb).endVertex();
buffer.pos(bounds.maxX, bounds.minY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v1).lightmap(downLMa, downLMb).endVertex();
buffer.pos(bounds.maxX, bounds.minY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v2).lightmap(downLMa, downLMb).endVertex();
}
if (tankRenderInfo.shouldRender(EnumFacing.UP)) {
int upCombined = getWorld().getCombinedLight(te.getPos().up(), 0);
int upLMa = upCombined >> 16 & 65535;
int upLMb = upCombined & 65535;
buffer.pos(bounds.minX, bounds.maxY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v2).lightmap(upLMa, upLMb).endVertex();
buffer.pos(bounds.maxX, bounds.maxY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v2).lightmap(upLMa, upLMb).endVertex();
buffer.pos(bounds.maxX, bounds.maxY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v1).lightmap(upLMa, upLMb).endVertex();
buffer.pos(bounds.minX, bounds.maxY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v1).lightmap(upLMa, upLMb).endVertex();
}
if (tankRenderInfo.shouldRender(EnumFacing.NORTH)) {
int northCombined = getWorld().getCombinedLight(te.getPos().north(), 0);
int northLMa = northCombined >> 16 & 65535;
int northLMb = northCombined & 65535;
buffer.pos(bounds.minX, bounds.minY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v1).lightmap(northLMa, northLMb).endVertex();
buffer.pos(bounds.minX, bounds.maxY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v2).lightmap(northLMa, northLMb).endVertex();
buffer.pos(bounds.maxX, bounds.maxY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v2).lightmap(northLMa, northLMb).endVertex();
buffer.pos(bounds.maxX, bounds.minY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v1).lightmap(northLMa, northLMb).endVertex();
}
if (tankRenderInfo.shouldRender(EnumFacing.SOUTH)) {
int southCombined = getWorld().getCombinedLight(te.getPos().south(), 0);
int southLMa = southCombined >> 16 & 65535;
int southLMb = southCombined & 65535;
buffer.pos(bounds.maxX, bounds.minY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v1).lightmap(southLMa, southLMb).endVertex();
buffer.pos(bounds.maxX, bounds.maxY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v2).lightmap(southLMa, southLMb).endVertex();
buffer.pos(bounds.minX, bounds.maxY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v2).lightmap(southLMa, southLMb).endVertex();
buffer.pos(bounds.minX, bounds.minY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v1).lightmap(southLMa, southLMb).endVertex();
}
if (tankRenderInfo.shouldRender(EnumFacing.WEST)) {
int westCombined = getWorld().getCombinedLight(te.getPos().west(), 0);
int westLMa = westCombined >> 16 & 65535;
int westLMb = westCombined & 65535;
buffer.pos(bounds.minX, bounds.minY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v2).lightmap(westLMa, westLMb).endVertex();
buffer.pos(bounds.minX, bounds.maxY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v2).lightmap(westLMa, westLMb).endVertex();
buffer.pos(bounds.minX, bounds.maxY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v1).lightmap(westLMa, westLMb).endVertex();
buffer.pos(bounds.minX, bounds.minY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v1).lightmap(westLMa, westLMb).endVertex();
}
if (tankRenderInfo.shouldRender(EnumFacing.EAST)) {
int eastCombined = getWorld().getCombinedLight(te.getPos().east(), 0);
int eastLMa = eastCombined >> 16 & 65535;
int eastLMb = eastCombined & 65535;
buffer.pos(bounds.maxX, bounds.minY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v1).lightmap(eastLMa, eastLMb).endVertex();
buffer.pos(bounds.maxX, bounds.maxY, bounds.minZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v1).lightmap(eastLMa, eastLMb).endVertex();
buffer.pos(bounds.maxX, bounds.maxY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u2, v2).lightmap(eastLMa, eastLMb).endVertex();
buffer.pos(bounds.maxX, bounds.minY, bounds.maxZ).color(1.0f, 1.0f, 1.0f, FLUID_ALPHA).tex(u1, v2).lightmap(eastLMa, eastLMb).endVertex();
}
}
use of net.minecraftforge.fluids.IFluidTank in project pnc-repressurized by TeamPneumatic.
the class GuiLogisticsBase method actionPerformed.
@Override
public void actionPerformed(IGuiWidget widget) {
super.actionPerformed(widget);
if (widget instanceof WidgetFluidStack) {
boolean leftClick = Mouse.isButtonDown(0);
boolean middleClick = Mouse.isButtonDown(2);
boolean shift = PneumaticCraftRepressurized.proxy.isSneakingInGui();
IFluidTank tank = logistics.getTankFilter(widget.getID());
if (tank.getFluidAmount() > 0) {
if (middleClick) {
logistics.setFilter(widget.getID(), null);
} else if (leftClick) {
tank.drain(shift ? tank.getFluidAmount() / 2 : 1000, true);
if (tank.getFluidAmount() < 1000) {
tank.drain(1000, true);
}
} else {
tank.fill(new FluidStack(tank.getFluid().getFluid(), shift ? tank.getFluidAmount() : 1000), true);
}
NetworkHandler.sendToServer(new PacketSetLogisticsFluidFilterStack(logistics, tank.getFluid(), widget.getID()));
} else {
fluidSearchGui = new GuiLogisticsLiquidFilter(this);
editingSlot = widget.getID();
mc.displayGuiScreen(fluidSearchGui);
}
}
}
use of net.minecraftforge.fluids.IFluidTank in project TinkersConstruct by SlimeKnights.
the class MelterFuelWrapper method consumeFuel.
/**
* Drains one copy of fuel from the given tank
* @param fuel Fuel to drain
* @return Ticks of fuel units
*/
public int consumeFuel(MeltingFuel fuel) {
IFluidTank tank = this.tank.get();
if (tank != null) {
int amount = fuel.getAmount(this);
if (amount > 0) {
// TODO: assert drained valid?
int drained = tank.drain(amount, FluidAction.EXECUTE).getAmount();
int duration = fuel.getDuration();
if (drained < amount) {
return duration * drained / amount;
} else {
return duration;
}
}
}
return 0;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.
the class BoilerRecipeLogic method trySearchNewRecipe.
@Override
protected void trySearchNewRecipe() {
MetaTileEntityLargeBoiler boiler = (MetaTileEntityLargeBoiler) metaTileEntity;
if (ConfigHolder.machines.enableMaintenance && boiler.hasMaintenanceMechanics() && boiler.getNumMaintenanceProblems() > 5) {
return;
}
// can optimize with an override of checkPreviousRecipe() and a check here
IMultipleTankHandler importFluids = boiler.getImportFluids();
List<ItemStack> dummyList = NonNullList.create();
boolean didStartRecipe = false;
for (IFluidTank fluidTank : importFluids.getFluidTanks()) {
FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
if (fuelStack == null || ModHandler.isWater(fuelStack))
continue;
Recipe dieselRecipe = RecipeMaps.COMBUSTION_GENERATOR_FUELS.findRecipe(GTValues.V[GTValues.MAX], dummyList, Collections.singletonList(fuelStack), Integer.MAX_VALUE, MatchingMode.IGNORE_ITEMS);
// run only if it can apply a certain amount of "parallel", this is to mitigate int division
if (dieselRecipe != null && fuelStack.amount >= dieselRecipe.getFluidInputs().get(0).amount * FLUID_DRAIN_MULTIPLIER) {
fluidTank.drain(dieselRecipe.getFluidInputs().get(0).amount * FLUID_DRAIN_MULTIPLIER, true);
// divide by 2, as it is half burntime for combustion
setMaxProgress(adjustBurnTimeForThrottle(Math.max(1, boiler.boilerType.runtimeBoost((Math.abs(dieselRecipe.getEUt()) * dieselRecipe.getDuration()) / FLUID_BURNTIME_TO_EU / 2))));
didStartRecipe = true;
break;
}
Recipe denseFuelRecipe = RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.findRecipe(GTValues.V[GTValues.MAX], dummyList, Collections.singletonList(fuelStack), Integer.MAX_VALUE, MatchingMode.IGNORE_ITEMS);
// run only if it can apply a certain amount of "parallel", this is to mitigate int division
if (denseFuelRecipe != null && fuelStack.amount >= denseFuelRecipe.getFluidInputs().get(0).amount * FLUID_DRAIN_MULTIPLIER) {
fluidTank.drain(denseFuelRecipe.getFluidInputs().get(0).amount * FLUID_DRAIN_MULTIPLIER, true);
// multiply by 2, as it is 2x burntime for semi-fluid
setMaxProgress(adjustBurnTimeForThrottle(Math.max(1, boiler.boilerType.runtimeBoost((Math.abs(denseFuelRecipe.getEUt()) * denseFuelRecipe.getDuration() / FLUID_BURNTIME_TO_EU * 2)))));
didStartRecipe = true;
break;
}
}
if (!didStartRecipe) {
IItemHandlerModifiable importItems = boiler.getImportItems();
for (int i = 0; i < importItems.getSlots(); i++) {
ItemStack stack = importItems.getStackInSlot(i);
int fuelBurnTime = (int) Math.ceil(ModHandler.getFuelValue(stack));
if (fuelBurnTime / 80 > 0) {
// try to ensure this fuel can burn for at least 1 tick
if (FluidUtil.getFluidHandler(stack) != null)
continue;
this.excessFuel += fuelBurnTime % 80;
int excessProgress = this.excessFuel / 80;
this.excessFuel %= 80;
setMaxProgress(excessProgress + adjustBurnTimeForThrottle(boiler.boilerType.runtimeBoost(fuelBurnTime / 80)));
stack.shrink(1);
didStartRecipe = true;
break;
}
}
}
if (didStartRecipe) {
this.progressTime = 1;
this.recipeEUt = adjustEUtForThrottle(boiler.boilerType.steamPerTick());
if (wasActiveAndNeedsUpdate) {
wasActiveAndNeedsUpdate = false;
} else {
setActive(true);
}
}
metaTileEntity.getNotifiedItemInputList().clear();
metaTileEntity.getNotifiedFluidInputList().clear();
}
Aggregations