diff options
author | miozune <miozune@gmail.com> | 2022-12-30 20:29:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-30 12:29:59 +0100 |
commit | 910437230b18d15a61a02cb31ce95f20a63dcade (patch) | |
tree | efde15d87baa33cc6eb563d3c027fb8a29f9cbb5 /src/main/java | |
parent | ac802e0abae29b3f7d16dc6134a384200bc791da (diff) | |
download | GT5-Unofficial-910437230b18d15a61a02cb31ce95f20a63dcade.tar.gz GT5-Unofficial-910437230b18d15a61a02cb31ce95f20a63dcade.tar.bz2 GT5-Unofficial-910437230b18d15a61a02cb31ce95f20a63dcade.zip |
Improve NEI customizability (#1583)
* Move descriptions to recipemap
* Move tooltips to recipemap
* Move overlays to recipemap
* Use shared code for generating grid positions
* 2 fluid inputs for freezer recipes
* Add deprecation javadoc
Diffstat (limited to 'src/main/java')
8 files changed, 550 insertions, 374 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 81937c42f8..9af6e45885 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -1,13 +1,16 @@ package gregtech.api.util; import static gregtech.api.enums.GT_Values.*; +import static net.minecraft.util.EnumChatFormatting.GRAY; import codechicken.nei.PositionedStack; +import com.gtnewhorizons.modularui.api.GlStateManager; import com.gtnewhorizons.modularui.api.ModularUITextures; import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.math.Alignment; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -22,6 +25,7 @@ import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.*; import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.GT_GUIColorOverride; import gregtech.api.gui.modularui.FallbackableSteamTexture; import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.gui.modularui.SteamTexture; @@ -33,7 +37,15 @@ import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; import gregtech.api.util.extensions.ArrayExt; import gregtech.common.gui.modularui.UIHelper; +import gregtech.common.power.EUPower; +import gregtech.common.power.Power; +import gregtech.common.power.UnspecifiedEUPower; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Replicator; +import gregtech.nei.FusionSpecialValueFormatter; +import gregtech.nei.GT_NEI_DefaultHandler; +import gregtech.nei.HeatingCoilSpecialValueFormatter; +import gregtech.nei.INEISpecialInfoFormatter; +import gregtech.nei.NEIRecipeInfo; import ic2.core.Ic2Items; import java.awt.*; import java.util.*; @@ -41,12 +53,15 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import javax.annotation.Nullable; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; @@ -739,6 +754,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return neiDesc; } + /** + * Sets description shown on NEI. + * <br>If you have a large number of recipes for the recipemap, + * this is not efficient memory wise, so use {@link GT_Recipe_Map#setNEISpecialInfoFormatter} instead. + */ protected void setNeiDesc(String... neiDesc) { this.neiDesc = neiDesc; } @@ -1664,33 +1684,25 @@ public class GT_Recipe implements Comparable<GT_Recipe> { true) .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_BOXED) .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); - public static final GT_Recipe_Map sFusionRecipes = new GT_Recipe_Map( - new HashSet<>(50), - "gt.recipe.fusionreactor", - "Fusion Reactor", - null, - RES_PATH_GUI + "basicmachines/FusionReactor", - 0, - 0, - 0, - 2, - 1, - "Start: ", - 1, - " EU", - true, - true) { - @Override - public List<Pos2d> getFluidInputPositions(int fluidInputCount) { - return UIHelper.getItemInputPositions(fluidInputCount); - } - - @Override - public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { - return UIHelper.getItemOutputPositions(fluidOutputCount); - } - }.setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) - .setUsualFluidInputCount(2); + public static final GT_Recipe_Map sFusionRecipes = new GT_Recipe_Map_FluidOnly( + new HashSet<>(50), + "gt.recipe.fusionreactor", + "Fusion Reactor", + null, + RES_PATH_GUI + "basicmachines/FusionReactor", + 0, + 0, + 0, + 2, + 1, + "Start: ", + 1, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(2) + .setNEISpecialInfoFormatter(FusionSpecialValueFormatter.INSTANCE); public static final GT_Recipe_Map sComplexFusionRecipes = new GT_Recipe_Map_ComplexFusion( new HashSet<>(50), "gt.recipe.complexfusionreactor", @@ -1711,7 +1723,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { .setUsualFluidInputCount(16) .setUsualFluidOutputCount(16) .setNEITransferRect(new Rectangle(79, 34, 18, 18)) - .setLogoPos(80, 61); + .setLogoPos(80, 61) + .setNEISpecialInfoFormatter(FusionSpecialValueFormatter.INSTANCE); public static final GT_Recipe_Map sCentrifugeRecipes = new GT_Recipe_Map( new HashSet<>(1200), "gt.recipe.centrifuge", @@ -1768,7 +1781,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { " K", false, true) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setNEISpecialInfoFormatter(HeatingCoilSpecialValueFormatter.INSTANCE); public static final GT_Recipe_Map sPlasmaForgeRecipes = new GT_Recipe_Map_LargeNEI( new HashSet<>(20), "gt.recipe.plasmaforge", @@ -1787,7 +1801,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { true) .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) .setUsualFluidInputCount(9) - .setUsualFluidOutputCount(9); + .setUsualFluidOutputCount(9) + .setNEISpecialInfoFormatter(HeatingCoilSpecialValueFormatter.INSTANCE); public static final GT_Recipe_Map sPrimitiveBlastRecipes = new GT_Recipe_Map( new HashSet<>(200), "gt.recipe.primitiveblastfurnace", @@ -1840,7 +1855,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { E, false, true) - .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(2); public static final GT_Recipe_Map sChemicalRecipes = new GT_Recipe_Map( new HashSet<>(1170), "gt.recipe.chemicalreactor", @@ -2479,7 +2495,22 @@ public class GT_Recipe implements Comparable<GT_Recipe> { .useModularUI(true) .setUsualFluidInputCount(3) .setUsualFluidOutputCount(0) - .setProgressBar(GT_UITextures.PROGRESSBAR_ASSEMBLE, ProgressBar.Direction.RIGHT); + .setProgressBar(GT_UITextures.PROGRESSBAR_ASSEMBLE, ProgressBar.Direction.RIGHT) + .setNEISpecialInfoFormatter((recipeInfo, applyPrefixAndSuffix) -> { + List<String> result = new ArrayList<>(); + int bitmap = recipeInfo.recipe.mSpecialValue; + if ((bitmap & 0b1) > 0) { + result.add(GT_Utility.trans("336", "PCB Factory Tier: ") + 1); + } else if ((bitmap & 0b10) > 0) { + result.add(GT_Utility.trans("336", "PCB Factory Tier: ") + 2); + } else if ((bitmap & 0b100) > 0) { + result.add(GT_Utility.trans("336", "PCB Factory Tier: ") + 3); + } + if ((bitmap & 0b1000) > 0) { + result.add(GT_Utility.trans("337", "Upgrade Required: ") + GT_Utility.trans("338", "Bio")); + } + return result; + }); public static final GT_Recipe_Map_IC2NuclearFake sIC2NuclearFakeRecipe = new GT_Recipe_Map_IC2NuclearFake(); @@ -2625,6 +2656,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public Size neiBackgroundSize = new Size(172, 82); + protected final GT_GUIColorOverride colorOverride; + private int neiTextColorOverride = -1; + + private INEISpecialInfoFormatter neiSpecialInfoFormatter; + /** * Initialises a new type of Recipe Handler. * @@ -2683,6 +2719,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { progressBarTexture = new FallbackableUITexture( UITexture.fullImage("gregtech", "gui/progressbar/" + mUnlocalizedName), GT_UITextures.PROGRESSBAR_ARROW); + colorOverride = GT_GUIColorOverride.get(ModularUITextures.VANILLA_BACKGROUND.location); if (sIndexedMappings.put(mUniqueIdentifier, this) != null) throw new IllegalArgumentException("Duplicate recipe map registered: " + mUniqueIdentifier); } @@ -2885,6 +2922,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return this; } + public GT_Recipe_Map setNEISpecialInfoFormatter(INEISpecialInfoFormatter neiSpecialInfoFormatter) { + this.neiSpecialInfoFormatter = neiSpecialInfoFormatter; + return this; + } + public GT_Recipe addRecipe( boolean aOptimize, ItemStack[] aInputs, @@ -3491,6 +3533,284 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return UIHelper.getFluidOutputPositions(fluidOutputCount); } + public void drawNEIDescription(NEIRecipeInfo recipeInfo) { + drawNEIEnergyInfo(recipeInfo); + drawNEIDurationInfo(recipeInfo); + drawNEISpecialInfo(recipeInfo); + drawNEIRecipeOwnerInfo(recipeInfo); + } + + protected void drawNEIEnergyInfo(NEIRecipeInfo recipeInfo) { + GT_Recipe recipe = recipeInfo.recipe; + Power power = recipeInfo.power; + if (power.getEuPerTick() > 0) { + drawNEIText(recipeInfo, GT_Utility.trans("152", "Total: ") + power.getTotalPowerString()); + + String amperage = power.getAmperageString(); + String powerUsage = power.getPowerUsageString(); + if (amperage == null || amperage.equals("unspecified") || powerUsage.contains("(OC)")) { + drawNEIText(recipeInfo, GT_Utility.trans("153", "Usage: ") + powerUsage); + if (GT_Mod.gregtechproxy.mNEIOriginalVoltage) { + Power originalPower = getPowerFromRecipeMap(); + if (!(originalPower instanceof UnspecifiedEUPower)) { + originalPower.computePowerUsageAndDuration(recipe.mEUt, recipe.mDuration); + drawNEIText( + recipeInfo, + GT_Utility.trans("275", "Original voltage: ") + originalPower.getVoltageString()); + } + } + if (amperage != null && !amperage.equals("unspecified") && !amperage.equals("1")) { + drawNEIText(recipeInfo, GT_Utility.trans("155", "Amperage: ") + amperage); + } + } else if (amperage.equals("1")) { + drawNEIText(recipeInfo, GT_Utility.trans("154", "Voltage: ") + power.getVoltageString()); + } else { + drawNEIText(recipeInfo, GT_Utility.trans("153", "Usage: ") + powerUsage); + drawNEIText(recipeInfo, GT_Utility.trans("154", "Voltage: ") + power.getVoltageString()); + drawNEIText(recipeInfo, GT_Utility.trans("155", "Amperage: ") + amperage); + } + } + } + + protected void drawNEIDurationInfo(NEIRecipeInfo recipeInfo) { + Power power = recipeInfo.power; + if (power.getDurationTicks() > 0) { + String textToDraw = GT_Utility.trans("158", "Time: "); + if (GT_Mod.gregtechproxy.mNEIRecipeSecondMode) { + textToDraw += power.getDurationStringSeconds(); + if (power.getDurationSeconds() <= 1.0d) { + textToDraw += String.format(" (%s)", power.getDurationStringTicks()); + } + } else { + textToDraw += power.getDurationStringTicks(); + } + drawNEIText(recipeInfo, textToDraw); + } + } + + protected void drawNEISpecialInfo(NEIRecipeInfo recipeInfo) { + String[] recipeDesc = recipeInfo.recipe.getNeiDesc(); + if (recipeDesc != null) { + for (String s : recipeDesc) { + drawOptionalNEIText(recipeInfo, s); + } + } else if (neiSpecialInfoFormatter != null) { + drawNEITextMultipleLines( + recipeInfo, neiSpecialInfoFormatter.format(recipeInfo, this::formatSpecialValue)); + } else { + drawOptionalNEIText(recipeInfo, getNEISpecialInfo(recipeInfo.recipe.mSpecialValue)); + } + } + + protected String getNEISpecialInfo(int specialValue) { + if (specialValue == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { + return GT_Utility.trans("159", "Needs Low Gravity"); + } else if (specialValue == -200 && GT_Mod.gregtechproxy.mEnableCleanroom) { + return GT_Utility.trans("160", "Needs Cleanroom"); + } else if (specialValue == -201) { + return GT_Utility.trans("206", "Scan for Assembly Line"); + } else if (specialValue == -300 && GT_Mod.gregtechproxy.mEnableCleanroom) { + return GT_Utility.trans("160.1", "Needs Cleanroom & LowGrav"); + } else if (specialValue == -400) { + return GT_Utility.trans("216", "Deprecated Recipe"); + } else if (hasSpecialValueFormat()) { + return formatSpecialValue(specialValue); + } + return null; + } + + private boolean hasSpecialValueFormat() { + return (GT_Utility.isStringValid(mNEISpecialValuePre)) || (GT_Utility.isStringValid(mNEISpecialValuePost)); + } + + protected String formatSpecialValue(int specialValue) { + return mNEISpecialValuePre + + GT_Utility.formatNumbers((long) specialValue * mNEISpecialValueMultiplier) + + mNEISpecialValuePost; + } + + protected void drawNEIRecipeOwnerInfo(NEIRecipeInfo recipeInfo) { + GT_Recipe recipe = recipeInfo.recipe; + if (GT_Mod.gregtechproxy.mNEIRecipeOwner) { + if (recipe.owners.size() > 1) { + drawNEIText( + recipeInfo, + EnumChatFormatting.ITALIC + + GT_Utility.trans("273", "Original Recipe by: ") + + recipe.owners.get(0).getName()); + for (int i = 1; i < recipe.owners.size(); i++) { + drawNEIText( + recipeInfo, + EnumChatFormatting.ITALIC + + GT_Utility.trans("274", "Modified by: ") + + recipe.owners.get(i).getName()); + } + } else if (recipe.owners.size() > 0) { + drawNEIText( + recipeInfo, + EnumChatFormatting.ITALIC + + GT_Utility.trans("272", "Recipe by: ") + + recipe.owners.get(0).getName()); + } + } + if (GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace + && recipe.stackTraces != null + && !recipe.stackTraces.isEmpty()) { + drawNEIText(recipeInfo, "stackTrace:"); + // todo: good way to show all stacktraces + for (StackTraceElement stackTrace : recipe.stackTraces.get(0)) { + drawNEIText(recipeInfo, stackTrace.toString()); + } + } + } + + protected void drawNEIText(NEIRecipeInfo recipeInfo, String text) { + drawNEIText(recipeInfo, text, 10); + } + + /** + * Draws text on NEI recipe. + * @param yShift y position to shift after this text + */ + @SuppressWarnings("SameParameterValue") + protected void drawNEIText(NEIRecipeInfo recipeInfo, String text, int yShift) { + drawNEIText(recipeInfo, text, 10, yShift); + } + + /** + * Draws text on NEI recipe. + * @param xStart x position to start drawing + * @param yShift y position to shift after this text + */ + @SuppressWarnings("SameParameterValue") + protected void drawNEIText(NEIRecipeInfo recipeInfo, String text, int xStart, int yShift) { + Minecraft.getMinecraft() + .fontRenderer + .drawString( + text, + xStart, + recipeInfo.yPos, + neiTextColorOverride != -1 ? neiTextColorOverride : 0x000000); + recipeInfo.yPos += yShift; + } + + protected void drawOptionalNEIText(NEIRecipeInfo recipeInfo, String text) { + if (GT_Utility.isStringValid(text) && !text.equals("unspecified")) { + drawNEIText(recipeInfo, text, 10); + } + } + + protected void drawNEITextMultipleLines(NEIRecipeInfo recipeInfo, List<String> texts) { + for (String text : texts) { + drawNEIText(recipeInfo, text, 10); + } + } + + public List<String> handleNEIItemTooltip( + ItemStack stack, List<String> currentTip, GT_NEI_DefaultHandler.CachedDefaultRecipe neiCachedRecipe) { + for (PositionedStack pStack : neiCachedRecipe.mInputs) { + if (stack == pStack.item) { + if (pStack instanceof GT_NEI_DefaultHandler.FixedPositionedStack) { + currentTip = handleNEIItemInputTooltip( + currentTip, (GT_NEI_DefaultHandler.FixedPositionedStack) pStack); + } + break; + } + } + for (PositionedStack pStack : neiCachedRecipe.mOutputs) { + if (stack == pStack.item) { + if (pStack instanceof GT_NEI_DefaultHandler.FixedPositionedStack) { + currentTip = handleNEIItemOutputTooltip( + currentTip, (GT_NEI_DefaultHandler.FixedPositionedStack) pStack); + } + break; + } + } + return currentTip; + } + + protected List<String> handleNEIItemInputTooltip( + List<String> currentTip, GT_NEI_DefaultHandler.FixedPositionedStack pStack) { + if (pStack.isNotConsumed()) { + currentTip.add(GRAY + GT_Utility.trans("151", "Does not get consumed in the process")); + } + return currentTip; + } + + protected List<String> handleNEIItemOutputTooltip( + List<String> currentTip, GT_NEI_DefaultHandler.FixedPositionedStack pStack) { + if (pStack.isChanceBased()) { + currentTip.add(GRAY + GT_Utility.trans("150", "Chance: ") + pStack.getChanceText()); + } + return currentTip; + } + + public void drawNEIOverlays(GT_NEI_DefaultHandler.CachedDefaultRecipe neiCachedRecipe) { + for (PositionedStack stack : neiCachedRecipe.mInputs) { + if (stack instanceof GT_NEI_DefaultHandler.FixedPositionedStack) { + drawNEIOverlayForInput((GT_NEI_DefaultHandler.FixedPositionedStack) stack); + } + } + for (PositionedStack stack : neiCachedRecipe.mOutputs) { + if (stack instanceof GT_NEI_DefaultHandler.FixedPositionedStack) { + drawNEIOverlayForOutput((GT_NEI_DefaultHandler.FixedPositionedStack) stack); + } + } + } + + protected void drawNEIOverlayForInput(GT_NEI_DefaultHandler.FixedPositionedStack stack) { + if (stack.isNotConsumed()) { + drawNEIOverlayText("NC", stack); + } + } + + protected void drawNEIOverlayForOutput(GT_NEI_DefaultHandler.FixedPositionedStack stack) { + if (stack.isChanceBased()) { + drawNEIOverlayText(stack.getChanceText(), stack); + } + } + + @SuppressWarnings("SameParameterValue") + protected void drawNEIOverlayText( + String text, PositionedStack stack, int color, float scale, boolean shadow, Alignment alignment) { + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + int width = fontRenderer.getStringWidth(text); + int x = (int) ((stack.relx + 8 + 8 * alignment.x) / scale) - (width / 2 * (alignment.x + 1)); + int y = (int) ((stack.rely + 8 + 8 * alignment.y) / scale) + - (fontRenderer.FONT_HEIGHT / 2 * (alignment.y + 1)) + - (alignment.y - 1) / 2; + + GlStateManager.pushMatrix(); + GlStateManager.scale(scale, scale, 1); + fontRenderer.drawString(text, x, y, color, shadow); + GlStateManager.popMatrix(); + } + + protected void drawNEIOverlayText(String text, PositionedStack stack) { + drawNEIOverlayText( + text, + stack, + colorOverride.getTextColorOrDefault("nei_overlay_yellow", 0xFDD835), + 0.5f, + false, + Alignment.TopLeft); + } + + public void updateNEITextColorOverride() { + neiTextColorOverride = colorOverride.getTextColorOrDefault("nei", -1); + } + + public Power getPowerFromRecipeMap() { + // By default, assume generic EU LV power with no overclocks + Power power; + if (mShowVoltageAmperageInNEI) { + power = new EUPower((byte) 1, mAmperage); + } else { + power = new UnspecifiedEUPower((byte) 1, mAmperage); + } + return power; + } + /** * Use {@link #getItemInputPositions} or {@link #getSpecialItemPosition} or {@link #getFluidInputPositions} instead */ @@ -3562,24 +3882,22 @@ public class GT_Recipe implements Comparable<GT_Recipe> { @Override public List<Pos2d> getItemInputPositions(int itemInputCount) { - return UIHelper.getItemGridPositions(itemInputCount, 16, yOrigin, xDirMaxCount, 3); + return UIHelper.getGridPositions(itemInputCount, 16, yOrigin, xDirMaxCount); } @Override public List<Pos2d> getItemOutputPositions(int itemOutputCount) { - return UIHelper.getItemGridPositions(itemOutputCount, 106, yOrigin, xDirMaxCount, 3); + return UIHelper.getGridPositions(itemOutputCount, 106, yOrigin, xDirMaxCount); } @Override public List<Pos2d> getFluidInputPositions(int fluidInputCount) { - return UIHelper.getItemGridPositions( - fluidInputCount, 16, yOrigin + getItemRowCount() * 18, xDirMaxCount, 3); + return UIHelper.getGridPositions(fluidInputCount, 16, yOrigin + getItemRowCount() * 18, xDirMaxCount); } @Override public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { - return UIHelper.getItemGridPositions( - fluidOutputCount, 106, yOrigin + getItemRowCount() * 18, xDirMaxCount, 3); + return UIHelper.getGridPositions(fluidOutputCount, 106, yOrigin + getItemRowCount() * 18, xDirMaxCount); } @Override @@ -5306,7 +5624,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { null, RES_PATH_GUI + "basicmachines/Default", 1, - 0, + 1, 1, 0, 1, @@ -5885,20 +6203,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> { @Override public List<Pos2d> getFluidInputPositions(int fluidInputCount) { - List<Pos2d> results = new ArrayList<>(); - for (int i = 0; i < fluidInputCount; i++) { - results.add(new Pos2d(7 + (i % 4) * 18, 9 + (i / 4) * 18)); - } - return results; + return UIHelper.getGridPositions(fluidInputCount, 7, 9, 4); } @Override public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { - List<Pos2d> results = new ArrayList<>(); - for (int i = 0; i < fluidOutputCount; i++) { - results.add(new Pos2d(97 + (i % 4) * 18, 9 + (i / 4) * 18)); - } - return results; + return UIHelper.getGridPositions(fluidOutputCount, 97, 9, 4); } } @@ -5941,11 +6251,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { @Override public List<Pos2d> getItemInputPositions(int itemInputCount) { - List<Pos2d> results = new ArrayList<>(); - for (int i = 0; i < itemInputCount; i++) { - results.add(new Pos2d(16 + (i % 4) * 18, 8 + (i / 4) * 18)); - } - return results; + return UIHelper.getGridPositions(itemInputCount, 16, 8, 4); } @Override @@ -5960,11 +6266,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { @Override public List<Pos2d> getFluidInputPositions(int fluidInputCount) { - List<Pos2d> results = new ArrayList<>(); - for (int i = 0; i < fluidInputCount; i++) { - results.add(new Pos2d(106, 8 + i * 18)); - } - return results; + return UIHelper.getGridPositions(fluidInputCount, 106, 8, 1); } @Override diff --git a/src/main/java/gregtech/common/gui/modularui/UIHelper.java b/src/main/java/gregtech/common/gui/modularui/UIHelper.java index 1639cf023f..42d704bbf4 100644 --- a/src/main/java/gregtech/common/gui/modularui/UIHelper.java +++ b/src/main/java/gregtech/common/gui/modularui/UIHelper.java @@ -93,18 +93,18 @@ public class UIHelper { case 0: return Collections.emptyList(); case 1: - return getItemGridPositions(itemInputCount, 52, 24, 1, 1); + return getGridPositions(itemInputCount, 52, 24, 1, 1); case 2: - return getItemGridPositions(itemInputCount, 34, 24, 2, 1); + return getGridPositions(itemInputCount, 34, 24, 2, 1); case 3: - return getItemGridPositions(itemInputCount, 16, 24, 3, 1); + return getGridPositions(itemInputCount, 16, 24, 3, 1); case 4: - return getItemGridPositions(itemInputCount, 34, 15, 2, 2); + return getGridPositions(itemInputCount, 34, 15, 2, 2); case 5: case 6: - return getItemGridPositions(itemInputCount, 16, 15, 3, 2); + return getGridPositions(itemInputCount, 16, 15, 3, 2); default: - return getItemGridPositions(itemInputCount, 16, 6, 3, 3); + return getGridPositions(itemInputCount, 16, 6, 3); } } @@ -116,18 +116,18 @@ public class UIHelper { case 0: return Collections.emptyList(); case 1: - return getItemGridPositions(itemOutputCount, 106, 24, 1, 1); + return getGridPositions(itemOutputCount, 106, 24, 1, 1); case 2: - return getItemGridPositions(itemOutputCount, 106, 24, 2, 1); + return getGridPositions(itemOutputCount, 106, 24, 2, 1); case 3: - return getItemGridPositions(itemOutputCount, 106, 24, 3, 1); + return getGridPositions(itemOutputCount, 106, 24, 3, 1); case 4: - return getItemGridPositions(itemOutputCount, 106, 15, 2, 2); + return getGridPositions(itemOutputCount, 106, 15, 2, 2); case 5: case 6: - return getItemGridPositions(itemOutputCount, 106, 15, 3, 2); + return getGridPositions(itemOutputCount, 106, 15, 3, 2); default: - return getItemGridPositions(itemOutputCount, 106, 6, 3, 3); + return getGridPositions(itemOutputCount, 106, 6, 3); } } @@ -164,30 +164,38 @@ public class UIHelper { return results; } - public static List<Pos2d> getItemGridPositions( - int itemCount, int xOrigin, int yOrigin, int xDirMaxCount, int yDirMaxCount) { + public static List<Pos2d> getGridPositions( + int totalCount, int xOrigin, int yOrigin, int xDirMaxCount, int yDirMaxCount) { // 18 pixels to get to a new grid for placing an item tile since they are 16x16 and have 1 pixel buffers // around them. - int distanceGrid = 18; - int xMax = xOrigin + xDirMaxCount * distanceGrid; + int distance = 18; List<Pos2d> results = new ArrayList<>(); - // Temp variables to keep track of current coordinates to place item at. - int xCoord = xOrigin; - int yCoord = yOrigin; - - for (int i = 0; i < itemCount; i++) { - results.add(new Pos2d(xCoord, yCoord)); - xCoord += distanceGrid; - if (xCoord == xMax) { - xCoord = xOrigin; - yCoord += distanceGrid; + int count = 0; + loop: + for (int j = 0; j < yDirMaxCount; j++) { + for (int i = 0; i < xDirMaxCount; i++) { + if (count >= totalCount) break loop; + results.add(new Pos2d(xOrigin + i * distance, yOrigin + j * distance)); + count++; } } - return results; } + public static List<Pos2d> getGridPositions(int totalCount, int xOrigin, int yOrigin, int xDirMaxCount) { + return getGridPositions(totalCount, xOrigin, yOrigin, xDirMaxCount, 100); + } + + /** + * @deprecated Renamed to {@link #getGridPositions} + */ + @Deprecated + public static List<Pos2d> getItemGridPositions( + int itemCount, int xOrigin, int yOrigin, int xDirMaxCount, int yDirMaxCount) { + return getGridPositions(itemCount, xOrigin, yOrigin, xDirMaxCount, yDirMaxCount); + } + private static IDrawable[] getBackgroundsForSlot( IDrawable base, GT_Recipe.GT_Recipe_Map recipeMap, diff --git a/src/main/java/gregtech/common/power/EUPower.java b/src/main/java/gregtech/common/power/EUPower.java index cc8c00f8f5..c074cc0b69 100644 --- a/src/main/java/gregtech/common/power/EUPower.java +++ b/src/main/java/gregtech/common/power/EUPower.java @@ -51,6 +51,6 @@ public class EUPower extends Power { } protected int computeVoltageForEuRate(int euPerTick) { - return euPerTick / amperage; + return amperage != 0 ? euPerTick / amperage : euPerTick; } } diff --git a/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java b/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java new file mode 100644 index 0000000000..2cbcb5bf1d --- /dev/null +++ b/src/main/java/gregtech/nei/FusionSpecialValueFormatter.java @@ -0,0 +1,41 @@ +package gregtech.nei; + +import gregtech.api.enums.GT_Values; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +public class FusionSpecialValueFormatter implements INEISpecialInfoFormatter { + + public static final FusionSpecialValueFormatter INSTANCE = new FusionSpecialValueFormatter(); + private static final int M = 1000000; + + @Override + public List<String> format(NEIRecipeInfo recipeInfo, Function<Integer, String> applyPrefixAndSuffix) { + int euToStart = recipeInfo.recipe.mSpecialValue; + int voltage = recipeInfo.recipe.mEUt; + int tier; + + if (euToStart <= 10 * M * 16) { + tier = 1; + } else if (euToStart <= 20 * M * 16) { + tier = 2; + } else if (euToStart <= 40 * M * 16) { + tier = 3; + } else { + tier = 4; + } + + if (voltage <= GT_Values.V[6]) { + // no-op + } else if (voltage <= GT_Values.V[7]) { + tier = Math.max(tier, 2); + } else if (voltage <= GT_Values.V[8]) { + tier = Math.max(tier, 3); + } else { + tier = 4; + } + + return Collections.singletonList(applyPrefixAndSuffix.apply(euToStart) + " (MK " + tier + ")"); + } +} diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index b255fa4ddc..f6a06979e2 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -1,7 +1,6 @@ package gregtech.nei; import static codechicken.nei.recipe.RecipeInfo.getGuiOffset; -import static net.minecraft.util.EnumChatFormatting.GRAY; import codechicken.lib.gui.GuiDraw; import codechicken.nei.NEIClientUtils; @@ -26,7 +25,6 @@ import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.widget.SlotWidget; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; -import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.ItemList; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.SteamVariant; @@ -41,9 +39,7 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.common.blocks.GT_Item_Machines; import gregtech.common.gui.modularui.UIHelper; -import gregtech.common.power.EUPower; import gregtech.common.power.Power; -import gregtech.common.power.UnspecifiedEUPower; import java.awt.*; import java.lang.ref.SoftReference; import java.text.DecimalFormat; @@ -63,19 +59,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.Range; import org.lwjgl.opengl.GL11; public class GT_NEI_DefaultHandler extends RecipeMapHandler { - @SuppressWarnings("unused") // Public constant - public static final int sOffsetX = 5; - @SuppressWarnings("unused") // Public constant + public static final int sOffsetX = 5; public static final int sOffsetY = 11; - private static final int M = 1000000; private static final ConcurrentMap<GT_Recipe.GT_Recipe_Map, SortedRecipeListCache> CACHE = new ConcurrentHashMap<>(); @@ -316,6 +308,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (mRecipeName == null) { mRecipeName = computeRecipeName(); updateOverrideTextColor(); + mRecipeMap.updateNEITextColorOverride(); } return mRecipeName; } @@ -371,30 +364,8 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { public List<String> handleItemTooltip( GuiRecipe<?> gui, ItemStack aStack, List<String> currentTip, int aRecipeIndex) { CachedRecipe tObject = this.arecipes.get(aRecipeIndex); - if ((tObject instanceof CachedDefaultRecipe)) { - CachedDefaultRecipe tRecipe = (CachedDefaultRecipe) tObject; - for (PositionedStack tStack : tRecipe.mOutputs) { - if (aStack == tStack.item) { - if ((!(tStack instanceof FixedPositionedStack)) - || (!((FixedPositionedStack) tStack).isChanceBased())) { - break; - } - currentTip.add(GRAY - + GT_Utility.trans("150", "Chance: ") - + ((FixedPositionedStack) tStack).getChanceText()); - break; - } - } - for (PositionedStack tStack : tRecipe.mInputs) { - if (aStack == tStack.item) { - if ((!(tStack instanceof FixedPositionedStack)) - || (!((FixedPositionedStack) tStack).isNotConsumed())) { - break; - } - currentTip.add(GRAY + GT_Utility.trans("151", "Does not get consumed in the process")); - break; - } - } + if (tObject instanceof CachedDefaultRecipe) { + currentTip = mRecipeMap.handleNEIItemTooltip(aStack, currentTip, (CachedDefaultRecipe) tObject); } if (mRecipeNameTooltip != null) { @@ -403,242 +374,31 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { return currentTip; } - private Power getPowerFromRecipeMap() { - // By default, assume generic EU LV power with no overclocks - Power power; - if (this.mRecipeMap.mShowVoltageAmperageInNEI) { - power = new EUPower((byte) 1, this.mRecipeMap.mAmperage); - } else { - power = new UnspecifiedEUPower((byte) 1, this.mRecipeMap.mAmperage); - } - return power; - } - @Override public void drawExtras(int aRecipeIndex) { CachedDefaultRecipe cachedRecipe = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)); - GT_Recipe recipe = cachedRecipe.mRecipe; - String[] recipeDesc = recipe.getNeiDesc(); - if (recipeDesc == null) { - drawDescription(recipe); - } else { - drawOverrideDescription(recipeDesc); - } - drawOverlays(cachedRecipe); + + drawDescription(cachedRecipe); + mRecipeMap.drawNEIOverlays(cachedRecipe); } - private void drawDescription(GT_Recipe recipe) { + private void drawDescription(CachedDefaultRecipe cachedRecipe) { + GT_Recipe recipe = cachedRecipe.mRecipe; if (mPower == null) { - mPower = getPowerFromRecipeMap(); + mPower = mRecipeMap.getPowerFromRecipeMap(); } mPower.computePowerUsageAndDuration(recipe.mEUt, recipe.mDuration); - int lineCounter = 0; - if (mPower.getEuPerTick() > 0) { - drawLine(lineCounter, GT_Utility.trans("152", "Total: ") + mPower.getTotalPowerString()); - lineCounter++; - - String amperage = mPower.getAmperageString(); - String powerUsage = mPower.getPowerUsageString(); - if (amperage == null || amperage.equals("unspecified") || powerUsage.contains("(OC)")) { - drawLine(lineCounter, GT_Utility.trans("153", "Usage: ") + powerUsage); - lineCounter++; - if (GT_Mod.gregtechproxy.mNEIOriginalVoltage) { - Power originalPower = getPowerFromRecipeMap(); - if (!(originalPower instanceof UnspecifiedEUPower)) { - originalPower.computePowerUsageAndDuration(recipe.mEUt, recipe.mDuration); - drawLine( - lineCounter, - GT_Utility.trans("275", "Original voltage: ") + originalPower.getVoltageString()); - lineCounter++; - } - } - if (amperage != null && !amperage.equals("unspecified") && !amperage.equals("1")) { - drawLine(lineCounter, GT_Utility.trans("155", "Amperage: ") + amperage); - lineCounter++; - } - } else if (amperage.equals("1")) { - drawLine(lineCounter, GT_Utility.trans("154", "Voltage: ") + mPower.getVoltageString()); - lineCounter++; - } else { - drawLine(lineCounter, GT_Utility.trans("153", "Usage: ") + powerUsage); - lineCounter++; - drawLine(lineCounter, GT_Utility.trans("154", "Voltage: ") + mPower.getVoltageString()); - lineCounter++; - drawLine(lineCounter, GT_Utility.trans("155", "Amperage: ") + amperage); - lineCounter++; - } - } - if (mPower.getDurationTicks() > 0) { - if (GT_Mod.gregtechproxy.mNEIRecipeSecondMode) { - if (mPower.getDurationSeconds() > 1.0d) { - drawLine(lineCounter, GT_Utility.trans("158", "Time: ") + mPower.getDurationStringSeconds()); - } else { - drawLine( - lineCounter, - GT_Utility.trans("158", "Time: ") - + mPower.getDurationStringSeconds() - + String.format(" (%s)", mPower.getDurationStringTicks())); - } - } else { - drawLine(lineCounter, GT_Utility.trans("158", "Time: ") + mPower.getDurationStringTicks()); - } - lineCounter++; - } - if (this.mRecipeMap.mNEIName.equals("gt.recipe.fusionreactor") - || this.mRecipeMap.mNEIName.equals("gt.recipe.complexfusionreactor")) { - if (drawOptionalLine( - lineCounter, - getSpecialInfo(recipe.mSpecialValue) + " " - + formatSpecialValueFusion(recipe.mSpecialValue, recipe.mEUt))) { - lineCounter++; - } - } else if (this.mRecipeMap.mNEIName.equals("gt.recipe.pcbfactory")) { - int bitmap = recipe.mSpecialValue; - if ((bitmap & 0b1) > 0) { - drawLine(lineCounter++, GT_Utility.trans("336", "PCB Factory Tier: ") + 1); - } else if ((bitmap & 0b10) > 0) { - drawLine(lineCounter++, GT_Utility.trans("336", "PCB Factory Tier: ") + 2); - } else if ((bitmap & 0b100) > 0) { - drawLine(lineCounter++, GT_Utility.trans("336", "PCB Factory Tier: ") + 3); - } - if ((bitmap & 0b1000) > 0) { - drawLine(lineCounter++, GT_Utility.trans("337", "Upgrade Required: ") + GT_Utility.trans("338", "Bio")); - } - } else if (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePre) - && this.mRecipeMap.mNEISpecialValuePre.toLowerCase().contains("heat capacity")) { - drawLine(lineCounter, getSpecialInfo(recipe.mSpecialValue)); - lineCounter++; - drawLine(lineCounter, " " + formatSpecialValueHeatCoil(recipe.mSpecialValue)); - lineCounter++; - } else if (drawOptionalLine(lineCounter, getSpecialInfo(recipe.mSpecialValue))) { - lineCounter++; - } - if (GT_Mod.gregtechproxy.mNEIRecipeOwner) { - if (recipe.owners.size() > 1) { - drawLine( - lineCounter, - EnumChatFormatting.ITALIC - + GT_Utility.trans("273", "Original Recipe by: ") - + recipe.owners.get(0).getName()); - lineCounter++; - for (int i = 1; i < recipe.owners.size(); i++) { - drawLine( - lineCounter, - EnumChatFormatting.ITALIC - + GT_Utility.trans("274", "Modified by: ") - + recipe.owners.get(i).getName()); - lineCounter++; - } - } else if (recipe.owners.size() > 0) { - drawLine( - lineCounter, - EnumChatFormatting.ITALIC - + GT_Utility.trans("272", "Recipe by: ") - + recipe.owners.get(0).getName()); - lineCounter++; - } - } - if (GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace - && recipe.stackTraces != null - && !recipe.stackTraces.isEmpty()) { - drawLine(lineCounter, "stackTrace:"); - lineCounter++; - // todo: good way to show all stacktraces - for (StackTraceElement stackTrace : recipe.stackTraces.get(0)) { - drawLine(lineCounter, stackTrace.toString()); - lineCounter++; - } - } - } - - private void drawOverrideDescription(String[] recipeDesc) { - for (int i = 0; i < recipeDesc.length; i++) { - if (recipeDesc[i] != null) { - drawLine(i, recipeDesc[i]); - } - } + mRecipeMap.drawNEIDescription( + new NEIRecipeInfo(recipe, mRecipeMap, cachedRecipe, mPower, getDescriptionYOffset())); } + @Deprecated protected String getSpecialInfo(int specialValue) { - String specialInfo = null; - if (specialValue == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { - specialInfo = GT_Utility.trans("159", "Needs Low Gravity"); - } else if (specialValue == -200 && GT_Mod.gregtechproxy.mEnableCleanroom) { - specialInfo = GT_Utility.trans("160", "Needs Cleanroom"); - } else if (specialValue == -201) { - specialInfo = GT_Utility.trans("206", "Scan for Assembly Line"); - } else if (specialValue == -300 && GT_Mod.gregtechproxy.mEnableCleanroom) { - specialInfo = GT_Utility.trans("160.1", "Needs Cleanroom & LowGrav"); - } else if (specialValue == -400) { - specialInfo = GT_Utility.trans("216", "Deprecated Recipe"); - } else if (hasSpecialValueFormat()) { - specialInfo = formatSpecialValue(specialValue); - } - return specialInfo; - } - - private boolean hasSpecialValueFormat() { - return (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePre)) - || (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePost)); - } - - protected String formatSpecialValue(int SpecialValue) { - return this.mRecipeMap.mNEISpecialValuePre - + GT_Utility.formatNumbers((long) SpecialValue * this.mRecipeMap.mNEISpecialValueMultiplier) - + this.mRecipeMap.mNEISpecialValuePost; - } - - private String formatSpecialValueFusion(int SpecialValue, int Voltage) { - int tier; - if (SpecialValue <= 10 * M * 16) { - tier = 1; - } else if (SpecialValue <= 20 * M * 16) { - tier = 2; - } else if (SpecialValue <= 40 * M * 16) { - tier = 3; - } else { - tier = 4; - } - if (Voltage <= GT_Values.V[6]) { - // no-op - } else if (Voltage <= GT_Values.V[7]) { - tier = Math.max(tier, 2); - } else if (Voltage <= GT_Values.V[8]) { - tier = Math.max(tier, 3); - } else { - tier = 4; - } - return "(MK " + tier + ")"; - } - - private String formatSpecialValueHeatCoil(int heat) { - for (HeatingCoilLevel heatLevel : HeatingCoilLevel.values()) { - if (heatLevel == HeatingCoilLevel.None || heatLevel == HeatingCoilLevel.ULV) continue; - if (heatLevel.getHeat() >= heat) { - return "(" + heatLevel.getName() + ")"; - } - } - return "(" + HeatingCoilLevel.MAX.getName() + "+)"; - } - - @SuppressWarnings("unused") // TODO: Consider removing - protected boolean drawOptionalLine(int lineNumber, String line, String prefix) { - if (!(line == null || "unspecified".equals(line))) { - drawLine(lineNumber, prefix + line); - return true; - } - return false; - } - - protected boolean drawOptionalLine(int lineNumber, String line) { - if (!(line == null || "unspecified".equals(line))) { - drawLine(lineNumber, line); - return true; - } - return false; + return ""; } + @Deprecated protected void drawLine(int lineNumber, String line) { drawText(10, getDescriptionYOffset() + lineNumber * 10, line, 0xFF000000); } @@ -647,38 +407,6 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { return mRecipeMap.neiBackgroundSize.height + mRecipeMap.neiBackgroundOffset.y + WINDOW_OFFSET.y + 3; } - protected void drawOverlays(CachedDefaultRecipe recipe) { - for (PositionedStack stack : recipe.mInputs) { - if (!(stack instanceof FixedPositionedStack)) continue; - drawOverlayForStack((FixedPositionedStack) stack); - } - for (PositionedStack stack : recipe.mOutputs) { - if (!(stack instanceof FixedPositionedStack)) continue; - drawOverlayForStack((FixedPositionedStack) stack); - } - } - - protected void drawOverlayForStack(FixedPositionedStack stack) { - if (stack.isChanceBased()) { - drawOverlayText(stack.getChanceText(), stack); - } else if (stack.isNotConsumed()) { - drawOverlayText("NC", stack); - } - } - - protected void drawOverlayText(String text, FixedPositionedStack stack) { - GlStateManager.pushMatrix(); - GlStateManager.scale(0.5, 0.5, 1); - Minecraft.getMinecraft() - .fontRenderer - .drawString( - text, - stack.relx * 2, - stack.rely * 2 + 1, - colorOverride.getTextColorOrDefault("nei_overlay", 0xFDD835)); - GlStateManager.popMatrix(); - } - protected void drawUI(ModularWindow window) { for (IDrawable background : window.getBackground()) { GlStateManager.pushMatrix(); diff --git a/src/main/java/gregtech/nei/HeatingCoilSpecialValueFormatter.java b/src/main/java/gregtech/nei/HeatingCoilSpecialValueFormatter.java new file mode 100644 index 0000000000..c5a22d570d --- /dev/null +++ b/src/main/java/gregtech/nei/HeatingCoilSpecialValueFormatter.java @@ -0,0 +1,29 @@ +package gregtech.nei; + +import gregtech.api.enums.HeatingCoilLevel; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + +public class HeatingCoilSpecialValueFormatter implements INEISpecialInfoFormatter { + + public static final HeatingCoilSpecialValueFormatter INSTANCE = new HeatingCoilSpecialValueFormatter(); + + @Override + public List<String> format(NEIRecipeInfo recipeInfo, Function<Integer, String> applyPrefixAndSuffix) { + int heat = recipeInfo.recipe.mSpecialValue; + + List<String> result = new ArrayList<>(); + result.add(applyPrefixAndSuffix.apply(heat)); + + for (HeatingCoilLevel heatLevel : HeatingCoilLevel.values()) { + if (heatLevel == HeatingCoilLevel.None || heatLevel == HeatingCoilLevel.ULV) continue; + if (heatLevel.getHeat() >= heat) { + result.add(" (" + heatLevel.getName() + ")"); + return result; + } + } + result.add(" (" + HeatingCoilLevel.MAX.getName() + "+)"); + return result; + } +} diff --git a/src/main/java/gregtech/nei/INEISpecialInfoFormatter.java b/src/main/java/gregtech/nei/INEISpecialInfoFormatter.java new file mode 100644 index 0000000000..8f15be7026 --- /dev/null +++ b/src/main/java/gregtech/nei/INEISpecialInfoFormatter.java @@ -0,0 +1,18 @@ +package gregtech.nei; + +import java.util.List; +import java.util.function.Function; + +/** + * Getter for description for {@link gregtech.api.util.GT_Recipe#mSpecialValue} etc. that will be drawn on NEI. + */ +@FunctionalInterface +public interface INEISpecialInfoFormatter { + + /** + * @param recipeInfo Recipe info to draw description. You can retrieve special value with {@code recipeInfo.recipe.mSpecialValue}. + * @param applyPrefixAndSuffix Function to apply {@link gregtech.api.util.GT_Recipe.GT_Recipe_Map#formatSpecialValue}. + * @return List of strings containing info for special value etc. + */ + List<String> format(NEIRecipeInfo recipeInfo, Function<Integer, String> applyPrefixAndSuffix); +} diff --git a/src/main/java/gregtech/nei/NEIRecipeInfo.java b/src/main/java/gregtech/nei/NEIRecipeInfo.java new file mode 100644 index 0000000000..e19ff6f2ba --- /dev/null +++ b/src/main/java/gregtech/nei/NEIRecipeInfo.java @@ -0,0 +1,50 @@ +package gregtech.nei; + +import gregtech.api.util.GT_Recipe; +import gregtech.common.power.Power; + +/** + * Holds info used for drawing descriptions on NEI. + */ +public class NEIRecipeInfo { + + /** + * Recipe to show description. + */ + public final GT_Recipe recipe; + + /** + * RecipeMap the recipe belongs to. + */ + public final GT_Recipe.GT_Recipe_Map recipeMap; + + /** + * Recipe object for NEI. + */ + public final GT_NEI_DefaultHandler.CachedDefaultRecipe neiCachedRecipe; + + /** + * When user looks up usage for machine, NEI will show all the recipes that the machine can process, + * taking tier of the machine into consideration. + * This object can be used to show info around overclocked EU/t and duration. + */ + public final Power power; + + /** + * Current Y position for drawing description. + */ + public int yPos; + + public NEIRecipeInfo( + GT_Recipe recipe, + GT_Recipe.GT_Recipe_Map recipeMap, + GT_NEI_DefaultHandler.CachedDefaultRecipe neiCachedRecipe, + Power power, + int descriptionYOffset) { + this.recipe = recipe; + this.recipeMap = recipeMap; + this.neiCachedRecipe = neiCachedRecipe; + this.power = power; + this.yPos = descriptionYOffset; + } +} |