From 273a5b3458dde88c2d3a5dcf1eec02de0c5054b5 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 27 Aug 2022 10:49:46 +0100 Subject: Fix spotless rebase (#1307) * Fix broken rebase * Undo Materials formatting, it generates too many lines * Dummy commit * Missed a structurelib update --- .../java/gregtech/nei/GT_NEI_AssLineHandler.java | 65 ++++- .../java/gregtech/nei/GT_NEI_DefaultHandler.java | 304 +++++++++++++-------- 2 files changed, 245 insertions(+), 124 deletions(-) (limited to 'src/main/java/gregtech/nei') diff --git a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java index 8026e8b4ec..e75b5e3ad0 100644 --- a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java @@ -30,6 +30,7 @@ import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; import org.lwjgl.opengl.GL11; @@ -44,6 +45,8 @@ public class GT_NEI_AssLineHandler extends RecipeMapHandler { */ public static int cycleTicksStatic = Math.abs((int) System.currentTimeMillis()); + private String mRecipeName; + static { GuiContainerManager.addInputHandler(new GT_RectHandler()); GuiContainerManager.addTooltipHandler(new GT_RectHandler()); @@ -195,7 +198,11 @@ public class GT_NEI_AssLineHandler extends RecipeMapHandler { @Override public String getRecipeName() { - return GT_LanguageManager.getTranslation(this.mRecipeMap.mUnlocalizedName); + if (mRecipeName == null) { + mRecipeName = GT_LanguageManager.getTranslation(this.mRecipeMap.mUnlocalizedName); + updateOverrideTextColor(); + } + return mRecipeName; } @Override @@ -240,9 +247,10 @@ public class GT_NEI_AssLineHandler extends RecipeMapHandler { @Override public void drawExtras(int aRecipeIndex) { - int tEUt = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mEUt; - int tDuration = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mDuration; - String[] recipeDesc = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.getNeiDesc(); + GT_Recipe recipe = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe; + int tEUt = recipe.mEUt; + int tDuration = recipe.mDuration; + String[] recipeDesc = recipe.getNeiDesc(); if (recipeDesc == null) { if (tEUt != 0) { drawText( @@ -259,7 +267,7 @@ public class GT_NEI_AssLineHandler extends RecipeMapHandler { 10, 93, trans("154", "Voltage: ") + GT_Utility.formatNumbers(voltage) + " EU", - 0xFFFF0000); + 0xFF000000); } else { drawText( 10, @@ -286,12 +294,16 @@ public class GT_NEI_AssLineHandler extends RecipeMapHandler { 0xFF000000); } int tSpecial = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mSpecialValue; + boolean specialDrew = false; if (tSpecial == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { drawText(10, 123, trans("159", "Needs Low Gravity"), 0xFF000000); + specialDrew = true; } else if (tSpecial == -200 && GT_Mod.gregtechproxy.mEnableCleanroom) { drawText(10, 123, trans("160", "Needs Cleanroom"), 0xFF000000); + specialDrew = true; } else if (tSpecial == -201) { drawText(10, 123, trans("206", "Scan for Assembly Line"), 0xFF000000); + specialDrew = true; } else if ((GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePre)) || (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePost))) { drawText( @@ -301,6 +313,49 @@ public class GT_NEI_AssLineHandler extends RecipeMapHandler { + GT_Utility.formatNumbers(tSpecial * this.mRecipeMap.mNEISpecialValueMultiplier) + this.mRecipeMap.mNEISpecialValuePost, 0xFF000000); + specialDrew = true; + } + int y = 123 + (specialDrew ? 10 : 0); + if (GT_Mod.gregtechproxy.mNEIRecipeOwner) { + if (recipe.owners.size() > 1) { + drawText( + 10, + y, + EnumChatFormatting.ITALIC + + GT_Utility.trans("226", "Original Recipe by: ") + + recipe.owners.get(0).getName(), + 0xFF000000); + y += 10; + for (int i = 1; i < recipe.owners.size(); i++) { + drawText( + 10, + y, + EnumChatFormatting.ITALIC + + GT_Utility.trans("227", "Modified by: ") + + recipe.owners.get(i).getName(), + 0xFF000000); + y += 10; + } + } else if (recipe.owners.size() > 0) { + drawText( + 10, + y, + EnumChatFormatting.ITALIC + + GT_Utility.trans("225", "Recipe by: ") + + recipe.owners.get(0).getName(), + 0xFF000000); + y += 10; + } + } + if (GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace + && recipe.stackTraces != null + && !recipe.stackTraces.isEmpty()) { + drawText(10, y, "stackTrace:", 0xFF000000); + y += 10; + for (StackTraceElement stackTrace : recipe.stackTraces.get(0)) { + drawText(10, y, stackTrace.toString(), 0xFF000000); + y += 10; + } } } else { int i = 0; diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index 06f7bde416..4f3d681899 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -17,6 +17,7 @@ import codechicken.nei.recipe.RecipeCatalysts; import codechicken.nei.recipe.TemplateRecipeHandler; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; +import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.OrePrefixes; import gregtech.api.gui.GT_GUIContainer; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -35,8 +36,11 @@ import java.awt.*; import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; @@ -47,19 +51,23 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.init.Blocks; 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; -@SuppressWarnings("all") 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 sOffsetY = 11; + private static final int M = 1000000; private static final ConcurrentMap CACHE = new ConcurrentHashMap<>(); - private Power mPower; + protected Power mPower; private String mRecipeName; // Name of the handler displayed on top private NEIHandlerAbsoluteTooltip mRecipeNameTooltip; private static final int RECIPE_NAME_WIDTH = 140; @@ -105,7 +113,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { .sorted() .map(CachedDefaultRecipe::new) .collect(Collectors.toList()); - // while the NEI parallelize handlers, for each individual handler it still uses sequential execution model + // while the NEI parallelize handlers, for each individual handler it still uses sequential execution model, // so we do not need any synchronization here // even if it does break, at worst case it's just recreating the cache multiple times, which should be fine cacheHolder.setCachedRecipes(cache); @@ -166,13 +174,13 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } private void loadTieredCraftingRecipesUpTo(byte upperTier) { - arecipes.addAll(getTieredRecipes((byte) 0, upperTier)); + arecipes.addAll(getTieredRecipes(upperTier)); } - private List getTieredRecipes(byte lowerTier, byte upperTier) { + private List getTieredRecipes(byte upperTier) { List recipes = getCache(); if (recipes.size() > 0) { - Range indexRange = getCacheHolder().getIndexRangeForTiers(lowerTier, upperTier); + Range indexRange = getCacheHolder().getIndexRangeForTiers((byte) 0, upperTier); recipes = recipes.subList(indexRange.getMinimum(), indexRange.getMaximum() + 1); } return recipes; @@ -205,11 +213,10 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (gtTileEntity instanceof GT_MetaTileEntity_BasicMachine) { Power power = ((GT_MetaTileEntity_BasicMachine) gtTileEntity).getPower(); handler.loadCraftingRecipes(getOverlayIdentifier(), power); - return handler; } else { handler.loadCraftingRecipes(getOverlayIdentifier(), (Object) null); - return handler; } + return handler; } } return this.getUsageHandler(inputId, ingredients); @@ -251,6 +258,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { public String getRecipeName() { if (mRecipeName == null) { mRecipeName = computeRecipeName(); + updateOverrideTextColor(); } return mRecipeName; } @@ -258,19 +266,24 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { private String computeRecipeName() { String recipeName = GT_LanguageManager.getTranslation(this.mRecipeMap.mUnlocalizedName); if (mPower != null) { - recipeName = addSuffixToRecipeName(recipeName, " (", mPower.getTierString() + ")"); + recipeName = addSuffixToRecipeName(recipeName, mPower.getTierString() + ")"); } return recipeName; } - private String addSuffixToRecipeName(String recipeName, String separator, String suffix) { + private String addSuffixToRecipeName(final String aRecipeName, final String suffix) { + final String recipeName; + final String separator; FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; - int recipeNameWidth = fontRenderer.getStringWidth(recipeName); + int recipeNameWidth = fontRenderer.getStringWidth(aRecipeName); int targetWidth = RECIPE_NAME_WIDTH - fontRenderer.getStringWidth(suffix); - if (recipeNameWidth + fontRenderer.getStringWidth(separator) > targetWidth) { - setupRecipeNameTooltip(recipeName + separator + suffix); + if (recipeNameWidth + fontRenderer.getStringWidth(" (") <= targetWidth) { + recipeName = aRecipeName; + separator = " ("; + } else { + setupRecipeNameTooltip(aRecipeName + " (" + suffix); separator = "...("; - recipeName = shrinkRecipeName(recipeName, targetWidth - fontRenderer.getStringWidth(separator)); + recipeName = shrinkRecipeName(aRecipeName, targetWidth - fontRenderer.getStringWidth(separator)); } return recipeName + separator + suffix; } @@ -299,7 +312,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { @Override public List handleItemTooltip( - GuiRecipe gui, ItemStack aStack, List currenttip, int aRecipeIndex) { + GuiRecipe gui, ItemStack aStack, List currentTip, int aRecipeIndex) { CachedRecipe tObject = this.arecipes.get(aRecipeIndex); if ((tObject instanceof CachedDefaultRecipe)) { CachedDefaultRecipe tRecipe = (CachedDefaultRecipe) tObject; @@ -310,7 +323,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { || (((FixedPositionedStack) tStack).mChance == 10000)) { break; } - currenttip.add( + currentTip.add( GT_Utility.trans("150", "Chance: ") + ((FixedPositionedStack) tStack).mChance / 100 + "." + (((FixedPositionedStack) tStack).mChance % 100 < 10 ? "0" + ((FixedPositionedStack) tStack).mChance % 100 @@ -325,16 +338,16 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { || (tStack.item.stackSize != 0)) { break; } - currenttip.add(GT_Utility.trans("151", "Does not get consumed in the process")); + currentTip.add(GT_Utility.trans("151", "Does not get consumed in the process")); break; } } } if (mRecipeNameTooltip != null) { - mRecipeNameTooltip.handleTooltip(currenttip, aRecipeIndex); + mRecipeNameTooltip.handleTooltip(currentTip, aRecipeIndex); } - return currenttip; + return currentTip; } private Power getPowerFromRecipeMap() { @@ -375,6 +388,20 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { 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("228", "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++; @@ -390,20 +417,64 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (mPower.getDurationTicks() > 0) { if (GT_Mod.gregtechproxy.mNEIRecipeSecondMode) { drawLine(lineCounter, GT_Utility.trans("158", "Time: ") + mPower.getDurationStringSeconds()); - lineCounter++; } else { drawLine(lineCounter, GT_Utility.trans("158", "Time: ") + mPower.getDurationStringTicks()); - lineCounter++; } + lineCounter++; } if (this.mRecipeMap.mNEIName.equals("gt.recipe.fusionreactor") || this.mRecipeMap.mNEIName.equals("gt.recipe.complexfusionreactor")) { - drawOptionalLine( + if (drawOptionalLine( lineCounter, getSpecialInfo(recipe.mSpecialValue) + " " - + formatSpecialValueFusion(recipe.mSpecialValue, recipe.mEUt)); + + formatSpecialValueFusion(recipe.mSpecialValue, recipe.mEUt))) { + lineCounter++; + } + } 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("226", "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("227", "Modified by: ") + + recipe.owners.get(i).getName()); + lineCounter++; + } + } else if (recipe.owners.size() > 0) { + drawLine( + lineCounter, + EnumChatFormatting.ITALIC + + GT_Utility.trans("225", "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++; + } } - drawOptionalLine(lineCounter, getSpecialInfo(recipe.mSpecialValue)); } private void drawOverrideDescription(String[] recipeDesc) { @@ -414,7 +485,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } } - private String getSpecialInfo(int specialValue) { + protected String getSpecialInfo(int specialValue) { String specialInfo = null; if (specialValue == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { specialInfo = GT_Utility.trans("159", "Needs Low Gravity"); @@ -437,14 +508,14 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { || (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePost)); } - private String formatSpecialValue(int SpecialValue) { + 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 = 0; + int tier; if (SpecialValue <= 10 * M * 16) { tier = 1; } else if (SpecialValue <= 20 * M * 16) { @@ -454,40 +525,59 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } else { tier = 4; } - if (Voltage <= 32768) { - tier = Math.max(tier, 1); - } else if (Voltage <= 65536) { + if (Voltage <= GT_Values.V[6]) { + // no-op + } else if (Voltage <= GT_Values.V[7]) { tier = Math.max(tier, 2); - } else if (Voltage <= 131072) { + } else if (Voltage <= GT_Values.V[8]) { tier = Math.max(tier, 3); } else { - tier = Math.max(tier, 4); + tier = 4; } return "(MK " + tier + ")"; } - private void drawOptionalLine(int lineNumber, String line, String prefix) { - if (!"unspecified".equals(line)) { + 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; } - private void drawOptionalLine(int lineNumber, String line) { - if (!"unspecified".equals(line)) { + protected boolean drawOptionalLine(int lineNumber, String line) { + if (!(line == null || "unspecified".equals(line))) { drawLine(lineNumber, line); + return true; } + return false; } - private void drawLine(int lineNumber, String line) { - drawText(10, 73 + lineNumber * 10, line, 0xFF000000); + protected void drawLine(int lineNumber, String line) { + drawText(10, getDescriptionYOffset() + lineNumber * 10, line, 0xFF000000); + } + + protected int getDescriptionYOffset() { + return 73; } public static class GT_RectHandler implements IContainerInputHandler, IContainerTooltipHandler { @Override - public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) { + public boolean mouseClicked(GuiContainer gui, int mouseX, int mouseY, int button) { if (canHandle(gui)) { NEI_TransferRectHost host = (NEI_TransferRectHost) gui; - if (hostRectContainsMouse(host, getMousePos(gui, mousex, mousey))) { + if (hostRectContainsMouse(host, getMousePos(gui, mouseX, mouseY))) { if (button == 0) { return handleTransferRectMouseClick(host, false); } @@ -499,11 +589,10 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { return false; } - private Point getMousePos(GuiContainer gui, int mousex, int mousey) { - Point point = new Point( - mousex - ((GT_GUIContainer) gui).getLeft() - getGuiOffset(gui)[0], - mousey - ((GT_GUIContainer) gui).getTop() - getGuiOffset(gui)[1]); - return point; + private Point getMousePos(GuiContainer gui, int mouseX, int mouseY) { + return new Point( + mouseX - ((GT_GUIContainer) gui).getLeft() - getGuiOffset(gui)[0], + mouseY - ((GT_GUIContainer) gui).getTop() - getGuiOffset(gui)[1]); } private boolean hostRectContainsMouse(NEI_TransferRectHost host, Point mousePos) { @@ -527,25 +616,25 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } @Override - public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { - if ((canHandle(gui)) && (currenttip.isEmpty())) { + public List handleTooltip(GuiContainer gui, int mouseX, int mouseY, List currentTip) { + if ((canHandle(gui)) && (currentTip.isEmpty())) { NEI_TransferRectHost host = (NEI_TransferRectHost) gui; - if (hostRectContainsMouse(host, getMousePos(gui, mousex, mousey))) { - currenttip.add(host.getNeiTransferRectTooltip()); + if (hostRectContainsMouse(host, getMousePos(gui, mouseX, mouseY))) { + currentTip.add(host.getNeiTransferRectTooltip()); } } - return currenttip; + return currentTip; } @Override - public List handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List currenttip) { - return currenttip; + public List handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List currentTip) { + return currentTip; } @Override public List handleItemTooltip( - GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List currenttip) { - return currenttip; + GuiContainer gui, ItemStack itemstack, int mouseX, int mouseY, List currentTip) { + return currentTip; } @Override @@ -557,21 +646,21 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {} @Override - public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {} + public void onMouseClicked(GuiContainer gui, int mouseX, int mouseY, int button) {} @Override - public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {} + public void onMouseUp(GuiContainer gui, int mouseX, int mouseY, int button) {} @Override - public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) { + public boolean mouseScrolled(GuiContainer gui, int mouseX, int mouseY, int scrolled) { return false; } @Override - public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {} + public void onMouseScrolled(GuiContainer gui, int mouseX, int mouseY, int scrolled) {} @Override - public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {} + public void onMouseDragged(GuiContainer gui, int mouseX, int mouseY, int button, long heldTime) {} } public static class FixedPositionedStack extends PositionedStack { @@ -634,6 +723,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { public final List mInputs; // Draw a grid of fluids and items (in that order). + @SuppressWarnings("unused") // Public API method public void drawNEIItemAndFluidGrid( ItemStack[] ItemArray, FluidStack[] FluidArray, @@ -695,7 +785,6 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } } } - ; // Draws a grid of items for NEI rendering. private void drawNEIItemGrid( @@ -709,11 +798,11 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { if (ItemArray.length > x_dir_max_items * y_max_dir_max_items) { GT_Log.err.println("Recipe cannot be properly displayed in NEI due to too many items."); } - // 18 pixels to get to a new grid for placing a item tile since they are 16x16 and have 1 pixel buffers + // 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 x_max = x_coord_origin + x_dir_max_items * 18; - // Temp variables to keep track of current coords to place item at. + // Temp variables to keep track of current coordinates to place item at. int x_coord = x_coord_origin; int y_coord = y_coord_origin; @@ -741,56 +830,34 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } } - // Draws a grid of fluids for NEI rendering. - private void drawNEIFluidGrid( - FluidStack[] FluidArray, - int x_coord_origin, - int y_coord_origin, - int x_dir_max_fluids, - int y_max_dir_max_fluids, - GT_Recipe Recipe, - boolean is_input) { - - if (FluidArray.length > x_dir_max_fluids * y_max_dir_max_fluids) { - GT_Log.err.println("Recipe cannot be properly displayed in NEI due to too many fluids."); - } - - // 18 pixels to get to a new grid for placing a fluid tile since they are 16x16 and have 1 pixel buffers - // around them. - int x_max = x_coord_origin + x_dir_max_fluids * 18; - - // Temp variables to keep track of current coords to place fluid at. - int x_coord = x_coord_origin; - int y_coord = y_coord_origin; - - // Iterate over all fluids in array and display them. - for (FluidStack fluid : FluidArray) { - if (fluid != GT_Values.NF) { - if (is_input) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(fluid, true), x_coord, y_coord, true)); - } else { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(fluid, true), - x_coord, - y_coord, - GT_NEI_DefaultHandler.this.mRecipeMap.mNEIUnificateOutput)); - } - x_coord += 18; - if (x_coord == x_max) { - x_coord = x_coord_origin; - y_coord += 18; - } - } - } - } - + @SuppressWarnings("deprecation") public CachedDefaultRecipe(GT_Recipe aRecipe) { super(); this.mRecipe = aRecipe; List maybeIn; List maybeOut; + try { + maybeIn = GT_NEI_DefaultHandler.this.mRecipeMap.getInputPositionedStacks(aRecipe); + } catch (NullPointerException npe) { + maybeIn = null; + GT_Log.err.println("CachedDefaultRecipe - Invalid InputPositionedStacks " + aRecipe); + npe.printStackTrace(GT_Log.err); + } + try { + maybeOut = GT_NEI_DefaultHandler.this.mRecipeMap.getOutputPositionedStacks(aRecipe); + } catch (NullPointerException npe) { + maybeOut = null; + GT_Log.err.println("CachedDefaultRecipe - Invalid OutputPositionedStacks " + aRecipe); + npe.printStackTrace(GT_Log.err); + } + + if (maybeOut != null && maybeIn != null) { + mOutputs = maybeOut; + mInputs = maybeIn; + return; + } + try { maybeIn = aRecipe.getInputPositionedStacks(); } catch (NullPointerException npe) { @@ -829,8 +896,6 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 1, aRecipe, true); break; case 4: - drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 2, aRecipe, true); - break; case 5: drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 2, aRecipe, true); break; @@ -857,8 +922,6 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 2, 2, aRecipe, false); break; case 5: - drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 3, 2, aRecipe, false); - break; case 6: drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 3, 2, aRecipe, false); break; @@ -946,7 +1009,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { @Nullable private SoftReference> mCachedRecipes; - private Range[] mTierIndexes; + private Map> mTierIndexes; private Range mTierRange; public int getCachedRecipesVersion() { @@ -974,8 +1037,11 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } private void computeTierIndexes() { - mTierIndexes = new Range[GT_Values.V.length]; - Iterator iterator = mCachedRecipes.get().iterator(); + // Holds 16 elements without rehashing + mTierIndexes = new HashMap<>(GT_Values.V.length + 1, 1f); + assert mCachedRecipes != null; + Iterator iterator = + Objects.requireNonNull(mCachedRecipes.get()).iterator(); int index = 0; int minIndex = 0; @@ -988,7 +1054,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { GT_Utility.getTier(recipe.mRecipe.mEUt / GT_NEI_DefaultHandler.this.mRecipeMap.mAmperage); if (recipeTier != previousTier) { if (maxIndex != -1) { - mTierIndexes[previousTier] = Range.between(minIndex, maxIndex); + mTierIndexes.put(previousTier, Range.between(minIndex, maxIndex)); } else { lowestTier = recipeTier; } @@ -998,7 +1064,7 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { maxIndex = index; index++; if (!iterator.hasNext()) { - mTierIndexes[recipeTier] = Range.between(minIndex, maxIndex); + mTierIndexes.put(recipeTier, Range.between(minIndex, maxIndex)); mTierRange = Range.between(lowestTier, recipeTier); } } @@ -1006,18 +1072,18 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { private int getLowIndexForTier(byte lowerTier) { byte lowTier = (byte) Math.max(mTierRange.getMinimum(), lowerTier); - while (mTierIndexes[lowTier] == null) { + while (mTierIndexes.get(lowTier) == null) { lowTier++; } - return mTierIndexes[lowTier].getMinimum(); + return mTierIndexes.get(lowTier).getMinimum(); } private int getHighIndexForTier(byte upperTier) { byte highTier = (byte) Math.min(mTierRange.getMaximum(), upperTier); - while (mTierIndexes[highTier] == null) { + while (mTierIndexes.get(highTier) == null) { highTier--; } - return mTierIndexes[highTier].getMaximum(); + return mTierIndexes.get(highTier).getMaximum(); } } } -- cgit