diff options
author | Maxim <maxim235@gmx.de> | 2023-02-16 10:14:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-16 10:14:49 +0100 |
commit | 3b834d6cebae287cd9bbeddd4f157338da6e1ea5 (patch) | |
tree | 84b429a27e1adf0674569160e40e4c916a1d93c3 | |
parent | e1ba22d7de9388dffb0ea7d99add79b95f94aa6a (diff) | |
download | GT5-Unofficial-3b834d6cebae287cd9bbeddd4f157338da6e1ea5.tar.gz GT5-Unofficial-3b834d6cebae287cd9bbeddd4f157338da6e1ea5.tar.bz2 GT5-Unofficial-3b834d6cebae287cd9bbeddd4f157338da6e1ea5.zip |
Fusion NEI support (#1742)
* Added optional special value to Power and getter for power into IMTE
* Added FusionPower to properly display available fusion recipes and OC
* spotlessApply (#1743)
Co-authored-by: GitHub GTNH Actions <>
* Moved compare flag to recipe map
* Missed a new constructor
* Added user request
* Addressed reviews
* Typo
* Update src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java
Co-authored-by: miozune <miozune@gmail.com>
* Removed wrong bracket from git online commit
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: miozune <miozune@gmail.com>
13 files changed, 157 insertions, 17 deletions
diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java index 66c85be547..849b82565e 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java @@ -33,6 +33,7 @@ import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Util; +import gregtech.common.power.Power; /** * Warning, this Interface has just been made to be able to add multiple kinds of MetaTileEntities (Cables, Pipes, @@ -354,6 +355,13 @@ public interface IMetaTileEntity extends ISidedInventory, IFluidTank, IFluidHand String getSpecialVoltageToolTip(); /** + * @return Power object used for displaying in NEI + */ + default Power getPower() { + return null; + } + + /** * Icon of the Texture. If this returns null then it falls back to getTextureIndex. * * @param aSide is the Side of the Block 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 501e78ccec..62d6868286 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 @@ -751,7 +751,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B /** * Calcualtes overclocked ness using long integers - * + * * @param aEUt - recipe EUt * @param aDuration - recipe Duration */ @@ -1238,6 +1238,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B } } + @Override public Power getPower() { return mPower; } diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 524976adc9..824d97a382 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -1636,7 +1636,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { " EU", true, true).setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) - .setUsualFluidInputCount(2).setNEISpecialInfoFormatter(FusionSpecialValueFormatter.INSTANCE); + .useComparatorForNEI(true).setUsualFluidInputCount(2) + .setNEISpecialInfoFormatter(FusionSpecialValueFormatter.INSTANCE); public static final GT_Recipe_Map sComplexFusionRecipes = new GT_Recipe_Map_ComplexFusion( new HashSet<>(50), "gt.recipe.complexfusionreactor", @@ -2617,6 +2618,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> { private INEISpecialInfoFormatter neiSpecialInfoFormatter; /** + * Flag if a comparator should be used to search the recipe in NEI (which is defined in {@link Power}). Else + * only the voltage will be used to find recipes + */ + public boolean useComparatorForNEI; + + /** * Initialises a new type of Recipe Handler. * * @param aRecipeList a List you specify as Recipe List. Usually just an ArrayList with a @@ -2700,6 +2707,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return this; } + public GT_Recipe_Map useComparatorForNEI(boolean use) { + this.useComparatorForNEI = use; + return this; + } + public GT_Recipe_Map useModularUI(boolean use) { this.useModularUI = use; return this; diff --git a/src/main/java/gregtech/common/power/BasicMachineEUPower.java b/src/main/java/gregtech/common/power/BasicMachineEUPower.java index 14f1d27a3f..6fec7e7954 100644 --- a/src/main/java/gregtech/common/power/BasicMachineEUPower.java +++ b/src/main/java/gregtech/common/power/BasicMachineEUPower.java @@ -11,6 +11,10 @@ public class BasicMachineEUPower extends EUPower { super(tier, amperage); } + public BasicMachineEUPower(byte tier, int amperage, int specialValue) { + super(tier, amperage, specialValue); + } + @Override public void computePowerUsageAndDuration(int euPerTick, int duration) { super.computePowerUsageAndDuration(euPerTick, duration); diff --git a/src/main/java/gregtech/common/power/EUPower.java b/src/main/java/gregtech/common/power/EUPower.java index 815ae0c190..a630c2d90d 100644 --- a/src/main/java/gregtech/common/power/EUPower.java +++ b/src/main/java/gregtech/common/power/EUPower.java @@ -13,6 +13,11 @@ public class EUPower extends Power { this.amperage = amperage; } + public EUPower(byte tier, int amperage, int specialValue) { + super(tier, specialValue); + this.amperage = amperage; + } + @Override // This generic EU Power class has no overclock defined and does no special calculations. public void computePowerUsageAndDuration(int euPerTick, int duration) { diff --git a/src/main/java/gregtech/common/power/FusionPower.java b/src/main/java/gregtech/common/power/FusionPower.java new file mode 100644 index 0000000000..c253d51be0 --- /dev/null +++ b/src/main/java/gregtech/common/power/FusionPower.java @@ -0,0 +1,52 @@ +package gregtech.common.power; + +import static gregtech.api.enums.GT_Values.V; + +import net.minecraft.util.EnumChatFormatting; + +import gregtech.api.enums.GT_Values; +import gregtech.nei.FusionSpecialValueFormatter; + +public class FusionPower extends BasicMachineEUPower { + + public FusionPower(byte tier, int startupPower) { + super(tier, 1, startupPower); + } + + @Override + public void computePowerUsageAndDuration(int euPerTick, int duration, int specialValue) { + originalVoltage = computeVoltageForEuRate(euPerTick); + recipeEuPerTick = euPerTick; + recipeDuration = duration; + // It's safe to assume fusion is above ULV. We put this as safety check here anyway + if (tier > 0) { + int maxPossibleOverclocks = FusionSpecialValueFormatter.getFusionTier(this.specialValue, V[tier - 1]) + - FusionSpecialValueFormatter.getFusionTier(specialValue, euPerTick); + // Isn't too low EUt check? + long tempEUt = Math.max(euPerTick, V[1]); + + recipeDuration = duration; + + while (tempEUt <= V[tier - 1] * (long) amperage && maxPossibleOverclocks-- > 0) { + tempEUt <<= 1; // this actually controls overclocking + recipeDuration >>= 1; // this is effect of overclocking + } + if (tempEUt > Integer.MAX_VALUE - 1) { + recipeEuPerTick = Integer.MAX_VALUE - 1; + recipeDuration = Integer.MAX_VALUE - 1; + } else { + recipeEuPerTick = (int) tempEUt; + if (recipeEuPerTick == 0) recipeEuPerTick = 1; + if (recipeDuration == 0) recipeDuration = 1; // set time to 1 tick + } + } + wasOverclocked = checkIfOverclocked(); + } + + @Override + public String getTierString() { + return GT_Values.TIER_COLORS[tier] + "MK " + + FusionSpecialValueFormatter.getFusionTier(specialValue, recipeEuPerTick) + + EnumChatFormatting.RESET; + } +} diff --git a/src/main/java/gregtech/common/power/Power.java b/src/main/java/gregtech/common/power/Power.java index 13d1cc37c1..0c80c43bf3 100644 --- a/src/main/java/gregtech/common/power/Power.java +++ b/src/main/java/gregtech/common/power/Power.java @@ -7,9 +7,15 @@ public abstract class Power { protected final byte tier; protected int recipeEuPerTick; protected int recipeDuration; + protected final int specialValue; public Power(byte tier) { + this(tier, 0); + } + + public Power(byte tier, int specialValue) { this.tier = tier; + this.specialValue = specialValue; } public byte getTier() { @@ -23,6 +29,10 @@ public abstract class Power { */ public abstract void computePowerUsageAndDuration(int euPerTick, int duration); + public void computePowerUsageAndDuration(int euPerTick, int duration, int specialValue) { + computePowerUsageAndDuration(euPerTick, duration); + } + public int getEuPerTick() { return recipeEuPerTick; } @@ -53,4 +63,11 @@ public abstract class Power { public abstract String getVoltageString(); public abstract String getAmperageString(); + + public int compareTo(byte tier, int specialValue) { + if (this.tier != tier) { + return this.tier - tier; + } + return this.specialValue - specialValue; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java index 1f2b4f8222..1e7e0f822e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java @@ -51,11 +51,15 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import gregtech.common.power.FusionPower; +import gregtech.common.power.Power; public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity_EnhancedMultiBlockBase<GT_MetaTileEntity_FusionComputer> implements ISurvivalConstructable, IAddUIWidgets { + protected FusionPower power; + public static final String STRUCTURE_PIECE_MAIN = "main"; private static final ClassValue<IStructureDefinition<GT_MetaTileEntity_FusionComputer>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GT_MetaTileEntity_FusionComputer>>() { @@ -130,6 +134,11 @@ public abstract class GT_MetaTileEntity_FusionComputer super(aName); } + @Override + public Power getPower() { + return power; + } + public abstract int tier(); @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java index f032a9b53e..2ff938d2f4 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer1.java @@ -11,6 +11,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.common.power.FusionPower; public class GT_MetaTileEntity_FusionComputer1 extends GT_MetaTileEntity_FusionComputer { @@ -20,10 +21,12 @@ public class GT_MetaTileEntity_FusionComputer1 extends GT_MetaTileEntity_FusionC public GT_MetaTileEntity_FusionComputer1(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional, 6); + power = new FusionPower((byte) 6, 160_000_000); } public GT_MetaTileEntity_FusionComputer1(String aName) { super(aName); + power = new FusionPower((byte) 6, 160_000_000); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java index 6d95abd1cb..413245d43f 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer2.java @@ -11,6 +11,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.common.power.FusionPower; public class GT_MetaTileEntity_FusionComputer2 extends GT_MetaTileEntity_FusionComputer { @@ -19,11 +20,13 @@ public class GT_MetaTileEntity_FusionComputer2 extends GT_MetaTileEntity_FusionC TextureFactory.builder().addIcon(OVERLAY_FUSION2_GLOW).extFacing().glow().build()); public GT_MetaTileEntity_FusionComputer2(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional, 6); + super(aID, aName, aNameRegional, 7); + power = new FusionPower((byte) 7, 320_000_000); } public GT_MetaTileEntity_FusionComputer2(String aName) { super(aName); + power = new FusionPower((byte) 7, 320_000_000); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java index 210a427f32..ebc88c28f3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer3.java @@ -11,6 +11,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.common.power.FusionPower; public class GT_MetaTileEntity_FusionComputer3 extends GT_MetaTileEntity_FusionComputer { @@ -19,11 +20,13 @@ public class GT_MetaTileEntity_FusionComputer3 extends GT_MetaTileEntity_FusionC TextureFactory.builder().addIcon(OVERLAY_FUSION3_GLOW).extFacing().glow().build()); public GT_MetaTileEntity_FusionComputer3(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional, 6); + super(aID, aName, aNameRegional, 8); + power = new FusionPower((byte) 8, 640_000_000); } public GT_MetaTileEntity_FusionComputer3(String aName) { super(aName); + power = new FusionPower((byte) 8, 640_000_000); } @Override diff --git a/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java b/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java index 55cdc9b8be..0d5517b6f0 100644 --- a/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java +++ b/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java @@ -15,13 +15,18 @@ public class FusionSpecialValueFormatter implements INEISpecialInfoFormatter { public List<String> format(NEIRecipeInfo recipeInfo, Function<Integer, String> applyPrefixAndSuffix) { int euToStart = recipeInfo.recipe.mSpecialValue; int voltage = recipeInfo.recipe.mEUt; - int tier; + int tier = getFusionTier(euToStart, voltage); + + return Collections.singletonList(applyPrefixAndSuffix.apply(euToStart) + " (MK " + tier + ")"); + } - if (euToStart <= 10 * M * 16) { + public static int getFusionTier(int startupPower, long voltage) { + int tier; + if (startupPower <= 10 * M * 16) { tier = 1; - } else if (euToStart <= 20 * M * 16) { + } else if (startupPower <= 20 * M * 16) { tier = 2; - } else if (euToStart <= 40 * M * 16) { + } else if (startupPower <= 40 * M * 16) { tier = 3; } else { tier = 4; @@ -36,7 +41,6 @@ public class FusionSpecialValueFormatter implements INEISpecialInfoFormatter { } else { tier = 4; } - - return Collections.singletonList(applyPrefixAndSuffix.apply(euToStart) + " (MK " + tier + ")"); + return tier; } } diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index 4bcaeddc0d..ba64ba2e54 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -58,7 +58,6 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SteamVariant; import gregtech.api.gui.GT_GUIContainer; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; import gregtech.api.objects.ItemData; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; @@ -165,7 +164,11 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (outputId.equals(getOverlayIdentifier())) { if (results.length > 0 && results[0] instanceof Power) { mPower = (Power) results[0]; - loadTieredCraftingRecipesUpTo(mPower.getTier()); + if (mRecipeMap.useComparatorForNEI) { + loadTieredCraftingRecipesWithPower(mPower); + } else { + loadTieredCraftingRecipesUpTo(mPower.getTier()); + } } else { arecipes.addAll(getCache()); } @@ -205,6 +208,21 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } } + private void loadTieredCraftingRecipesWithPower(Power power) { + arecipes.addAll(getTieredRecipes(power)); + } + + private List<CachedDefaultRecipe> getTieredRecipes(Power power) { + List<CachedDefaultRecipe> recipes = getCache(); + if (recipes.size() > 0) { + recipes = recipes.stream().filter( + recipe -> power.compareTo(GT_Utility.getTier(recipe.mRecipe.mEUt), recipe.mRecipe.mSpecialValue) + >= 0) + .collect(Collectors.toList()); + } + return recipes; + } + private void loadTieredCraftingRecipesUpTo(byte upperTier) { arecipes.addAll(getTieredRecipes(upperTier)); } @@ -242,12 +260,13 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { GT_NEI_DefaultHandler handler = (GT_NEI_DefaultHandler) newInstance(); if (RecipeCatalysts.containsCatalyst(handler, candidate)) { IMetaTileEntity gtTileEntity = GT_Item_Machines.getMetaTileEntity(candidate); - if (gtTileEntity instanceof GT_MetaTileEntity_BasicMachine) { - Power power = ((GT_MetaTileEntity_BasicMachine) gtTileEntity).getPower(); - handler.loadCraftingRecipes(getOverlayIdentifier(), power); + Power power; + if (gtTileEntity != null) { + power = gtTileEntity.getPower(); } else { - handler.loadCraftingRecipes(getOverlayIdentifier(), (Object) null); + power = null; } + handler.loadCraftingRecipes(getOverlayIdentifier(), power); return handler; } } @@ -386,7 +405,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (mPower == null) { mPower = mRecipeMap.getPowerFromRecipeMap(); } - mPower.computePowerUsageAndDuration(recipe.mEUt, recipe.mDuration); + mPower.computePowerUsageAndDuration(recipe.mEUt, recipe.mDuration, recipe.mSpecialValue); mRecipeMap.drawNEIDescription( new NEIRecipeInfo(recipe, mRecipeMap, cachedRecipe, mPower, getDescriptionYOffset())); |