diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-10-02 19:51:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-02 19:51:28 +0200 |
commit | 89eccf0728b9b2175c68036ead3408b359c2981c (patch) | |
tree | 2b25dc6b165ca8a64391a21806ca792051205957 /src/main/java/kubatech/api/helpers | |
parent | 697d8932b67b4c6fb5f698c4b72e004f518adc46 (diff) | |
download | GT5-Unofficial-89eccf0728b9b2175c68036ead3408b359c2981c.tar.gz GT5-Unofficial-89eccf0728b9b2175c68036ead3408b359c2981c.tar.bz2 GT5-Unofficial-89eccf0728b9b2175c68036ead3408b359c2981c.zip |
Allow Extreme Extermination Chamber to overclock past 1 tick (#25)
* Revert "Shift outputs when needed"
This reverts commit e476c41e8956a61de6e1d962c9bb40948db8c2b5.
* OC past 1 tick
* Fix
* ok
* Ye
* info
Diffstat (limited to 'src/main/java/kubatech/api/helpers')
-rw-r--r-- | src/main/java/kubatech/api/helpers/GTHelper.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/kubatech/api/helpers/GTHelper.java b/src/main/java/kubatech/api/helpers/GTHelper.java new file mode 100644 index 0000000000..bf2b28ff79 --- /dev/null +++ b/src/main/java/kubatech/api/helpers/GTHelper.java @@ -0,0 +1,53 @@ +package kubatech.api.helpers; + +import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity; + +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import java.util.ArrayList; +import java.util.Arrays; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GTHelper { + + private static final double ln4 = Math.log(4d); + + public static int calculateOverclockedNessMulti( + GT_MetaTileEntity_MultiBlockBase mte, long aEUt, int aDuration, boolean perfect) { + final long maxInputVoltage = getMaxInputEU(mte); + final int tiers = (int) (Math.log((double) maxInputVoltage / (double) aEUt) / ln4); + if (tiers <= 0) { + mte.mEUt = (int) aEUt; + mte.mMaxProgresstime = aDuration; + return 0; + } + mte.mEUt = (int) (aEUt << (tiers << 1)); + int dMulti = 1; + final int aDurationModifier = perfect ? 2 : 1; + for (int i = 0; i < tiers; i++) + if (aDuration > 1) aDuration >>= aDurationModifier; + else dMulti <<= aDurationModifier; + if (dMulti > 1) { + final ArrayList<ItemStack> stacks = new ArrayList<>(Arrays.asList(mte.mOutputItems)); + for (ItemStack mOutputItem : mte.mOutputItems) { + mOutputItem.stackSize *= dMulti; + int maxSize = mOutputItem.getMaxStackSize(); + while (mOutputItem.stackSize > maxSize) + stacks.add(mOutputItem.splitStack(Math.min(mOutputItem.stackSize - maxSize, maxSize))); + } + if (stacks.size() != mte.mOutputItems.length) mte.mOutputItems = stacks.toArray(new ItemStack[0]); + for (FluidStack mOutputFluid : mte.mOutputFluids) mOutputFluid.amount *= dMulti; + } + if (aDuration <= 0) aDuration = 1; + mte.mMaxProgresstime = aDuration; + return tiers; + } + + public static long getMaxInputEU(GT_MetaTileEntity_MultiBlockBase mte) { + long rEU = 0; + for (GT_MetaTileEntity_Hatch_Energy tHatch : mte.mEnergyHatches) + if (isValidMetaTileEntity(tHatch)) rEU += tHatch.maxEUInput() * tHatch.maxAmperesIn(); + return rEU; + } +} |