diff options
author | BlueWeabo <76872108+BlueWeabo@users.noreply.github.com> | 2022-09-23 20:21:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-23 19:21:40 +0200 |
commit | 6990cc6c82e070f35b91d386b729228b64855c9b (patch) | |
tree | 0bd4d74f2864f583b64079fa53a626957b881907 /src/main/java/gtPlusPlus/xmod/gregtech/common | |
parent | 9ff8d7475cd1e8cd4d43273340a7eca37af95d98 (diff) | |
download | GT5-Unofficial-6990cc6c82e070f35b91d386b729228b64855c9b.tar.gz GT5-Unofficial-6990cc6c82e070f35b91d386b729228b64855c9b.tar.bz2 GT5-Unofficial-6990cc6c82e070f35b91d386b729228b64855c9b.zip |
XL Plasma consumes every tick instead of second (#363)
* fixes
* remove commented code to appease reviewer
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common')
-rw-r--r-- | src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java | 123 |
1 files changed, 122 insertions, 1 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java index f856e4ba95..b665844593 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java @@ -3,10 +3,13 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.t import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; import java.util.ArrayList; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidRegistry; @@ -60,6 +63,125 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur } @Override + public boolean checkRecipeGeneric( + ItemStack[] aItemInputs, + FluidStack[] aFluidInputs, + int aMaxParallelRecipes, + long aEUPercent, + int aSpeedBonusPercent, + int aOutputChanceRoll, + GT_Recipe aRecipe) { + + try { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); + if (aEmptyTurbineRotorHatches.size() > 0) { + log("Found " + aEmptyTurbineRotorHatches.size() + " Assemblies without Turbine."); + hatch: + for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { + ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); + for (ItemStack aTurbineItem : aTurbines) { + if (aTurbineItem == null) { + continue; + } + if (aHatch.insertTurbine(aTurbineItem.copy())) { + boolean aDidDeplete = depleteTurbineFromStock(aTurbineItem); + log("Put Turbine into Assembly - " + aDidDeplete); + continue hatch; + } + } + } + } + + if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { + log("BAD RETURN - 1"); + stopMachine(); + return false; + } + + ArrayList<FluidStack> tFluids = getStoredFluids(); + + if (tFluids.size() > 0) { + 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(); + for (int i = 0; i < getSpeedMultiplier(); i++) { + if (i == 0) { + aTotalBaseEff += GT_Utility.safeInt((long) + ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) + * 1000F)); + } + aTotalOptimalFlow += GT_Utility.safeInt((long) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()) + .getToolStats(aStack) + .getSpeedMultiplier() + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed + * 50)); + if (aTotalOptimalFlow < 0) { + log("Int overflow, report to issue tracker"); + aTotalOptimalFlow = 100; + } + } + + flowMultipliers[0] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mSteamMultiplier; + flowMultipliers[1] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mGasMultiplier; + flowMultipliers[2] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mPlasmaMultiplier; + baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); + optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); + if (optFlow <= 0 || baseEff <= 0) { + log("Running checkRecipeGeneric(bad-1)"); + stopMachine(); // in case the turbine got removed + return false; + } + } else { + counter++; + } + } + + + // How much the turbine should be producing with this flow + int newPower = fluidIntoPower(tFluids, optFlow, baseEff, flowMultipliers); + int difference = newPower - this.mEUt; // 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, GT_Utility.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.mEUt += change; // Apply the change + } else { + this.mEUt = newPower; + } + if (this.mEUt <= 0) { + this.mEUt = 0; + this.mEfficiency = 0; + log("Running checkRecipeGeneric(bad-2)"); + return false; + } 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) + startProcess(); + return true; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return false; + } + + @Override int fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { if (aFluids.size() >= 1) { aOptFlow *= 800; // CHANGED THINGS HERE, check recipe runs once per 20 ticks @@ -106,7 +228,6 @@ public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTur if (totalFlow <= 0) return 0; tEU = GT_Utility.safeInt((long) ((fuelValue / 20D) * (double) totalFlow)); - // GT_FML_LOGGER.info(totalFlow+" : "+fuelValue+" : "+aOptFlow+" : "+actualOptimalFlow+" : "+tEU); if (totalFlow == actualOptimalFlow) { tEU = GT_Utility.safeInt((long) (aBaseEff / 10000D * tEU)); |