use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
the class FluidTankList method fillTanksImpl.
// fills exactly one tank if multi-filling is not allowed
// and as much tanks as possible otherwise
// note that it will always try to fill tanks with same fluid first
private int fillTanksImpl(FluidStack resource, boolean doFill) {
int totalFilled = 0;
// first, try to fill tanks that already have same fluid type
for (IFluidTank handler : fluidTanks) {
if (resource.isFluidEqual(handler.getFluid())) {
int filledAmount = handler.fill(resource, doFill);
totalFilled += filledAmount;
resource.amount -= filledAmount;
// if filling multiple tanks is not allowed, or resource is empty, return now
if (!allowSameFluidFill || resource.amount == 0)
return totalFilled;
}
}
// otherwise, try to fill empty tanks
for (IFluidTank handler : fluidTanks) {
if (handler.getFluidAmount() == 0) {
int filledAmount = handler.fill(resource, doFill);
totalFilled += filledAmount;
resource.amount -= filledAmount;
if (!allowSameFluidFill || resource.amount == 0)
return totalFilled;
}
}
return totalFilled;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
the class MetaTileEntityLargeBoiler method setupRecipeAndConsumeInputs.
private int setupRecipeAndConsumeInputs() {
for (IFluidTank fluidTank : fluidImportInventory.getFluidTanks()) {
FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
if (fuelStack == null || ModHandler.isWater(fuelStack))
// ignore empty tanks and water
continue;
FuelRecipe dieselRecipe = RecipeMaps.DIESEL_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
if (dieselRecipe != null) {
int fuelAmountToConsume = (int) Math.ceil(dieselRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
if (fuelStack.amount >= fuelAmountToConsume) {
fluidTank.drain(fuelAmountToConsume, true);
long recipeVoltage = FuelRecipeLogic.getTieredVoltage(dieselRecipe.getMinVoltage());
int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
return (int) Math.ceil(dieselRecipe.getDuration() * CONSUMPTION_MULTIPLIER / 2.0 * voltageMultiplier * getThrottleMultiplier());
} else
continue;
}
FuelRecipe denseFuelRecipe = RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
if (denseFuelRecipe != null) {
int fuelAmountToConsume = (int) Math.ceil(denseFuelRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
if (fuelStack.amount >= fuelAmountToConsume) {
fluidTank.drain(fuelAmountToConsume, true);
long recipeVoltage = FuelRecipeLogic.getTieredVoltage(denseFuelRecipe.getMinVoltage());
int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
return (int) Math.ceil(denseFuelRecipe.getDuration() * CONSUMPTION_MULTIPLIER * 2 * voltageMultiplier * getThrottleMultiplier());
}
}
}
for (int slotIndex = 0; slotIndex < itemImportInventory.getSlots(); slotIndex++) {
ItemStack itemStack = itemImportInventory.getStackInSlot(slotIndex);
int fuelBurnValue = (int) Math.ceil(TileEntityFurnace.getItemBurnTime(itemStack) / (50.0 * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier()));
if (fuelBurnValue > 0) {
if (itemStack.getCount() == 1) {
ItemStack containerItem = itemStack.getItem().getContainerItem(itemStack);
itemImportInventory.setStackInSlot(slotIndex, containerItem);
} else {
itemStack.shrink(1);
itemImportInventory.setStackInSlot(slotIndex, itemStack);
}
return fuelBurnValue;
}
}
return 0;
}
use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCE.
the class MetaTileEntityLargeBoiler method getFuels.
@Override
public Collection<IFuelInfo> getFuels() {
if (!isStructureFormed())
return Collections.emptySet();
final LinkedHashMap<Object, IFuelInfo> fuels = new LinkedHashMap<Object, IFuelInfo>();
// fluid capacity is all non water tanks
int fluidCapacity = 0;
for (IFluidTank fluidTank : fluidImportInventory.getFluidTanks()) {
FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
if (!ModHandler.isWater(fuelStack))
fluidCapacity += fluidTank.getCapacity();
}
for (IFluidTank fluidTank : fluidImportInventory.getFluidTanks()) {
FluidStack fuelStack = fluidTank.drain(Integer.MAX_VALUE, false);
if (fuelStack == null || ModHandler.isWater(fuelStack))
continue;
FuelRecipe dieselRecipe = RecipeMaps.DIESEL_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
if (dieselRecipe != null) {
long recipeVoltage = FuelRecipeLogic.getTieredVoltage(dieselRecipe.getMinVoltage());
int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
int burnTime = (int) Math.ceil(dieselRecipe.getDuration() * CONSUMPTION_MULTIPLIER / 2.0 * voltageMultiplier * getThrottleMultiplier());
int fuelAmountToConsume = (int) Math.ceil(dieselRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
final long fuelBurnTime = (fuelStack.amount * burnTime) / fuelAmountToConsume;
FluidFuelInfo fluidFuelInfo = (FluidFuelInfo) fuels.get(fuelStack.getUnlocalizedName());
if (fluidFuelInfo == null) {
fluidFuelInfo = new FluidFuelInfo(fuelStack, fuelStack.amount, fluidCapacity, fuelAmountToConsume, fuelBurnTime);
fuels.put(fuelStack.getUnlocalizedName(), fluidFuelInfo);
} else {
fluidFuelInfo.addFuelRemaining(fuelStack.amount);
fluidFuelInfo.addFuelBurnTime(fuelBurnTime);
}
}
FuelRecipe denseFuelRecipe = RecipeMaps.SEMI_FLUID_GENERATOR_FUELS.findRecipe(GTValues.V[9], fuelStack);
if (denseFuelRecipe != null) {
long recipeVoltage = FuelRecipeLogic.getTieredVoltage(denseFuelRecipe.getMinVoltage());
int voltageMultiplier = (int) Math.max(1L, recipeVoltage / GTValues.V[GTValues.LV]);
int burnTime = (int) Math.ceil(denseFuelRecipe.getDuration() * CONSUMPTION_MULTIPLIER * 2 * voltageMultiplier * getThrottleMultiplier());
int fuelAmountToConsume = (int) Math.ceil(denseFuelRecipe.getRecipeFluid().amount * CONSUMPTION_MULTIPLIER * boilerType.fuelConsumptionMultiplier * getThrottleMultiplier());
final long fuelBurnTime = (fuelStack.amount * burnTime) / fuelAmountToConsume;
FluidFuelInfo fluidFuelInfo = (FluidFuelInfo) fuels.get(fuelStack.getUnlocalizedName());
if (fluidFuelInfo == null) {
fluidFuelInfo = new FluidFuelInfo(fuelStack, fuelStack.amount, fluidCapacity, fuelAmountToConsume, fuelBurnTime);
fuels.put(fuelStack.getUnlocalizedName(), fluidFuelInfo);
} else {
fluidFuelInfo.addFuelRemaining(fuelStack.amount);
fluidFuelInfo.addFuelBurnTime(fuelBurnTime);
}
}
}
// item capacity is all slots
int itemCapacity = 0;
for (int slotIndex = 0; slotIndex < itemImportInventory.getSlots(); slotIndex++) {
itemCapacity += itemImportInventory.getSlotLimit(slotIndex);
}
for (int slotIndex = 0; slotIndex < itemImportInventory.getSlots(); slotIndex++) {
ItemStack itemStack = itemImportInventory.getStackInSlot(slotIndex);
final long burnTime = (int) Math.ceil(TileEntityFurnace.getItemBurnTime(itemStack) / (50.0 * this.boilerType.fuelConsumptionMultiplier * getThrottleMultiplier()));
if (burnTime > 0) {
ItemFuelInfo itemFuelInfo = (ItemFuelInfo) fuels.get(itemStack.getTranslationKey());
if (itemFuelInfo == null) {
itemFuelInfo = new ItemFuelInfo(itemStack, itemStack.getCount(), itemCapacity, 1, itemStack.getCount() * burnTime);
fuels.put(itemStack.getTranslationKey(), itemFuelInfo);
} else {
itemFuelInfo.addFuelRemaining(itemStack.getCount());
itemFuelInfo.addFuelBurnTime(itemStack.getCount() * burnTime);
}
}
}
return fuels.values();
}
use of net.minecraftforge.fluids.IFluidTank in project Metalworks by canitzp.
the class TileBase method writeCapabilities.
private void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
if (hasEnergyFluidInv().getRight()) {
IItemHandler inventory = this.getInventory(side);
if (inventory instanceof IItemHandlerModifiable) {
nbt.setTag("Inventory", Objects.requireNonNull(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side)));
}
}
if (hasEnergyFluidInv().getMiddle()) {
IFluidHandler tank = getTank(side);
if (tank instanceof IFluidTank) {
nbt.setTag("FluidTank", Objects.requireNonNull(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side)));
}
}
if (hasEnergyFluidInv().getLeft()) {
IEnergyStorage energy = getEnergy(side);
if (energy instanceof CustomEnergyStorage) {
NBTTagCompound energyTag = new NBTTagCompound();
energyTag.setInteger("Stored", energy.getEnergyStored());
energyTag.setInteger("Capacity", energy.getMaxEnergyStored());
energyTag.setInteger("MaxReceive", ((CustomEnergyStorage) energy).getReceiveTransfer());
energyTag.setInteger("MaxExtract", ((CustomEnergyStorage) energy).getExtractTransfer());
nbt.setTag("Energy", energyTag);
}
}
}
use of net.minecraftforge.fluids.IFluidTank in project Solar by ArekkuusuJerii.
the class BlockBlastFurnacePipeGauge method onDrawScreenPost.
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawScreenPost(RenderGameOverlayEvent.Post event) {
Minecraft mc = Minecraft.getMinecraft();
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
RayTraceResult ray = mc.objectMouseOver;
if (ray != null) {
BlockPos pos = ray.typeOfHit == RayTraceResult.Type.BLOCK ? ray.getBlockPos() : null;
IBlockState state = pos != null ? mc.world.getBlockState(pos) : null;
Block block = state == null ? null : state.getBlock();
if (block == this) {
EnumFacing facing = state.getValue(BlockDirectional.FACING);
BlockPos offset = pos.offset(facing);
TileEntity tile = mc.world.getTileEntity(offset);
if (tile != null) {
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
if (handler != null) {
int xc = event.getResolution().getScaledWidth() / 2;
int yc = event.getResolution().getScaledHeight() / 2;
int max = 0;
int amount = 0;
if (handler instanceof IFluidTank) {
max = ((IFluidTank) handler).getCapacity();
amount = ((IFluidTank) handler).getFluidAmount();
} else {
IFluidTankProperties tankProperty = handler.getTankProperties()[0];
max = tankProperty.getCapacity();
if (tankProperty.getContents() != null)
amount += tankProperty.getContents().amount;
}
String s = I18n.format("status.gauge");
String s1 = amount + "/" + max;
mc.fontRenderer.drawStringWithShadow(s, xc - mc.fontRenderer.getStringWidth(s) / 2, yc + 10, 0xFFFFFF);
mc.fontRenderer.drawStringWithShadow(s1, xc - mc.fontRenderer.getStringWidth(s) / 2, yc + 20, 0xFFFFFF);
}
}
}
}
}
}
Aggregations