use of gregtech.api.recipes.recipes.FuelRecipe in project GregTech by GregTechCE.
the class FuelRecipeLogic method tryAcquireNewRecipe.
private int tryAcquireNewRecipe(FluidStack fluidStack) {
FuelRecipe currentRecipe;
if (previousRecipe != null && previousRecipe.matches(getMaxVoltage(), fluidStack)) {
// if previous recipe still matches inputs, try to use it
currentRecipe = previousRecipe;
} else {
// else, try searching new recipe for given inputs
currentRecipe = recipeMap.findRecipe(getMaxVoltage(), fluidStack);
// if we found recipe that can be buffered, buffer it
if (currentRecipe != null) {
this.previousRecipe = currentRecipe;
}
}
if (currentRecipe != null && checkRecipe(currentRecipe)) {
int fuelAmountToUse = calculateFuelAmount(currentRecipe);
if (fluidStack.amount >= fuelAmountToUse) {
this.recipeDurationLeft = calculateRecipeDuration(currentRecipe);
this.recipeOutputVoltage = startRecipe(currentRecipe, fuelAmountToUse, recipeDurationLeft);
if (wasActiveAndNeedsUpdate) {
this.wasActiveAndNeedsUpdate = false;
} else {
setActive(true);
}
return fuelAmountToUse;
}
}
return 0;
}
use of gregtech.api.recipes.recipes.FuelRecipe in project GregTech by GregTechCE.
the class FuelRecipeMap method addRecipe.
@ZenMethod
public void addRecipe(FuelRecipe fuelRecipe) {
FluidKey fluidKey = new FluidKey(fuelRecipe.getRecipeFluid());
if (recipeFluidMap.containsKey(fluidKey)) {
FuelRecipe oldRecipe = recipeFluidMap.remove(fluidKey);
recipeList.remove(oldRecipe);
}
recipeFluidMap.put(fluidKey, fuelRecipe);
recipeList.add(fuelRecipe);
}
use of gregtech.api.recipes.recipes.FuelRecipe 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 gregtech.api.recipes.recipes.FuelRecipe 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 gregtech.api.recipes.recipes.FuelRecipe 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();
}
Aggregations