diff options
Diffstat (limited to 'src/main/java/gregtech')
5 files changed, 111 insertions, 57 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 4c890a5673..be7f9e26dc 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -69,7 +69,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B public int mMainFacing = -1, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mOutputBlocked = 0; public FluidStack mOutputFluid; public String mGUIName, mNEIName; - private final Power mPower; + protected final Power mPower; @Deprecated diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 21a45b745c..c0a9a67e4c 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -815,7 +815,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public static final GT_Recipe_Map sExtruderRecipes = new GT_Recipe_Map(new HashSet<>(13000), "gt.recipe.extruder", "Extruder", null, RES_PATH_GUI + "basicmachines/Extruder", 2, 1, 2, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sHammerRecipes = new GT_Recipe_Map(new HashSet<>(3800), "gt.recipe.hammer", "Forge Hammer", null, RES_PATH_GUI + "basicmachines/Hammer", 1, 1, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sAmplifiers = new GT_Recipe_Map(new HashSet<>(2), "gt.recipe.uuamplifier", "Amplifabricator", null, RES_PATH_GUI + "basicmachines/Amplifabricator", 1, 0, 1, 0, 1, E, 1, E, true, true); - public static final GT_Recipe_Map sMassFabFakeRecipes = new GT_Recipe_Map(new HashSet<>(2), "gt.recipe.massfab", "Mass Fabrication", null, RES_PATH_GUI + "basicmachines/Massfabricator", 1, 0, 1, 0, 10, E, 1, E, true, true); + public static final GT_Recipe_Map sMassFabFakeRecipes = new GT_Recipe_Map(new HashSet<>(2), "gt.recipe.massfab", "Mass Fabrication", null, RES_PATH_GUI + "basicmachines/Massfabricator", 1, 0, 1, 0, 8, E, 1, E, true, true); public static final GT_Recipe_Map_Fuel sDieselFuels = new GT_Recipe_Map_Fuel(new HashSet<>(20), "gt.recipe.dieselgeneratorfuel", "Combustion Generator Fuels", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sExtremeDieselFuels = new GT_Recipe_Map_Fuel(new HashSet<>(20), "gt.recipe.extremedieselgeneratorfuel", "Extreme Diesel Engine Fuel", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); public static final GT_Recipe_Map_Fuel sTurbineFuels = new GT_Recipe_Map_Fuel(new HashSet<>(25), "gt.recipe.gasturbinefuel", "Gas Turbine Fuel", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, "Fuel Value: ", 1000, " EU", true, true); diff --git a/src/main/java/gregtech/common/power/BasicMachineEUPower.java b/src/main/java/gregtech/common/power/BasicMachineEUPower.java index 12691ac6d9..aad3a72718 100644 --- a/src/main/java/gregtech/common/power/BasicMachineEUPower.java +++ b/src/main/java/gregtech/common/power/BasicMachineEUPower.java @@ -1,12 +1,10 @@ package gregtech.common.power; -import gregtech.api.util.GT_Utility; - import static gregtech.api.enums.GT_Values.V; -public class BasicMachineEUPower extends EUPower{ - private static final String OC = " (OC)"; - private boolean wasOverclocked; +public class BasicMachineEUPower extends EUPower { + protected static final String OC = " (OC)"; + protected boolean wasOverclocked; public BasicMachineEUPower(byte tier, int amperage) { super(tier, amperage); @@ -59,14 +57,14 @@ public class BasicMachineEUPower extends EUPower{ return decorateWithOverclockLabel(super.getPowerUsageString()); } - private String decorateWithOverclockLabel(String s) { + protected String decorateWithOverclockLabel(String s) { if (wasOverclocked) { s += OC; } return s; } - private boolean checkIfOverclocked() { + protected boolean checkIfOverclocked() { return originalVoltage != computeVoltageForEuRate(recipeEuPerTick); } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java index 68dd9f2fee..d2b389f42f 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Massfabricator.java @@ -1,6 +1,7 @@ package gregtech.common.tileentities.machines.basic; import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.interfaces.ITexture; @@ -10,6 +11,9 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.common.power.BasicMachineEUPower; +import gregtech.common.power.Power; import net.minecraftforge.fluids.FluidStack; import static gregtech.api.enums.GT_Values.V; @@ -20,6 +24,7 @@ public class GT_MetaTileEntity_Massfabricator extends GT_MetaTileEntity_BasicMac public static int sUUASpeedBonus = 4; public static int sDurationMultiplier = 3215; public static boolean sRequiresUUA = false; + protected final long EUt; public GT_MetaTileEntity_Massfabricator(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 1, "UUM = Matter * Fabrication Squared", 1, 1, "Massfabricator.png", "", @@ -47,14 +52,17 @@ public class GT_MetaTileEntity_Massfabricator extends GT_MetaTileEntity_BasicMac TextureFactory.of( TextureFactory.of(OVERLAY_BOTTOM_MASSFAB), TextureFactory.builder().addIcon(OVERLAY_BOTTOM_MASSFAB_GLOW).glow().build())); + EUt = V[1] * (long) Math.pow(2, mTier + 2); } public GT_MetaTileEntity_Massfabricator(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + EUt = V[1] * (long) Math.pow(2, mTier + 2); } public GT_MetaTileEntity_Massfabricator(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { super(aName, aTier, 1, aDescription, aTextures, 1, 1, aGUIName, aNEIName); + EUt = V[1] * (long) Math.pow(2, mTier + 2); } @Override @@ -63,6 +71,11 @@ public class GT_MetaTileEntity_Massfabricator extends GT_MetaTileEntity_BasicMac } @Override + protected Power buildPower() { + return new MassfabricatorPower(mTier, mAmperage); + } + + @Override public void onConfigLoad(GT_Config aConfig) { super.onConfigLoad(aConfig); sDurationMultiplier = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUM_Duration_Multiplier", sDurationMultiplier); @@ -87,18 +100,17 @@ public class GT_MetaTileEntity_Massfabricator extends GT_MetaTileEntity_BasicMac FluidStack tFluid = getDrainableStack(); if ((tFluid == null) || (tFluid.amount < getCapacity())) { this.mOutputFluid = Materials.UUMatter.getFluid(1L); - calculateOverclockedNessMassFabricator(); + calculateOverclockedNess((int) EUt, containsUUA(getFillableStack()) ? sDurationMultiplier / sUUASpeedBonus : sDurationMultiplier); //In case recipe is too OP for that machine if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - if (((tFluid = getFillableStack()) != null) && (tFluid.amount >= sUUAperUUM) && (tFluid.isFluidEqual(Materials.UUAmplifier.getFluid(1L)))) { + if (containsUUA(tFluid = getFillableStack())) { tFluid.amount -= sUUAperUUM; - this.mMaxProgresstime /= sUUASpeedBonus; - return 2; + return FOUND_AND_SUCCESSFULLY_USED_RECIPE; } - return (sRequiresUUA) || (ItemList.Circuit_Integrated.isStackEqual(getInputAt(0), true, true)) ? 1 : 2; + return (sRequiresUUA) || (ItemList.Circuit_Integrated.isStackEqual(getInputAt(0), true, true)) ? FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS : FOUND_AND_SUCCESSFULLY_USED_RECIPE; } - return 0; + return DID_NOT_FIND_RECIPE; } @Override @@ -106,45 +118,6 @@ public class GT_MetaTileEntity_Massfabricator extends GT_MetaTileEntity_BasicMac return GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes; } - private void calculateOverclockedNessMassFabricator() { - if (mTier == 0) { - //Long time calculation - long xMaxProgresstime = ((long) sDurationMultiplier) << 1; - if (xMaxProgresstime > Integer.MAX_VALUE - 1) { - //make impossible if too long - mEUt = Integer.MAX_VALUE - 1; - mMaxProgresstime = Integer.MAX_VALUE - 1; - } else { - mEUt = (int) (V[1] << 2);//2^2=4 so shift <<2 - mMaxProgresstime = (int) xMaxProgresstime; - } - } else { - //Long EUt calculation - long xEUt = V[1] * (long) Math.pow(2, mTier + 2); - - long tempEUt = V[1]; - - mMaxProgresstime = sDurationMultiplier; - - while (tempEUt <= V[mTier - 1]) { - tempEUt <<= 2;//this actually controls overclocking - mMaxProgresstime >>= 1;//this is effect of overclocking - if (mMaxProgresstime == 0) - xEUt = (long) (xEUt / 1.1D);//U know, if the time is less than 1 tick make the machine use less power - } - if (xEUt > Integer.MAX_VALUE - 1) { - mEUt = Integer.MAX_VALUE - 1; - mMaxProgresstime = Integer.MAX_VALUE - 1; - } else { - mEUt = (int) xEUt; - if (mEUt == 0) - mEUt = 1; - if (mMaxProgresstime == 0) - mMaxProgresstime = 1;//set time to 1 tick - } - } - } - @Override public boolean isFluidInputAllowed(FluidStack aFluid) { return aFluid.isFluidEqual(Materials.UUAmplifier.getFluid(1L)); @@ -154,4 +127,87 @@ public class GT_MetaTileEntity_Massfabricator extends GT_MetaTileEntity_BasicMac public int getCapacity() { return Math.max(sUUAperUUM, 1000); } + + private boolean containsUUA(FluidStack aFluid) { + return aFluid != null + && aFluid.amount >= sUUAperUUM + && aFluid.isFluidEqual(Materials.UUAmplifier.getFluid(1L)); + } + + protected class MassfabricatorPower extends BasicMachineEUPower { + protected MassfabricatorPower(byte tier, int amperage) { + super(tier, amperage); + } + + @Override + public void computePowerUsageAndDuration(int euPerTick, int duration) { + originalVoltage = computeVoltageForEuRate(euPerTick); + + if (mTier == 0) { + //Long time calculation + long xMaxProgresstime = ((long) duration) << 1; + if (xMaxProgresstime > Integer.MAX_VALUE - 1) { + //make impossible if too long + recipeEuPerTick = Integer.MAX_VALUE - 1; + recipeDuration = Integer.MAX_VALUE - 1; + } else { + recipeEuPerTick = (int) (V[1] << 2);//2^2=4 so shift <<2 + recipeDuration = (int) xMaxProgresstime; + } + } else { + //Long EUt calculation + long xEUt = EUt; + + long tempEUt = V[1]; + + recipeDuration = duration; + + while (tempEUt <= V[mTier - 1]) { + tempEUt <<= 2;//this actually controls overclocking + recipeDuration >>= 1;//this is effect of overclocking + if (recipeDuration == 0) + xEUt = (long) (xEUt / 1.1D);//U know, if the time is less than 1 tick make the machine use less power + } + if (xEUt > Integer.MAX_VALUE - 1) { + recipeEuPerTick = Integer.MAX_VALUE - 1; + recipeDuration = Integer.MAX_VALUE - 1; + } else { + recipeEuPerTick = (int) xEUt; + if (recipeEuPerTick == 0) + recipeEuPerTick = 1; + if (recipeDuration == 0) + recipeDuration = 1;//set time to 1 tick + } + } + wasOverclocked = checkIfOverclocked(); + } + + @Override + public String getVoltageString() { + long voltage = V[1]; + String voltageDescription = GT_Utility.formatNumbers(voltage) + " EU"; + byte recipeTier = GT_Utility.getTier(voltage); + if (recipeTier >= 0 && recipeTier < 16) { + voltageDescription += " (" + GT_Values.VN[recipeTier] + ")"; + } + return voltageDescription; + } + + @Override + public String getAmperageString() { + long amperage = originalVoltage / V[1]; + int denominator = 1; + for (int i = 1; i < mTier; i++) { + amperage >>= 1; + if (amperage == 0) { + denominator <<= 1; + } + } + if (amperage > 0) { + return GT_Utility.formatNumbers(amperage); + } else { + return "1/" + denominator; + } + } + } } diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index b99d7d213b..4fcb2fea26 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -1065,7 +1065,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { return GT_Utility.trans(aKey, aEnglish); } - private static class SortedRecipeListCache { + private class SortedRecipeListCache { private int mCachedRecipesVersion = -1; @Nullable private SoftReference<List<CachedDefaultRecipe>> mCachedRecipes; @@ -1107,9 +1107,9 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { byte lowestTier = 0; while(iterator.hasNext()) { CachedDefaultRecipe recipe = iterator.next(); - byte recipeTier = GT_Utility.getTier(recipe.mRecipe.mEUt); + byte recipeTier = GT_Utility.getTier(recipe.mRecipe.mEUt / GT_NEI_DefaultHandler.this.mRecipeMap.mAmperage); if (recipeTier != previousTier) { - if ( maxIndex != -1) { + if (maxIndex != -1) { mTierIndexes[previousTier] = Range.between(minIndex, maxIndex); } else { lowestTier = recipeTier; |