diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2022-12-19 14:39:08 +0800 |
---|---|---|
committer | Glease <4586901+Glease@users.noreply.github.com> | 2022-12-20 22:24:48 +0800 |
commit | 6ca4c1ce4b0ecaefac92bee0599f3075f51b0329 (patch) | |
tree | eaac8b1fe6671b79fdc64ef36c5f61c0d3c2bb1f /src/main/java/net/glease/ggfab | |
parent | 198f834592e0ed103c722c77f0a7e01d0578d779 (diff) | |
download | GT5-Unofficial-6ca4c1ce4b0ecaefac92bee0599f3075f51b0329.tar.gz GT5-Unofficial-6ca4c1ce4b0ecaefac92bee0599f3075f51b0329.tar.bz2 GT5-Unofficial-6ca4c1ce4b0ecaefac92bee0599f3075f51b0329.zip |
add LaSEr overclock
Diffstat (limited to 'src/main/java/net/glease/ggfab')
-rw-r--r-- | src/main/java/net/glease/ggfab/mte/MTE_AdvAssLine.java | 78 | ||||
-rw-r--r-- | src/main/java/net/glease/ggfab/util/GGUtils.java (renamed from src/main/java/net/glease/ggfab/GGUtils.java) | 2 | ||||
-rw-r--r-- | src/main/java/net/glease/ggfab/util/OverclockHelper.java | 71 |
3 files changed, 108 insertions, 43 deletions
diff --git a/src/main/java/net/glease/ggfab/mte/MTE_AdvAssLine.java b/src/main/java/net/glease/ggfab/mte/MTE_AdvAssLine.java index bd533b29c8..58aacf178c 100644 --- a/src/main/java/net/glease/ggfab/mte/MTE_AdvAssLine.java +++ b/src/main/java/net/glease/ggfab/mte/MTE_AdvAssLine.java @@ -1,6 +1,5 @@ package net.glease.ggfab.mte; -import com.google.common.collect.Collections2; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; @@ -18,6 +17,7 @@ import gregtech.api.util.*; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.glease.ggfab.GGConstants; +import net.glease.ggfab.util.OverclockHelper; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -49,7 +49,7 @@ Dev note: 1. This multi will be an assline but with greater throughput. it will take one input every 2. */ -public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE_AdvAssLine> implements ISurvivalConstructable { +public class MTE_AdvAssLine extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<MTE_AdvAssLine> implements ISurvivalConstructable { private static final String STRUCTURE_PIECE_FIRST = "first"; private static final String STRUCTURE_PIECE_LATER = "later"; private static final String STRUCTURE_PIECE_LAST = "last"; @@ -123,12 +123,12 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE private final Slice[] slices = IntStream.range(0, 16).mapToObj(Slice::new).toArray(Slice[]::new); private boolean processing; private long inputVoltage; + // surely no one is using more EUt than this, no? + private long inputEUt; private long baseEUt; private boolean stuck; private final ArrayList<GT_MetaTileEntity_Hatch_DataAccess> mDataAccessHatches = new ArrayList<>(); - private final Collection<GT_MetaTileEntity_Hatch> allEnergyHatchesView = Collections2.filter(new ConcatList<>(mExoticEnergyHatches, mEnergyHatches), GT_MetaTileEntity_MultiBlockBase::isValidMetaTileEntity); - public MTE_AdvAssLine(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -200,7 +200,7 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE @SuppressWarnings("unchecked") List<EntityPlayerMP> l = MinecraftServer.getServer().getConfigurationManager().playerEntityList; for (EntityPlayerMP p : l) { if (p.getUniqueID().equals(ownerUuid)) { - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 9; i++) { p.addChatMessage(new ChatComponentTranslation("ggfab.info.advassline." + i)); } } @@ -365,12 +365,9 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { if (checkMachine()) { inputVoltage = Integer.MAX_VALUE; - for (GT_MetaTileEntity_Hatch tHatch : mEnergyHatches) { - inputVoltage = Math.min(inputVoltage, tHatch.maxEUInput()); - } - for (GT_MetaTileEntity_Hatch tHatch : mExoticEnergyHatches) { - inputVoltage = Math.min(inputVoltage, tHatch.maxEUInput()); - } + inputEUt = 0; + mEnergyHatches.forEach(this::recordEnergySupplier); + mExoticEnergyHatches.forEach(this::recordEnergySupplier); return true; } else { inputVoltage = V[0]; @@ -378,9 +375,14 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE } } - @Override - public boolean drainEnergyInput(long aEU) { - return GT_ExoticEnergyInputHelper.drainEnergy(aEU, allEnergyHatchesView); + private void recordEnergySupplier(GT_MetaTileEntity_Hatch hatch) { + if (!isValidMetaTileEntity(hatch)) + return; + inputEUt += hatch.maxEUInput() * hatch.maxAmperesIn(); + inputVoltage = Math.min(inputVoltage, hatch.maxEUInput()); + if (inputEUt < 0) + // I'd prefer bullying colen than use bigint + inputEUt = Long.MAX_VALUE; } @Override @@ -578,9 +580,20 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE recipe = findRecipe(stack); if (recipe != null) { setCurrentRecipe(stack, recipe); + // first overclock normally calculateOverclockedNessMulti(currentRecipe.mEUt, Math.max(recipe.mDuration / recipe.mInputs.length, 1), 1, inputVoltage); - // correct the recipe duration - mMaxProgresstime *= recipe.mInputs.length; + // then laser overclock if needed + if (!mExoticEnergyHatches.isEmpty()) { + OverclockHelper.OverclockOutput laserOverclock = OverclockHelper.laserOverclock(mEUt, mMaxProgresstime, inputEUt / recipe.mInputs.length, 0.3f); + if (laserOverclock == null) { + if (GT_Values.D1) { + GT_FML_LOGGER.info("Recipe too OP"); + } + continue; + } + lEUt = laserOverclock.getEUt(); + mMaxProgresstime = laserOverclock.getDuration(); + } // In case recipe is too OP for that machine if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { if (GT_Values.D1) { @@ -588,6 +601,8 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE } continue; } + // correct the recipe duration + mMaxProgresstime *= recipe.mInputs.length; break; } } @@ -690,6 +705,11 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE tag.setInteger("mDuration", mMaxProgresstime / currentRecipe.mInputs.length); } + @Override + public String[] getInfoData() { + return super.getInfoData(); + } + private void drainAllFluids(GT_Recipe.GT_Recipe_AssemblyLine recipe) { for (int i = 0; i < recipe.mFluidInputs.length; i++) { depleteInput(recipe.mFluidInputs[i]); @@ -800,30 +820,4 @@ public class MTE_AdvAssLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<MTE return t.mDataAccessHatches.size(); } } - - private static class ConcatList<T> extends AbstractList<T> { - private final List<? extends T> la, lb; - - public ConcatList(List<? extends T> la, List<? extends T> lb) { - this.la = la; - this.lb = lb; - } - - @Override - public T get(int index) { - int lasize = la.size(); - return index < lasize ? la.get(index) : lb.get(index - lasize); - } - - @Override - public int size() { - return la.size() + lb.size(); - } - - @Override - public T remove(int index) { - int lasize = la.size(); - return index < lasize ? la.remove(index) : lb.remove(index - lasize); - } - } } diff --git a/src/main/java/net/glease/ggfab/GGUtils.java b/src/main/java/net/glease/ggfab/util/GGUtils.java index ea34952971..1f47c82885 100644 --- a/src/main/java/net/glease/ggfab/GGUtils.java +++ b/src/main/java/net/glease/ggfab/util/GGUtils.java @@ -1,4 +1,4 @@ -package net.glease.ggfab; +package net.glease.ggfab.util; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; diff --git a/src/main/java/net/glease/ggfab/util/OverclockHelper.java b/src/main/java/net/glease/ggfab/util/OverclockHelper.java new file mode 100644 index 0000000000..7d0699a298 --- /dev/null +++ b/src/main/java/net/glease/ggfab/util/OverclockHelper.java @@ -0,0 +1,71 @@ +package net.glease.ggfab.util; + +import gregtech.api.util.GT_Utility; + +public class OverclockHelper { + public static OverclockOutput normalOverclock(long recipeEUt, int duration, long inputVoltage, boolean perfectOC) { + if (recipeEUt > inputVoltage) return null; + int recipeTier = Math.max(1, GT_Utility.getTier(recipeEUt)); // ULV no overclock + int machineTier = GT_Utility.getTier(inputVoltage); + int shift = perfectOC ? 2 : 1; + while (recipeTier < machineTier && duration > 1) { + duration >>= shift; + recipeEUt <<= 2; + recipeTier++; + } + return new OverclockOutput(recipeEUt, duration); + } + + public static OverclockOutput laserOverclock(long recipeEUt, int duration, long inputEUt, float penaltyIncreaseFactor) { + if (recipeEUt > inputEUt) return null; + float currentPenalty = 4 + penaltyIncreaseFactor; + // 2/(n+k) overclock until energy hatch is crying + while (recipeEUt * currentPenalty < inputEUt && duration > 1) { + duration >>= 1; + recipeEUt *= currentPenalty; + currentPenalty += penaltyIncreaseFactor; + } + return new OverclockOutput(recipeEUt, duration); + } + + public static final class OverclockOutput { + private final long mEUt; + private final int mDuration; + + public OverclockOutput(long aEUt, int aDuration) { + this.mEUt = aEUt; + this.mDuration = aDuration; + } + + public long getEUt() { + return mEUt; + } + + public int getDuration() { + return mDuration; + } + + @Override + public String toString() { + return mEUt + "@" + mDuration + "ticks"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof OverclockOutput)) return false; + + OverclockOutput that = (OverclockOutput) o; + + if (mEUt != that.mEUt) return false; + return mDuration == that.mDuration; + } + + @Override + public int hashCode() { + int result = (int) (mEUt ^ (mEUt >>> 32)); + result = 31 * result + mDuration; + return result; + } + } +} |