From 4058d5abf8f70468af8acb50758da927b2aedf82 Mon Sep 17 00:00:00 2001 From: Sampsa <69092953+S4mpsa@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:25:33 +0300 Subject: Large Large & Larger Turbine Rework (#3075) Co-authored-by: Daniel Mendes Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: NotAPenguin Co-authored-by: Martin Robertz --- .../production/turbines/MTELargeTurbineGas.java | 17 +- .../production/turbines/MTELargeTurbinePlasma.java | 315 -------------------- .../turbines/MTELargeTurbineSCSteam.java | 63 +++- .../turbines/MTELargeTurbineSHSteam.java | 153 +++++----- .../production/turbines/MTELargeTurbineSteam.java | 149 +++++----- .../production/turbines/MTELargerTurbineBase.java | 72 ++--- .../turbines/MTELargerTurbinePlasma.java | 318 +++++++++++++++++++++ .../GregtechLargeTurbinesAndHeatExchanger.java | 4 +- 8 files changed, 552 insertions(+), 539 deletions(-) delete mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbinePlasma.java create mode 100644 src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargerTurbinePlasma.java (limited to 'src/main/java/gtPlusPlus') diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineGas.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineGas.java index e57a7d7e77..31450cc303 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineGas.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineGas.java @@ -25,6 +25,7 @@ import gregtech.api.recipe.check.SimpleCheckRecipeResult; import gregtech.api.recipe.maps.FuelBackend; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; +import gregtech.api.util.TurbineStatCalculator; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @SuppressWarnings("deprecation") @@ -111,7 +112,7 @@ public class MTELargeTurbineGas extends MTELargerTurbineBase { } @Override - long fluidIntoPower(ArrayList aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + long fluidIntoPower(ArrayList aFluids, TurbineStatCalculator turbine) { if (aFluids.size() >= 1) { int tEU = 0; int actualOptimalFlow = 0; @@ -119,17 +120,19 @@ public class MTELargeTurbineGas extends MTELargerTurbineBase { // Doesn't matter which one. Ignore the rest! int fuelValue = getFuelValue(firstFuelType); // log("Fuel Value of "+aFluids.get(0).getLocalizedName()+" is "+fuelValue+"eu"); - if (aOptFlow < fuelValue) { + if (turbine.getOptimalGasEUt() < fuelValue) { // turbine too weak and/or fuel too powerful // at least consume 1L this.realOptFlow = 1; // wastes the extra fuel and generate aOptFlow directly depleteInput(new FluidStack(firstFuelType, 1)); this.storedFluid += 1; - return GTUtility.safeInt((long) aOptFlow * (long) aBaseEff / 10000L); + return GTUtility.safeInt((long) (turbine.getOptimalGasEUt())); } - actualOptimalFlow = GTUtility.safeInt((long) (aOptFlow * (double) flowMultipliers[1] / fuelValue)); + actualOptimalFlow = GTUtility.safeInt( + (long) (getSpeedMultiplier() + * ((isLooseMode() ? turbine.getOptimalLooseGasFlow() : turbine.getOptimalGasFlow()) / fuelValue))); this.realOptFlow = actualOptimalFlow; int remainingFlow = GTUtility.safeInt((long) (actualOptimalFlow * 1.25f)); // Allowed to use up to 125% of @@ -154,11 +157,13 @@ public class MTELargeTurbineGas extends MTELargerTurbineBase { tEU = GTUtility.safeInt((long) totalFlow * fuelValue); if (totalFlow == actualOptimalFlow) { - tEU = GTUtility.safeInt((long) tEU * (long) aBaseEff / 10000L); + tEU = GTUtility.safeInt( + (long) (tEU * (isLooseMode() ? turbine.getLooseGasEfficiency() : turbine.getGasEfficiency()))); } else { float efficiency = 1.0f - Math.abs((totalFlow - actualOptimalFlow) / (float) actualOptimalFlow); tEU *= efficiency; - tEU = GTUtility.safeInt((long) tEU * (long) aBaseEff / 10000L); + tEU = GTUtility.safeInt( + (long) (tEU * (isLooseMode() ? turbine.getLooseGasEfficiency() : turbine.getGasEfficiency()))); } return tEU; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbinePlasma.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbinePlasma.java deleted file mode 100644 index 310463e0d5..0000000000 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbinePlasma.java +++ /dev/null @@ -1,315 +0,0 @@ -package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; - -import java.util.ArrayList; -import java.util.HashSet; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -import org.jetbrains.annotations.NotNull; - -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.items.MetaGeneratedTool; -import gregtech.api.objects.GTRenderedTexture; -import gregtech.api.recipe.RecipeMap; -import gregtech.api.recipe.RecipeMaps; -import gregtech.api.recipe.check.CheckRecipeResult; -import gregtech.api.recipe.check.CheckRecipeResultRegistry; -import gregtech.api.recipe.check.SimpleCheckRecipeResult; -import gregtech.api.recipe.maps.FuelBackend; -import gregtech.api.util.GTRecipe; -import gregtech.api.util.GTUtility; -import gregtech.api.util.shutdown.ShutDownReasonRegistry; -import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.MTEHatchTurbine; -import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; - -@SuppressWarnings("deprecation") -public class MTELargeTurbinePlasma extends MTELargerTurbineBase { - - private static final HashSet BLACKLIST = new HashSet<>(); - - public MTELargeTurbinePlasma(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public MTELargeTurbinePlasma(String aName) { - super(aName); - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new MTELargeTurbinePlasma(mName); - } - - @Override - public int getCasingMeta() { - return 4; - } - - @Override - public int getCasingTextureIndex() { - return 60; - } - - @Override - protected boolean requiresOutputHatch() { - return true; - } - - @Override - public int getPollutionPerSecond(ItemStack aStack) { - return 0; - } - - @Override - public int getFuelValue(FluidStack aLiquid) { - if (aLiquid == null) { - return 0; - } - GTRecipe tFuel = getRecipeMap().getBackend() - .findFuel(aLiquid); - if (tFuel != null) { - return tFuel.mSpecialValue; - } - return 0; - } - - @Override - public RecipeMap getRecipeMap() { - return RecipeMaps.plasmaFuels; - } - - @Override - public int getRecipeCatalystPriority() { - return -20; - } - - @Override - protected boolean filtersFluid() { - return false; - } - - @Override - public @NotNull CheckRecipeResult checkProcessing() { - - try { - ArrayList aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); - if (aEmptyTurbineRotorHatches.size() > 0) { - hatch: for (MTEHatchTurbine aHatch : aEmptyTurbineRotorHatches) { - ArrayList aTurbines = getAllBufferedTurbines(); - for (ItemStack aTurbineItem : aTurbines) { - if (aTurbineItem == null) { - continue; - } - if (aHatch.insertTurbine(aTurbineItem.copy())) { - depleteTurbineFromStock(aTurbineItem); - continue hatch; - } - } - } - } - - if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { - stopMachine(ShutDownReasonRegistry.NO_TURBINE); - return CheckRecipeResultRegistry.NO_TURBINE_FOUND; - } - - ArrayList tFluids = getStoredFluids(); - - if (tFluids.size() > 0) { - for (FluidStack fluid : tFluids) { - if (fluid != null && BLACKLIST.contains(fluid.getFluid())) { - return SimpleCheckRecipeResult.ofFailure("fuel_blacklisted"); - } - } - if (baseEff == 0 || optFlow == 0 - || counter >= 512 - || this.getBaseMetaTileEntity() - .hasWorkJustBeenEnabled() - || this.getBaseMetaTileEntity() - .hasInventoryBeenModified()) { - counter = 0; - - float aTotalBaseEff = 0; - float aTotalOptimalFlow = 0; - - ItemStack aStack = getFullTurbineAssemblies().get(0) - .getTurbine(); - aTotalBaseEff += GTUtility.safeInt( - (long) ((5F + ((MetaGeneratedTool) aStack.getItem()).getToolCombatDamage(aStack)) * 1000F)); - aTotalOptimalFlow += GTUtility - .safeInt( - (long) Math.max( - Float.MIN_NORMAL, - ((MetaGeneratedTool) aStack.getItem()).getToolStats(aStack) - .getSpeedMultiplier() * MetaGeneratedTool.getPrimaryMaterial(aStack).mToolSpeed - * 50)); - - // Calculate total EU/t (as shown on turbine tooltip (Fast mode doesn't affect)) - double aEUPerTurbine = aTotalOptimalFlow * 40 - * 0.0105 - * MetaGeneratedTool.getPrimaryMaterial(aStack).mPlasmaMultiplier - * (50.0f + (10.0f * ((MetaGeneratedTool) aStack.getItem()).getToolCombatDamage(aStack))); - aTotalOptimalFlow *= getSpeedMultiplier(); - - if (aTotalOptimalFlow < 0) { - aTotalOptimalFlow = 100; - } - - flowMultipliers[0] = MetaGeneratedTool.getPrimaryMaterial(aStack).mSteamMultiplier; - flowMultipliers[1] = MetaGeneratedTool.getPrimaryMaterial(aStack).mGasMultiplier; - flowMultipliers[2] = MetaGeneratedTool.getPrimaryMaterial(aStack).mPlasmaMultiplier; - baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); - optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); - euPerTurbine = MathUtils.roundToClosestInt(aEUPerTurbine); - if (optFlow <= 0 || baseEff <= 0) { - stopMachine(ShutDownReasonRegistry.NONE); // in case the turbine got removed - return CheckRecipeResultRegistry.NO_FUEL_FOUND; - } - } else { - counter++; - } - } - - // How much the turbine should be producing with this flow - long newPower = fluidIntoPower(tFluids, optFlow, baseEff, flowMultipliers); - - // Reduce produced power depending on the ratio between fuel value and turbine EU/t with the following - // formula: - // EU/t = EU/t * MIN(1, ( ( (FuelValue / 200) ^ 2 ) / EUPerTurbine)) - int fuelValue = 0; - if (tFluids.size() > 0) { - fuelValue = getFuelValue(new FluidStack(tFluids.get(0), 0)); - } - float magicValue = (fuelValue * 0.005f) * (fuelValue * 0.005f); - float efficiencyLoss = Math.min(1.0f, magicValue / euPerTurbine); - newPower *= efficiencyLoss; - - long difference = newPower - this.lEUt; // difference between current output and new output - - // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the - // difference in power level (per tick) - // This is how much the turbine can actually change during this tick - int maxChangeAllowed = Math.max(10, GTUtility.safeInt((long) Math.abs(difference) / 100)); - - if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed - // change - int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. - this.lEUt += change; // Apply the change - } else { - this.lEUt = newPower; - } - if (this.lEUt <= 0) { - this.lEUt = 0; - this.mEfficiency = 0; - return CheckRecipeResultRegistry.NO_FUEL_FOUND; - } else { - this.mMaxProgresstime = 20; - this.mEfficiencyIncrease = 10; - // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. - // Play sounds (GT++ addition - GT multiblocks play no sounds) - enableAllTurbineHatches(); - return CheckRecipeResultRegistry.GENERATING; - } - } catch (Throwable t) { - t.printStackTrace(); - } - return CheckRecipeResultRegistry.NO_FUEL_FOUND; - } - - @Override - long fluidIntoPower(ArrayList aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { - if (aFluids.size() >= 1) { - aOptFlow *= 800; // CHANGED THINGS HERE, check recipe runs once per 20 ticks - int tEU = 0; - - int actualOptimalFlow = 0; - - FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. - // Doesn't matter which one. Ignore the rest! - int fuelValue = getFuelValue(firstFuelType); - actualOptimalFlow = GTUtility - .safeInt((long) Math.ceil((double) aOptFlow * (double) flowMultipliers[2] / (double) fuelValue)); - this.realOptFlow = actualOptimalFlow; // For scanner info - - int remainingFlow = GTUtility.safeInt((long) (actualOptimalFlow * 1.25f)); // Allowed to use up to 125% of - // optimal flow. Variable - // required outside of loop for - // multi-hatch scenarios. - int flow = 0; - int totalFlow = 0; - - storedFluid = 0; - for (FluidStack aFluid : aFluids) { - if (aFluid.isFluidEqual(firstFuelType)) { - flow = Math.min(aFluid.amount, remainingFlow); // try to use up w/o exceeding remainingFlow - depleteInput(new FluidStack(aFluid, flow)); // deplete that amount - this.storedFluid += aFluid.amount; - remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches - totalFlow += flow; // track total input used - } - } - String fn = FluidRegistry.getFluidName(firstFuelType); - String[] nameSegments = fn.split("\\.", 2); - if (nameSegments.length == 2) { - String outputName = nameSegments[1]; - FluidStack output = FluidRegistry.getFluidStack(outputName, totalFlow); - if (output == null) { - output = FluidRegistry.getFluidStack("molten." + outputName, totalFlow); - } - if (output != null) { - addOutput(output); - } - } - if (totalFlow <= 0) return 0; - tEU = GTUtility.safeInt((long) ((fuelValue / 20D) * (double) totalFlow)); - - if (totalFlow == actualOptimalFlow) { - tEU = GTUtility.safeInt((long) (aBaseEff / 10000D * tEU)); - } else { - double efficiency = 1.0D - Math.abs((totalFlow - actualOptimalFlow) / (float) actualOptimalFlow); - - tEU = (int) (tEU * efficiency); - tEU = GTUtility.safeInt((long) (aBaseEff / 10000D * tEU)); - } - - return tEU; - } - return 0; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 1; - } - - @Override - public String getMachineType() { - return "Large Plasma Turbine"; - } - - @Override - protected String getTurbineType() { - return "Plasma"; - } - - @Override - protected String getCasingName() { - return "Reinforced Plasma Turbine Casing"; - } - - @Override - protected ITexture getTextureFrontFace() { - return new GTRenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced); - } - - @Override - protected ITexture getTextureFrontFaceActive() { - return new GTRenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active); - } -} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSCSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSCSteam.java index 0ef3ef0256..a608cbfc07 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSCSteam.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSCSteam.java @@ -6,17 +6,23 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; +import gregtech.api.enums.Materials; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTUtility; +import gregtech.api.util.TurbineStatCalculator; +import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; public class MTELargeTurbineSCSteam extends MTELargerTurbineBase { + private boolean hasConsumedSteam; + private boolean isUsingDenseSteam; + public MTELargeTurbineSCSteam(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -56,47 +62,88 @@ public class MTELargeTurbineSCSteam extends MTELargerTurbineBase { } @Override - long fluidIntoPower(ArrayList aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + long fluidIntoPower(ArrayList aFluids, TurbineStatCalculator turbine) { + int tEU = 0; int totalFlow = 0; // Byproducts are based on actual flow int flow = 0; + float denseFlow = 0; + float steamFlowForNextSteam = 0; + int steamInHatch = 0; // Variable required outside of loop for // multi-hatch scenarios. - this.realOptFlow = aOptFlow; + this.realOptFlow = getSpeedMultiplier() + * (looseFit ? turbine.getOptimalLooseSteamFlow() : turbine.getOptimalSteamFlow()); // this.realOptFlow = (double) aOptFlow * (double) flowMultipliers[0]; // Will there be an multiplier for SC? int remainingFlow = MathUtils.safeInt((long) (realOptFlow * 1.25f)); // Allowed to use up to // 125% of optimal flow. + float remainingDenseFlow = 0; storedFluid = 0; FluidStack tSCSteam = FluidRegistry.getFluidStack("supercriticalsteam", 1); for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { + String fluidName = aFluids.get(i) + .getFluid() + .getUnlocalizedName(aFluids.get(i)); if (GTUtility.areFluidsEqual(aFluids.get(i), tSCSteam, true)) { + if (!hasConsumedSteam) { + hasConsumedSteam = true; + isUsingDenseSteam = false; + } else if (isUsingDenseSteam) { + continue; + } flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount this.storedFluid += aFluids.get(i).amount; remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches totalFlow += flow; // track total input used + } else if (fluidName.equals("fluid.densesupercriticalsteam")) { + if (!hasConsumedSteam) { + hasConsumedSteam = true; + isUsingDenseSteam = true; + } else if (!isUsingDenseSteam) { + continue; + } + steamInHatch = aFluids.get(i).amount; + remainingDenseFlow = (float) remainingFlow / 1000; // Dense Steam is 1000x the EU value + denseFlow = Math.min(steamInHatch, remainingDenseFlow); // try to use up w/o exceeding + // remainingDenseFlow + depleteInput(new FluidStack(aFluids.get(i), (int) denseFlow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= denseFlow * 1000; // track amount we're allowed to continue depleting from hatches + totalFlow += denseFlow * 1000; // track total input used + steamFlowForNextSteam += denseFlow; } } if (totalFlow <= 0) return 0; - tEU = totalFlow; - addOutput(GTModHandler.getSteam(totalFlow * 100)); + tEU = totalFlow; // SC Steam has 1 EU per litre so the flow equals base EU produced + if (isUsingDenseSteam) { + addOutput(Materials.DenseSuperheatedSteam.getGas((long) steamFlowForNextSteam)); + } else { + addOutput(GTModHandler.getSteam(totalFlow * 100)); + } if (totalFlow != realOptFlow) { float efficiency = 1.0f - Math.abs((totalFlow - (float) realOptFlow) / (float) realOptFlow); // if(totalFlow>aOptFlow){efficiency = 1.0f;} tEU *= efficiency; - tEU = Math.max(1, MathUtils.safeInt((long) tEU * (long) aBaseEff / 10000L)); + tEU = Math.max( + 1, + MathUtils.safeInt( + (long) (tEU * (looseFit ? turbine.getLooseSteamEfficiency() : turbine.getSteamEfficiency())))); } else { - tEU = MathUtils.safeInt((long) tEU * (long) aBaseEff / 10000L); + tEU = MathUtils + .safeInt((long) (tEU * (looseFit ? turbine.getLooseSteamEfficiency() : turbine.getSteamEfficiency()))); + } + if (isUsingDenseSteam) { + return tEU; } - return tEU * 100L; } @Override public int getDamageToComponent(ItemStack aStack) { - return 8; + return (looseFit && GTPPCore.RANDOM.nextInt(4) == 0) ? 0 : 1; } @Override diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSHSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSHSteam.java index 7fdc36450d..afa13de0be 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSHSteam.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSHSteam.java @@ -2,29 +2,26 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.t import java.util.ArrayList; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import gregtech.GTMod; +import gregtech.api.enums.Materials; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GTRenderedTexture; import gregtech.api.util.GTModHandler; -import gregtech.api.util.GTUtility; +import gregtech.api.util.TurbineStatCalculator; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @SuppressWarnings("deprecation") public class MTELargeTurbineSHSteam extends MTELargerTurbineBase { public boolean achievement = false; - private boolean looseFit = false; + private boolean isUsingDenseSteam; public MTELargeTurbineSHSteam(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -65,118 +62,106 @@ public class MTELargeTurbineSHSteam extends MTELargerTurbineBase { } @Override - long fluidIntoPower(ArrayList aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { - if (looseFit) { - aOptFlow *= 4; - if (aBaseEff > 10000) { - aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); - aBaseEff = 7500; - } else if (aBaseEff > 7500) { - aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); - aBaseEff *= 0.75f; - } else { - aBaseEff *= 0.75f; - } - } - // prevent overflow like that in SC Steam + long fluidIntoPower(ArrayList aFluids, TurbineStatCalculator turbine) { + long tEU = 0; int totalFlow = 0; // Byproducts are based on actual flow int flow = 0; + float denseFlow = 0; + float steamFlowForNextSteam = 0; + int steamInHatch = 0; // Variable required outside of loop for // multi-hatch scenarios. - this.realOptFlow = aOptFlow * flowMultipliers[0]; + this.realOptFlow = getSpeedMultiplier() + * (looseFit ? turbine.getOptimalLooseSteamFlow() : turbine.getOptimalSteamFlow()); int remainingFlow = MathUtils.safeInt((long) (realOptFlow * 1.25f)); // Allowed to use up to // 125% of optimal flow. + float remainingDenseFlow = 0; + + boolean hasConsumedSteam = false; storedFluid = 0; for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { String fluidName = aFluids.get(i) .getFluid() .getUnlocalizedName(aFluids.get(i)); - if (fluidName.equals("ic2.fluidSuperheatedSteam")) { - flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow - depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount - this.storedFluid += aFluids.get(i).amount; - remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches - totalFlow += flow; // track total input used - if (!achievement) { - try { - GTMod.achievements.issueAchievement( - this.getBaseMetaTileEntity() - .getWorld() - .getPlayerEntityByName( - this.getBaseMetaTileEntity() - .getOwnerName()), - "efficientsteam"); - } catch (Exception e) {} - achievement = true; + switch (fluidName) { + case "ic2.fluidSuperheatedSteam" -> { + if (!hasConsumedSteam) { + hasConsumedSteam = true; + isUsingDenseSteam = false; + } else if (isUsingDenseSteam) { + continue; + } + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + if (!achievement) { + try { + GTMod.achievements.issueAchievement( + this.getBaseMetaTileEntity() + .getWorld() + .getPlayerEntityByName( + this.getBaseMetaTileEntity() + .getOwnerName()), + "efficientsteam"); + } catch (Exception e) {} + achievement = true; + } } - } else if (fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") - || fluidName.equals("fluid.mfr.steam.still.name")) { - depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + case "fluid.densesuperheatedsteam" -> { + if (!hasConsumedSteam) { + hasConsumedSteam = true; + isUsingDenseSteam = true; + } else if (!isUsingDenseSteam) { + continue; + } + steamInHatch = aFluids.get(i).amount; + remainingDenseFlow = (float) remainingFlow / 1000; // Dense Steam is 1000x the EU value + denseFlow = Math.min(steamInHatch, remainingDenseFlow); // try to use up w/o exceeding + // remainingDenseFlow + depleteInput(new FluidStack(aFluids.get(i), (int) denseFlow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= denseFlow * 1000; // track amount we're allowed to continue depleting from hatches + totalFlow += denseFlow * 1000; // track total input used + steamFlowForNextSteam += denseFlow; } + case "fluid.steam", "ic2.fluidSteam", "fluid.mfr.steam.still.name" -> depleteInput( + new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + } } if (totalFlow <= 0) return 0; - tEU = totalFlow; - addOutput(GTModHandler.getSteam(totalFlow)); + tEU = totalFlow; // SH Steam has 1 EU per litre so the flow equals base EU produced + if (isUsingDenseSteam) { + addOutput(Materials.DenseSteam.getGas((long) steamFlowForNextSteam)); + } else { + addOutput(GTModHandler.getSteam(totalFlow)); + } if (totalFlow != realOptFlow) { float efficiency = 1.0f - Math.abs((totalFlow - (float) realOptFlow) / (float) realOptFlow); // if(totalFlow>aOptFlow){efficiency = 1.0f;} tEU *= efficiency; - tEU = Math.max(1L, tEU * aBaseEff / 10000L); + tEU = Math.max( + 1, + MathUtils.safeInt( + (long) (tEU * (looseFit ? turbine.getLooseSteamEfficiency() : turbine.getSteamEfficiency())))); } else { - tEU = tEU * aBaseEff / 10000L; + tEU = MathUtils + .safeInt((long) (tEU * (looseFit ? turbine.getLooseSteamEfficiency() : turbine.getSteamEfficiency()))); } return tEU; } - @Override - public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { - // Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode - // Whenever there's a mode switch, there will be two messages on the player chat - // The two messages specify which two modes the turbine is on after the change - // (Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) - if (side == getBaseMetaTileEntity().getFrontFacing()) { - looseFit ^= true; - GTUtility.sendChatToPlayer( - aPlayer, - looseFit ? "Fitting is Loose (Higher Flow)" : "Fitting is Tight (Higher Efficiency)"); - } - - if (looseFit) { - super.onModeChangeByScrewdriver(side, aPlayer, aX, aY, aZ); - } else if (mFastMode) { - PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); - } else { - PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); - } - } - @Override public int getDamageToComponent(ItemStack aStack) { return (looseFit && GTPPCore.RANDOM.nextInt(4) == 0) ? 0 : 1; } - @Override - public boolean isLooseMode() { - return looseFit; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("turbineFitting", looseFit); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - looseFit = aNBT.getBoolean("turbineFitting"); - } - @Override public String getMachineType() { return "Large Super-heated Steam Turbine"; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSteam.java index 68cfc8cd1e..72a50cacf3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSteam.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargeTurbineSteam.java @@ -4,10 +4,7 @@ import static gtPlusPlus.core.lib.GTPPCore.RANDOM; import java.util.ArrayList; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import gregtech.GTMod; @@ -16,9 +13,8 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GTRenderedTexture; import gregtech.api.util.GTModHandler; -import gregtech.api.util.GTUtility; +import gregtech.api.util.TurbineStatCalculator; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @SuppressWarnings("deprecation") @@ -26,7 +22,7 @@ public class MTELargeTurbineSteam extends MTELargerTurbineBase { private float water; private boolean achievement = false; - private boolean looseFit = false; + private boolean isUsingDenseSteam; public MTELargeTurbineSteam(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -74,32 +70,27 @@ public class MTELargeTurbineSteam extends MTELargerTurbineBase { } @Override - long fluidIntoPower(ArrayList aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { - if (looseFit) { - aOptFlow *= 4; - if (aBaseEff > 10000) { - aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); - aBaseEff = 7500; - } else if (aBaseEff > 7500) { - aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); - aBaseEff *= 0.75f; - } else { - aBaseEff *= 0.75f; - } - } - // prevent overflow like that in SC Steam + long fluidIntoPower(ArrayList aFluids, TurbineStatCalculator turbine) { + long tEU = 0; int totalFlow = 0; // Byproducts are based on actual flow int flow = 0; + float denseFlow = 0; + float steamFlowForWater = 0; + int steamInHatch = 0; // Variable required outside of loop for // multi-hatch scenarios. - this.realOptFlow = aOptFlow * flowMultipliers[0]; + this.realOptFlow = getSpeedMultiplier() + * (looseFit ? turbine.getOptimalLooseSteamFlow() : turbine.getOptimalSteamFlow()); int remainingFlow = MathUtils.safeInt((long) (realOptFlow * 1.25f)); // Allowed to // use up to // 125% of // optimal flow. + float remainingDenseFlow = 0; + + boolean hasConsumedSteam = false; storedFluid = 0; for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { // loop through each hatch; extract inputs and @@ -107,87 +98,81 @@ public class MTELargeTurbineSteam extends MTELargerTurbineBase { String fluidName = aFluids.get(i) .getFluid() .getUnlocalizedName(aFluids.get(i)); - if (fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") - || fluidName.equals("fluid.mfr.steam.still.name")) { - flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow - depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount - this.storedFluid += aFluids.get(i).amount; - remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches - totalFlow += flow; // track total input used - if (!achievement) { - GTMod.achievements.issueAchievement( - this.getBaseMetaTileEntity() - .getWorld() - .getPlayerEntityByName( - this.getBaseMetaTileEntity() - .getOwnerName()), - "muchsteam"); - achievement = true; + switch (fluidName) { + case "fluid.steam", "ic2.fluidSteam", "fluid.mfr.steam.still.name" -> { + if (!hasConsumedSteam) { + hasConsumedSteam = true; + isUsingDenseSteam = false; + } else if (isUsingDenseSteam) { + continue; + } + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + if (!achievement) { + GTMod.achievements.issueAchievement( + this.getBaseMetaTileEntity() + .getWorld() + .getPlayerEntityByName( + this.getBaseMetaTileEntity() + .getOwnerName()), + "muchsteam"); + achievement = true; + } + } + case "fluid.densesteam" -> { + if (!hasConsumedSteam) { + hasConsumedSteam = true; + isUsingDenseSteam = true; + } else if (!isUsingDenseSteam) { + continue; + } + steamInHatch = aFluids.get(i).amount; + remainingDenseFlow = (float) remainingFlow / 1000; // Dense Steam is 1000x the EU value + denseFlow = Math.min(steamInHatch, remainingDenseFlow); // try to use up w/o exceeding + // remainingDenseFlow + depleteInput(new FluidStack(aFluids.get(i), (int) denseFlow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= denseFlow * 1000; // track amount we're allowed to continue depleting from hatches + totalFlow += denseFlow * 1000; // track total input used + steamFlowForWater += denseFlow * 1000; } - } else if (fluidName.equals("ic2.fluidSuperheatedSteam")) { - depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + case "ic2.fluidSuperheatedSteam" -> depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); } } if (totalFlow <= 0) return 0; - tEU = totalFlow; - int waterToOutput = useWater(totalFlow / 160.0f); + tEU = (long) (totalFlow * 0.5f); + int waterToOutput; + if (isUsingDenseSteam) { + // Water return is lower to counteract water generation from rounding errors + waterToOutput = useWater(steamFlowForWater / 160.1f); + } else { + waterToOutput = useWater(totalFlow / 160.0f); + } addOutput(GTModHandler.getDistilledWater(waterToOutput)); if (totalFlow != realOptFlow) { float efficiency = 1.0f - Math.abs((totalFlow - (float) realOptFlow) / (float) realOptFlow); // if(totalFlow>aOptFlow){efficiency = 1.0f;} tEU *= efficiency; - tEU = Math.max(1L, tEU * aBaseEff / 20000L); + tEU = Math.max( + 1, + MathUtils.safeInt( + (long) (tEU * (looseFit ? turbine.getLooseSteamEfficiency() : turbine.getSteamEfficiency())))); } else { - tEU = tEU * aBaseEff / 20000L; + tEU = MathUtils + .safeInt((long) (tEU * (looseFit ? turbine.getLooseSteamEfficiency() : turbine.getSteamEfficiency()))); } return tEU; } - @Override - public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { - // Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode - // Whenever there's a mode switch, there will be two messages on the player chat - // The two messages specify which two modes the turbine is on after the change - // (Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) - if (side == getBaseMetaTileEntity().getFrontFacing()) { - looseFit ^= true; - GTUtility.sendChatToPlayer( - aPlayer, - looseFit ? "Fitting: Loose - More Flow" : "Fitting: Tight - More Efficiency"); - } - - if (looseFit) { - super.onModeChangeByScrewdriver(side, aPlayer, aX, aY, aZ); - } else if (mFastMode) { - PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); - } else { - PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); - } - } - @Override public int getDamageToComponent(ItemStack aStack) { return (looseFit && RANDOM.nextInt(4) == 0) ? 0 : 1; } - @Override - public boolean isLooseMode() { - return looseFit; - } - - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("turbineFitting", looseFit); - } - - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - looseFit = aNBT.getBoolean("turbineFitting"); - } - @Override public String getMachineType() { return "Large Steam Turbine"; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargerTurbineBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargerTurbineBase.java index 0bd1397137..079983e337 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargerTurbineBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/MTELargerTurbineBase.java @@ -45,6 +45,7 @@ import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; +import gregtech.api.util.TurbineStatCalculator; import gregtech.api.util.shutdown.ShutDownReason; import gregtech.api.util.shutdown.ShutDownReasonRegistry; import gtPlusPlus.api.objects.Logger; @@ -53,7 +54,6 @@ import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.MTEHatchTurbine; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GTPPMultiBlockBase; @@ -67,7 +67,7 @@ public abstract class MTELargerTurbineBase extends GTPPMultiBlockBase tFluids = getStoredFluids(); + ItemStack aStack = getFullTurbineAssemblies().get(0) + .getTurbine(); + + TurbineStatCalculator turbine = new TurbineStatCalculator((MetaGeneratedTool) aStack.getItem(), aStack); + if (tFluids.size() > 0) { if (baseEff == 0 || optFlow == 0 || counter >= 512 @@ -461,25 +464,15 @@ public abstract class MTELargerTurbineBase extends GTPPMultiBlockBase aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers); + abstract long fluidIntoPower(ArrayList aFluids, TurbineStatCalculator turbine); @Override public int getDamageToComponent(ItemStack aStack) { @@ -572,7 +565,7 @@ public abstract class MTELargerTurbineBase extends GTPPMultiBlockBase BLACKLIST = new HashSet<>(); + + public MTELargerTurbinePlasma(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public MTELargerTurbinePlasma(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTELargerTurbinePlasma(mName); + } + + @Override + public int getCasingMeta() { + return 4; + } + + @Override + public int getCasingTextureIndex() { + return 60; + } + + @Override + protected boolean requiresOutputHatch() { + return true; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 0; + } + + @Override + public int getFuelValue(FluidStack aLiquid) { + if (aLiquid == null) { + return 0; + } + GTRecipe tFuel = getRecipeMap().getBackend() + .findFuel(aLiquid); + if (tFuel != null) { + return tFuel.mSpecialValue; + } + return 0; + } + + @Override + public RecipeMap getRecipeMap() { + return RecipeMaps.plasmaFuels; + } + + @Override + public int getRecipeCatalystPriority() { + return -20; + } + + @Override + protected boolean filtersFluid() { + return false; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + + try { + ArrayList aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); + if (aEmptyTurbineRotorHatches.size() > 0) { + hatch: for (MTEHatchTurbine aHatch : aEmptyTurbineRotorHatches) { + ArrayList aTurbines = getAllBufferedTurbines(); + for (ItemStack aTurbineItem : aTurbines) { + if (aTurbineItem == null) { + continue; + } + if (aHatch.insertTurbine(aTurbineItem.copy())) { + depleteTurbineFromStock(aTurbineItem); + continue hatch; + } + } + } + } + + if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { + stopMachine(ShutDownReasonRegistry.NO_TURBINE); + return CheckRecipeResultRegistry.NO_TURBINE_FOUND; + } + + // At this point all turbines are equivalent in all hatches, use the stats of the first turbine for + // calculations + ItemStack turbineItem = mTurbineRotorHatches.get(0) + .getTurbine(); + TurbineStatCalculator turbine = new TurbineStatCalculator( + (MetaGeneratedTool) turbineItem.getItem(), + turbineItem); + + ArrayList tFluids = getStoredFluids(); + + if (tFluids.size() > 0) { + for (FluidStack fluid : tFluids) { + if (fluid != null && BLACKLIST.contains(fluid.getFluid())) { + return SimpleCheckRecipeResult.ofFailure("fuel_blacklisted"); + } + } + if (baseEff == 0 || optFlow == 0 + || counter >= 512 + || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity() + .hasInventoryBeenModified()) { + counter = 0; + + float aTotalBaseEff = 0; + float aTotalOptimalFlow = 0; + + ItemStack aStack = getFullTurbineAssemblies().get(0) + .getTurbine(); + aTotalBaseEff += turbine.getPlasmaEfficiency() * 10000; + aTotalOptimalFlow += turbine.getOptimalPlasmaFlow(); + + // Calculate total EU/t (as shown on turbine tooltip (Fast mode doesn't affect)) + double aEUPerTurbine = turbine.getOptimalPlasmaEUt(); + aTotalOptimalFlow *= getSpeedMultiplier(); + + if (aTotalOptimalFlow < 0) { + aTotalOptimalFlow = 100; + } + + flowMultipliers[0] = MetaGeneratedTool.getPrimaryMaterial(aStack).mSteamMultiplier; + flowMultipliers[1] = MetaGeneratedTool.getPrimaryMaterial(aStack).mGasMultiplier; + flowMultipliers[2] = MetaGeneratedTool.getPrimaryMaterial(aStack).mPlasmaMultiplier; + baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); + optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); + euPerTurbine = MathUtils.roundToClosestInt(aEUPerTurbine); + if (optFlow <= 0 || baseEff <= 0) { + stopMachine(ShutDownReasonRegistry.NONE); // in case the turbine got removed + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + } else { + counter++; + } + } + + // How much the turbine should be producing with this flow + long newPower = fluidIntoPower(tFluids, turbine); + + // Reduce produced power depending on the ratio between fuel value and turbine EU/t with the following + // formula: + // EU/t = EU/t * MIN(1, ( ( (FuelValue / 200) ^ 2 ) / EUPerTurbine)) + int fuelValue = 0; + if (tFluids.size() > 0) { + fuelValue = getFuelValue(new FluidStack(tFluids.get(0), 0)); + } + float magicValue = (fuelValue * 0.005f) * (fuelValue * 0.005f); + float efficiencyLoss = Math.min(1.0f, magicValue / euPerTurbine); + newPower *= efficiencyLoss; + + long difference = newPower - this.lEUt; // difference between current output and new output + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the + // difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(10, GTUtility.safeInt((long) Math.abs(difference) / 100)); + + if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed + // change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.lEUt += change; // Apply the change + } else { + this.lEUt = newPower; + } + if (this.lEUt <= 0) { + this.lEUt = 0; + this.mEfficiency = 0; + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } else { + this.mMaxProgresstime = 20; + this.mEfficiencyIncrease = 200; + // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. + // Play sounds (GT++ addition - GT multiblocks play no sounds) + enableAllTurbineHatches(); + return CheckRecipeResultRegistry.GENERATING; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + + long fluidIntoPower(ArrayList aFluids, Turbine