Search in sources :

Example 1 with IFuelInfo

use of gregtech.api.capability.IFuelInfo 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();
}
Also used : IFuelInfo(gregtech.api.capability.IFuelInfo) FluidFuelInfo(gregtech.api.capability.impl.FluidFuelInfo) FluidStack(net.minecraftforge.fluids.FluidStack) ItemFuelInfo(gregtech.api.capability.impl.ItemFuelInfo) FuelRecipe(gregtech.api.recipes.recipes.FuelRecipe) ItemStack(net.minecraft.item.ItemStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with IFuelInfo

use of gregtech.api.capability.IFuelInfo in project GregTech by GregTechCE.

the class FuelableInfoProvider method addProbeInfo.

@Override
protected void addProbeInfo(IFuelable capability, IProbeInfo probeInfo, TileEntity tileEntity, EnumFacing sideHit) {
    Collection<IFuelInfo> fuels = capability.getFuels();
    if (fuels == null || fuels.isEmpty()) {
        probeInfo.text(TextStyleClass.WARNING + "{*gregtech.top.fuel_none*}");
        return;
    }
    for (IFuelInfo fuelInfo : fuels) {
        final String fuelName = fuelInfo.getFuelName();
        final int fuelRemaining = fuelInfo.getFuelRemaining();
        final int fuelCapacity = fuelInfo.getFuelCapacity();
        final int fuelMinConsumed = fuelInfo.getFuelMinConsumed();
        final long burnTime = fuelInfo.getFuelBurnTimeLong() / 20;
        IProbeInfo horizontalPane = probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
        if (fuelInfo instanceof ItemFuelInfo) {
            horizontalPane.text(TextStyleClass.INFO + "{*gregtech.top.fuel_name*} ").itemLabel(((ItemFuelInfo) fuelInfo).getItemStack());
        } else {
            horizontalPane.text(TextStyleClass.INFO + "{*gregtech.top.fuel_name*} {*" + fuelName + "*}");
        }
        horizontalPane = probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
        horizontalPane.progress(fuelRemaining, fuelCapacity, probeInfo.defaultProgressStyle().suffix("/" + fuelCapacity + " ").borderColor(0x00000000).backgroundColor(0x00000000).filledColor(0xFFFFE000).alternateFilledColor(0xFFEED000));
        if (fuelRemaining < fuelMinConsumed)
            horizontalPane.text("{*gregtech.top.fuel_min_consume*} " + fuelMinConsumed);
        else
            horizontalPane.text("{*gregtech.top.fuel_burn*} " + burnTime + " {*gregtech.top.fuel_time*}");
    }
}
Also used : IFuelInfo(gregtech.api.capability.IFuelInfo) ItemFuelInfo(gregtech.api.capability.impl.ItemFuelInfo) IProbeInfo(mcjty.theoneprobe.api.IProbeInfo)

Aggregations

IFuelInfo (gregtech.api.capability.IFuelInfo)2 ItemFuelInfo (gregtech.api.capability.impl.ItemFuelInfo)2 FluidFuelInfo (gregtech.api.capability.impl.FluidFuelInfo)1 FuelRecipe (gregtech.api.recipes.recipes.FuelRecipe)1 LinkedHashMap (java.util.LinkedHashMap)1 IProbeInfo (mcjty.theoneprobe.api.IProbeInfo)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidTank (net.minecraftforge.fluids.IFluidTank)1