diff options
author | miozune <miozune@gmail.com> | 2023-12-04 05:34:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-03 21:34:27 +0100 |
commit | f74c7cc297d1d19d38a19683cd277ad9ce605d3a (patch) | |
tree | b2a5d66ec5a959099240fb1db239ffc0f9531839 /src/main/java/gregtech/api/objects | |
parent | b08cde7de4ec93cba05fb070991ad1dffb800ce1 (diff) | |
download | GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.tar.gz GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.tar.bz2 GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.zip |
Refactor RecipeMap (#2345)
* Remove deprecated and unused things
* Move recipemap subclasses
* Move GT_Recipe_Map to outside and rename to RecipeMap
* Move recipemap instances to separated class & remove prepending s
* Remove useless GT_Recipe constructors
* Always use ModularUI
* Rename IGT_RecipeMap -> IRecipeMap
* Add RecipeMapBuilder
* Remove more deprecated and unused things
* Fix RecipeMap type parameters
* Use multimap for recipe index
* Fix bending recipe error in dev env
* Remove mUniqueIdentifier
* Update AE2FC
* Less edgy texture for NEI recipe background
* Add replicator fluid output slot for NEI and machine GUI
* Fix fluid fuels not having fuel value in large boilers
* Remove GT_RectHandler and NEI_TransferRectHost
* Remove RecipeMapHandler
* Move NEI energy description from RecipeMapFrontend to Power
* Refactor the way to filter fusion recipes
* Check restriction for some properties
* Remove showVoltageAmperage
* Make Power accept GT_Recipe
* Fix NPE
* Move NEI duration description to Power from Frontend
* Directly implement IRecipeProcessingAwareHatch for GT_MetaTileEntity_Hatch_InputBus_ME
* Make Power integrated with GT_OverclockCalculator
* Rename Power -> OverclockDescriber
* Don't modify recipe find logic until postload finishes
* Reformat reserved MTE ids
* Fix check for too few inputs on recipe addition
* Move replicator logic to backend
* Stop un-hiding assline recipes
* Allow setting custom recipe comparator & implement for fusion
* Update AE2FC
* Rename getRecipeList and getRecipes -> getRecipeMap
* Automatically register recipe catalysts
* Cleanup the way to detect recipe collision
* Make use of BasicUIProperties for basic machines
* Make use of BasicUIProperties for UIHelper
* Rename specialHandler -> recipeTransformer
* Add way to automatically register handler info
* Add recipe category
* Add some APIs for addons
* Rename blastRecipes ->
blastFurnaceRecipes
* Remove GT_MetaTileEntity_BasicMachine_GT_Recipe#mSharedTank and #mRequiresFluidForFiltering
* Don't require setting duration and EU/t for fuel recipes
* Don't require setting EU/t for primitive blast furnace recipes
* Revert change to addMultiblockChemicalRecipe
* Fix large boiler general desc recipe not being added
* Hide duration and EU/t from large boiler
* Cleanup recipe stacktrace draw
* Extend metadata usage of recipe builder to recipe itself
* Implement metadata handling & NEI comparator for PCB factory
* Some rename around NEIRecipeInfo
* Some toString implementations
* Add more APIs for addons & some rename
* Infer handler icon from recipe catalyst if one is not set
* Also shrink recipe title when OC is not used
* Remove rare earth centrifuge recipe
* Use metadata for replicator backend
* Adjust geothermal generator output slot
* Allow having multiple transferrects
* Store recipemap reference in backend
* Rename vacuumRecipes -> vacuumFreezerRecipes
* Add config to tweak visibility of recipe categories
* Remove mHideRecyclingRecipes in favor of recipe category config
* Fix typo fluidSolidfierRecipes -> fluidSolidifierRecipes
* Refactor findRecipe and ProcessingLogic to use Stream
* Fix BBF handler icon & remove bronze blast furnace
* Add fluent API for findRecipe
* Add way to stop adding progressbar
* Change arg order for special texture
* Avoid overwriting interesting failure with NO_RECIPE
* Some changes for FuelBackend
* Set space project icon
* Remove localization from TT
* Remove CNC recipe adder
* Move recipe extractor from AE2FC
* Minor internal change for ProcessingLogic#applyRecipe
* More javadoc on #getAvailableRecipeMaps
* Better implementation of #ofSupplier
* Move replicator exponent config to GT_Proxy
* Remove RC & IC2 macerator handling
* Rename StreamUtil -> GT_StreamUtil
* Refactor code around RecipeMetadataStorage
* Revise #compileRecipe javadoc
* Switch extreme diesel recipe loader to downstream recipe map
* Optimize #reMap
* Rename reload -> reloadNEICache
* Minor tweak for drawEnergyInfo
* a bit more doc
* Adjust recipe catalysts
* Add toString implementation for GT_Fluid for debug
* Minor revision for OilCrackerBackend
* Index replicator recipes by material
---------
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/objects')
5 files changed, 429 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/objects/overclockdescriber/EUNoOverclockDescriber.java b/src/main/java/gregtech/api/objects/overclockdescriber/EUNoOverclockDescriber.java new file mode 100644 index 0000000000..1e29e2d812 --- /dev/null +++ b/src/main/java/gregtech/api/objects/overclockdescriber/EUNoOverclockDescriber.java @@ -0,0 +1,110 @@ +package gregtech.api.objects.overclockdescriber; + +import static gregtech.api.util.GT_Utility.trans; + +import javax.annotation.ParametersAreNonnullByDefault; + +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.MethodsReturnNonnullByDefault; +import gregtech.nei.RecipeDisplayInfo; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class EUNoOverclockDescriber extends OverclockDescriber { + + /** + * Amperage of the recipemap. + */ + protected final int amperage; + + public EUNoOverclockDescriber(byte tier, int amperage) { + super(tier); + if (amperage < 1) { + throw new IllegalArgumentException("Amperage cannot be lower than 1"); + } + this.amperage = amperage; + } + + @Override + public GT_OverclockCalculator createCalculator(GT_OverclockCalculator template, GT_Recipe recipe) { + return GT_OverclockCalculator.ofNoOverclock(recipe); + } + + @Override + public String getTierString() { + return GT_Utility.getColoredTierNameFromTier(tier); + } + + @Override + public final void drawEnergyInfo(RecipeDisplayInfo recipeInfo) { + if (recipeInfo.calculator.getDuration() > 0 && recipeInfo.calculator.getConsumption() > 0) { + recipeInfo.drawText(trans("152", "Total: ") + getTotalPowerString(recipeInfo.calculator)); + } + drawEnergyInfoImpl(recipeInfo); + } + + /** + * Override this to draw custom info about the energy this object can handle on NEI recipe GUI, minus total + * power usage. + */ + protected void drawEnergyInfoImpl(RecipeDisplayInfo recipeInfo) { + if (recipeInfo.calculator.getConsumption() <= 0) { + return; + } + recipeInfo.drawText(trans("153", "Usage: ") + getEUtDisplay(recipeInfo.calculator)); + if (shouldShowAmperage(recipeInfo.calculator)) { + recipeInfo.drawText(trans("154", "Voltage: ") + getVoltageString(recipeInfo.calculator)); + recipeInfo.drawText(trans("155", "Amperage: ") + getAmperageString(recipeInfo.calculator)); + } + } + + protected String getTotalPowerString(GT_OverclockCalculator calculator) { + return GT_Utility.formatNumbers(calculator.getConsumption() * calculator.getDuration()) + " EU"; + } + + /** + * @return If amperage should be shown on NEI. + */ + protected boolean shouldShowAmperage(GT_OverclockCalculator calculator) { + return amperage != 1; + } + + /** + * @return Whole EU/t usage, without tier display. + */ + protected String getEUtWithoutTier(GT_OverclockCalculator calculator) { + return GT_Utility.formatNumbers(calculator.getConsumption()) + " EU/t"; + } + + /** + * @return Whole EU/t usage, with tier display. + */ + protected String getEUtWithTier(GT_OverclockCalculator calculator) { + return getEUtWithoutTier(calculator) + GT_Utility.getTierNameWithParentheses(calculator.getConsumption()); + } + + /** + * @return Whole EU/t usage. Also displays voltage tier if it should be shown. + */ + protected String getEUtDisplay(GT_OverclockCalculator calculator) { + return shouldShowAmperage(calculator) ? getEUtWithoutTier(calculator) : getEUtWithTier(calculator); + } + + /** + * @return EU/t usage, divided by amperage. With tier display. + */ + protected String getVoltageString(GT_OverclockCalculator calculator) { + long voltage = computeVoltageForEURate(calculator.getConsumption()); + return GT_Utility.formatNumbers(voltage) + " EU/t" + GT_Utility.getTierNameWithParentheses(voltage); + } + + protected String getAmperageString(GT_OverclockCalculator calculator) { + return GT_Utility.formatNumbers(amperage); + } + + protected long computeVoltageForEURate(long euPerTick) { + return euPerTick / amperage; + } +} diff --git a/src/main/java/gregtech/api/objects/overclockdescriber/EUOverclockDescriber.java b/src/main/java/gregtech/api/objects/overclockdescriber/EUOverclockDescriber.java new file mode 100644 index 0000000000..9d53711515 --- /dev/null +++ b/src/main/java/gregtech/api/objects/overclockdescriber/EUOverclockDescriber.java @@ -0,0 +1,80 @@ +package gregtech.api.objects.overclockdescriber; + +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.util.GT_Utility.trans; + +import javax.annotation.ParametersAreNonnullByDefault; + +import com.google.common.primitives.Ints; + +import gregtech.GT_Mod; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.MethodsReturnNonnullByDefault; +import gregtech.nei.RecipeDisplayInfo; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class EUOverclockDescriber extends EUNoOverclockDescriber { + + public EUOverclockDescriber(byte tier, int amperage) { + super(tier, amperage); + } + + @Override + public GT_OverclockCalculator createCalculator(GT_OverclockCalculator template, GT_Recipe recipe) { + return template.setEUt(Ints.saturatedCast(V[tier] * amperage)); + } + + @Override + protected void drawEnergyInfoImpl(RecipeDisplayInfo recipeInfo) { + if (!wasOverclocked(recipeInfo.calculator)) { + super.drawEnergyInfoImpl(recipeInfo); + return; + } + + recipeInfo.drawText(trans("153", "Usage: ") + getEUtDisplay(recipeInfo.calculator)); + if (shouldShowAmperage(recipeInfo.calculator)) { + recipeInfo.drawText(trans("154", "Voltage: ") + getVoltageString(recipeInfo.calculator)); + } + if (GT_Mod.gregtechproxy.mNEIOriginalVoltage) { + EUNoOverclockDescriber originalPower = new EUNoOverclockDescriber(tier, amperage); + GT_OverclockCalculator originalPowerCalculator = GT_OverclockCalculator.ofNoOverclock(recipeInfo.recipe) + .calculate(); + recipeInfo + .drawText(trans("275", "Original usage: ") + originalPower.getEUtDisplay(originalPowerCalculator)); + } + if (shouldShowAmperage(recipeInfo.calculator)) { + recipeInfo.drawText(trans("155", "Amperage: ") + getAmperageString(recipeInfo.calculator)); + } + } + + @Override + protected String getEUtWithoutTier(GT_OverclockCalculator calculator) { + return decorateWithOverclockLabel(super.getEUtWithoutTier(calculator), calculator); + } + + @Override + protected String getEUtWithTier(GT_OverclockCalculator calculator) { + return this.getEUtWithoutTier(calculator) + GT_Utility.getTierNameWithParentheses(calculator.getConsumption()); + } + + @Override + protected String getVoltageString(GT_OverclockCalculator calculator) { + long voltage = computeVoltageForEURate(calculator.getConsumption()); + return decorateWithOverclockLabel(GT_Utility.formatNumbers(voltage) + " EU/t", calculator) + + GT_Utility.getTierNameWithParentheses(voltage); + } + + protected String decorateWithOverclockLabel(String s, GT_OverclockCalculator calculator) { + if (wasOverclocked(calculator)) { + s += " (OC)"; + } + return s; + } + + protected boolean wasOverclocked(GT_OverclockCalculator calculator) { + return calculator.getPerformedOverclocks() > 0; + } +} diff --git a/src/main/java/gregtech/api/objects/overclockdescriber/FusionOverclockDescriber.java b/src/main/java/gregtech/api/objects/overclockdescriber/FusionOverclockDescriber.java new file mode 100644 index 0000000000..43ce1c8760 --- /dev/null +++ b/src/main/java/gregtech/api/objects/overclockdescriber/FusionOverclockDescriber.java @@ -0,0 +1,69 @@ +package gregtech.api.objects.overclockdescriber; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.util.EnumChatFormatting; + +import gregtech.api.enums.GT_Values; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.MethodsReturnNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class FusionOverclockDescriber extends EUOverclockDescriber { + + protected final long capableStartup; + + public FusionOverclockDescriber(byte energyTier, long capableStartup) { + super(energyTier, 1); + this.capableStartup = capableStartup; + } + + @Override + public GT_OverclockCalculator createCalculator(GT_OverclockCalculator template, GT_Recipe recipe) { + return super.createCalculator(template, recipe).limitOverclockCount(overclock(recipe.mSpecialValue)) + .setEUtIncreasePerOC(getEUtIncreasePerOC()) + .setDurationDecreasePerOC(getDurationDecreasePerOC()); + } + + protected int getEUtIncreasePerOC() { + return 1; + } + + protected int getDurationDecreasePerOC() { + return 1; + } + + @Override + public String getTierString() { + return GT_Values.TIER_COLORS[tier] + "MK " + getFusionTier() + EnumChatFormatting.RESET; + } + + @Override + public boolean canHandle(GT_Recipe recipe) { + byte tier = GT_Utility.getTier(recipe.mEUt); + if (this.tier < tier) { + return false; + } + return this.capableStartup >= recipe.mSpecialValue; + } + + protected int overclock(int startEnergy) { + return switch (getFusionTier()) { + case 1 -> 0; + case 2 -> (startEnergy <= 160000000) ? 1 : 0; + case 3 -> (startEnergy <= 160000000) ? 2 : ((startEnergy <= 320000000) ? 1 : 0); + case 4 -> (startEnergy <= 160000000) ? 3 + : (startEnergy <= 320000000) ? 2 : (startEnergy <= 640000000) ? 1 : 0; + case 5 -> (startEnergy <= 160000000) ? 4 + : (startEnergy <= 320000000) ? 3 : (startEnergy <= 640000000) ? 2 : (startEnergy <= 1280000000) ? 1 : 0; + default -> throw new IllegalStateException("Unexpected fusion tier: " + getFusionTier()); + }; + } + + protected int getFusionTier() { + return this.tier - 5; // Mk1 <-> LuV + } +} diff --git a/src/main/java/gregtech/api/objects/overclockdescriber/OverclockDescriber.java b/src/main/java/gregtech/api/objects/overclockdescriber/OverclockDescriber.java new file mode 100644 index 0000000000..0b253c95fa --- /dev/null +++ b/src/main/java/gregtech/api/objects/overclockdescriber/OverclockDescriber.java @@ -0,0 +1,106 @@ +package gregtech.api.objects.overclockdescriber; + +import static gregtech.api.util.GT_Utility.trans; + +import javax.annotation.ParametersAreNonnullByDefault; + +import gregtech.GT_Mod; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.MethodsReturnNonnullByDefault; +import gregtech.nei.RecipeDisplayInfo; + +/** + * Provides an overclock behavior that will run on machines with the ability to draw information about it on NEI. + * <p> + * Implement {@link gregtech.api.interfaces.tileentity.IOverclockDescriptionProvider} for corresponding machine to use + * derivative of this class when looking up NEI recipe catalyst. + */ +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public abstract class OverclockDescriber { + + /** + * Tier of the (maybe virtual) machine this object belongs to. + */ + protected final byte tier; + + public OverclockDescriber(byte tier) { + this.tier = tier; + } + + /** + * @return Tier of this object. Used to limit recipes shown on NEI, based on recipe EU/t. + */ + public final byte getTier() { + return tier; + } + + /** + * @return Tier display of this object, shown on NEI header in a form of {@code Machine Name (tier)} + */ + public abstract String getTierString(); + + /** + * Creates overclock calculator from given template. This template should be used instead of building from the + * ground to avoid issues coming from different caller using different templates, but it's not applicable when using + * {@link GT_OverclockCalculator#ofNoOverclock(GT_Recipe)}. + * + * @param template Calculator that can be used as template. Recipe EU/t and duration are already set. + * @param recipe Recipe to calculate. + */ + public abstract GT_OverclockCalculator createCalculator(GT_OverclockCalculator template, GT_Recipe recipe); + + /** + * Draws info about the energy this object can handle on NEI recipe GUI. + */ + public abstract void drawEnergyInfo(RecipeDisplayInfo recipeInfo); + + public void drawDurationInfo(RecipeDisplayInfo recipeInfo) { + if (getDurationTicks(recipeInfo.calculator) <= 0) return; + + String textToDraw = trans("158", "Time: "); + if (GT_Mod.gregtechproxy.mNEIRecipeSecondMode) { + textToDraw += getDurationStringSeconds(recipeInfo.calculator); + if (getDurationSeconds(recipeInfo.calculator) <= 1.0d) { + textToDraw += String.format(" (%s)", getDurationStringTicks(recipeInfo.calculator)); + } + } else { + textToDraw += getDurationStringTicks(recipeInfo.calculator); + } + recipeInfo.drawText(textToDraw); + } + + /** + * Used to limit the shown recipes when searching recipes with NEI recipe catalyst. Unless overridden, this method + * doesn't do anything special (except for a bit worse performance). + * <p> + * In order to make use of this method, {@link gregtech.api.recipe.RecipeMapBuilder#useCustomFilterForNEI} + * should be enabled for the recipemap. + * + * @return If this object can handle the supplied recipe + */ + public boolean canHandle(GT_Recipe recipe) { + byte tier = GT_Utility.getTier(recipe.mEUt); + return this.tier >= tier; + } + + private int getDurationTicks(GT_OverclockCalculator calculator) { + return calculator.getDuration(); + } + + private double getDurationSeconds(GT_OverclockCalculator calculator) { + return 0.05d * getDurationTicks(calculator); + } + + private String getDurationStringSeconds(GT_OverclockCalculator calculator) { + return GT_Utility.formatNumbers(getDurationSeconds(calculator)) + GT_Utility.trans("161", " secs"); + } + + private String getDurationStringTicks(GT_OverclockCalculator calculator) { + String ticksString = getDurationTicks(calculator) == 1 ? GT_Utility.trans("209.1", " tick") + : GT_Utility.trans("209", " ticks"); + return GT_Utility.formatNumbers(getDurationTicks(calculator)) + ticksString; + } +} diff --git a/src/main/java/gregtech/api/objects/overclockdescriber/SteamOverclockDescriber.java b/src/main/java/gregtech/api/objects/overclockdescriber/SteamOverclockDescriber.java new file mode 100644 index 0000000000..5da64d4028 --- /dev/null +++ b/src/main/java/gregtech/api/objects/overclockdescriber/SteamOverclockDescriber.java @@ -0,0 +1,64 @@ +package gregtech.api.objects.overclockdescriber; + +import static gregtech.api.util.GT_Utility.trans; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.util.StatCollector; + +import gregtech.api.enums.SteamVariant; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.MethodsReturnNonnullByDefault; +import gregtech.nei.RecipeDisplayInfo; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class SteamOverclockDescriber extends OverclockDescriber { + + private final SteamVariant steamVariant; + private final int euPerTickMultiplier; + private final int durationMultiplier; + + public SteamOverclockDescriber(SteamVariant steamVariant, int euPerTickMultiplier, int durationMultiplier) { + super((byte) 1); // recipe tier is always LV + this.steamVariant = steamVariant; + this.euPerTickMultiplier = euPerTickMultiplier; + this.durationMultiplier = durationMultiplier; + } + + @Override + public String getTierString() { + return StatCollector.translateToLocal("GT5U.steam_variant." + steamVariant.toString()); + } + + @Override + public GT_OverclockCalculator createCalculator(GT_OverclockCalculator template, GT_Recipe recipe) { + return GT_OverclockCalculator.ofNoOverclock(recipe) + .setEUtDiscount(euPerTickMultiplier) + .setSpeedBoost(durationMultiplier); + } + + @Override + public void drawEnergyInfo(RecipeDisplayInfo recipeInfo) { + if (recipeInfo.calculator.getConsumption() <= 0) return; + + recipeInfo.drawText(trans("152", "Total: ") + getTotalPowerString(recipeInfo.calculator)); + recipeInfo.drawText(trans("153", "Usage: ") + getSteamUsageString(recipeInfo.calculator)); + } + + private String getTotalPowerString(GT_OverclockCalculator calculator) { + return GT_Utility.formatNumbers(convertEUToSteam(calculator.getConsumption() * calculator.getDuration())) + + " Steam"; + } + + private String getSteamUsageString(GT_OverclockCalculator calculator) { + return GT_Utility.formatNumbers(20 * convertEUToSteam(calculator.getConsumption())) + " L/s Steam"; + } + + private static long convertEUToSteam(long eu) { + // 2L normal steam == 1EU + return 2 * eu; + } +} |