Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
added a safty mechanism to MegaMultis
Browse files Browse the repository at this point in the history
+they wont accept more recipes than they can power.
  • Loading branch information
bartimaeusnek committed Feb 24, 2019
1 parent 2f6d86a commit 8c3d299
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_ElectricBlastFurnace;
Expand All @@ -40,10 +41,7 @@
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.*;

import static gregtech.api.enums.GT_Values.V;

Expand Down Expand Up @@ -87,8 +85,11 @@ public boolean checkRecipe(ItemStack itemStack) {
GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sBlastRecipes.findRecipe(this.getBaseMetaTileEntity(), false, V[tTier], tFluids, tInputs);
boolean found_Recipe = false;
int processed = 0;

long nominalV = BW_Util.getnominalVoltage(this);

while (this.getStoredInputs().size() > 0 && processed < ConfigHandler.megaMachinesMax) {
if (tRecipe != null && this.mHeatingCapacity >= tRecipe.mSpecialValue && tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) {
if (tRecipe != null && this.mHeatingCapacity >= tRecipe.mSpecialValue && tRecipe.isRecipeInputEqual(true, tFluids, tInputs) && (tRecipe.mEUt*processed) < nominalV ) {
found_Recipe = true;
for (int i = 0; i < tRecipe.mOutputs.length; i++) {
outputItems.add(tRecipe.getOutput(i));
Expand All @@ -115,7 +116,7 @@ public boolean checkRecipe(ItemStack itemStack) {
}
overclockCount = calculateOverclockednessEBF((int) (actualEUT / (divider * 2)), tRecipe.mDuration * (divider * 2), tVoltage);
} else
overclockCount = calculateOverclockednessEBF(tRecipe.mEUt * 64, tRecipe.mDuration, tVoltage);
overclockCount = calculateOverclockednessEBF(actualEUT, tRecipe.mDuration, tVoltage);
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return false;
Expand Down Expand Up @@ -148,7 +149,7 @@ public boolean checkRecipe(ItemStack itemStack) {
* @param aEUt - recipe EUt
* @param aDuration - recipe Duration
*/
protected byte calculateOverclockednessEBF(int aEUt, int aDuration, long maxInputVoltage) {
protected byte calculateOverclockednessEBF(long aEUt, int aDuration, long maxInputVoltage) {
byte mTier = (byte) Math.max(0, GT_Utility.getTier(maxInputVoltage)), timesOverclocked = 0;
if (mTier == 0) {
//Long time calculation
Expand All @@ -158,7 +159,7 @@ protected byte calculateOverclockednessEBF(int aEUt, int aDuration, long maxInpu
mEUt = Integer.MAX_VALUE - 1;
mMaxProgresstime = Integer.MAX_VALUE - 1;
} else {
mEUt = aEUt >> 2;
mEUt = (int) (aEUt >> 2);
mMaxProgresstime = (int) xMaxProgresstime;
}
//return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public boolean checkRecipe(ItemStack itemStack) {
GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sVacuumRecipes.findRecipe(this.getBaseMetaTileEntity(), false, V[tTier], null, tInputs);
boolean found_Recipe = false;
int processed = 0;
long nominalV = BW_Util.getnominalVoltage(this);
while (this.getStoredInputs().size() > 0 && processed < ConfigHandler.megaMachinesMax) {
if (tRecipe != null && tRecipe.isRecipeInputEqual(true, null, tInputs)) {
if (tRecipe != null && tRecipe.isRecipeInputEqual(true, null, tInputs) && (tRecipe.mEUt*processed) < nominalV ) {
found_Recipe = true;
for (int i = 0; i < tRecipe.mOutputs.length; i++) {
outputItems.add(tRecipe.getOutput(i));
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/github/bartimaeusnek/bartworks/util/BW_Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.github.bartimaeusnek.bartworks.API.BioVatLogicAdder;
import gregtech.api.enums.Materials;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
Expand Down Expand Up @@ -232,6 +233,22 @@ public static void calculateOverclockedNessMulti(@Nonnegative int aEUt, @Nonnega
}
}

public static long getnominalVoltage(GT_MetaTileEntity_MultiBlockBase base){
long rVoltage = 0L;
long rAmperage = 0L;
Iterator var3 = base.mEnergyHatches.iterator();

while(var3.hasNext()) {
GT_MetaTileEntity_Hatch_Energy tHatch = (GT_MetaTileEntity_Hatch_Energy)var3.next();
if (base.isValidMetaTileEntity(tHatch)) {
rVoltage += tHatch.getBaseMetaTileEntity().getInputVoltage();
rAmperage += tHatch.getBaseMetaTileEntity().getInputAmperage();
}
}

return rVoltage * rAmperage;
}

public static EnumRarity getRarityFromByte(byte b) {
switch (b) {
case 1:
Expand Down

0 comments on commit 8c3d299

Please sign in to comment.