diff options
Diffstat (limited to 'src/main/java/gregtech/nei')
| -rw-r--r-- | src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java | 12 | ||||
| -rw-r--r-- | src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java | 136 | ||||
| -rw-r--r-- | src/main/java/gregtech/nei/NEI_GT_Config.java | 52 | ||||
| -rw-r--r-- | src/main/java/gregtech/nei/RecipeMapHandler.java | 20 |
4 files changed, 135 insertions, 85 deletions
diff --git a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java index 6c31a8ab6a..6aa8d50b98 100644 --- a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java @@ -9,7 +9,6 @@ import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.GuiUsageRecipe; import codechicken.nei.recipe.TemplateRecipeHandler; -import cpw.mods.fml.common.event.FMLInterModComms; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.enums.OrePrefixes; @@ -36,7 +35,7 @@ import java.util.List; import static gregtech.api.util.GT_Utility.trans; -public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { +public class GT_NEI_AssLineHandler extends RecipeMapHandler { public static final int sOffsetX = 5; public static final int sOffsetY = 11; @@ -45,16 +44,9 @@ public class GT_NEI_AssLineHandler extends TemplateRecipeHandler { GuiContainerManager.addTooltipHandler(new GT_RectHandler()); } - protected final GT_Recipe.GT_Recipe_Map mRecipeMap; - public GT_NEI_AssLineHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) {//this is called when recipes should be shown - this.mRecipeMap = aRecipeMap; + super(aRecipeMap); this.transferRects.add(new RecipeTransferRect(new Rectangle(138, 18, 18, 18), getOverlayIdentifier())); - if (!NEI_GT_Config.sIsAdded) { - FMLInterModComms.sendRuntimeMessage(GT_Values.GT, "NEIPlugins", "register-crafting-handler", "gregtech@" + getRecipeName() + "@" + getOverlayIdentifier()); - GuiCraftingRecipe.craftinghandlers.add(this); - GuiUsageRecipe.usagehandlers.add(this); - } } public List<GT_Recipe> getSortedRecipes() { diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index 802fcdbc6e..f51acd9a77 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -9,11 +9,12 @@ import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.GuiUsageRecipe; import codechicken.nei.recipe.TemplateRecipeHandler; -import cpw.mods.fml.common.event.FMLInterModComms; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; import gregtech.api.enums.OrePrefixes; import gregtech.api.gui.GT_GUIContainer_BasicMachine; +import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; @@ -36,7 +37,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { +public class GT_NEI_DefaultHandler extends RecipeMapHandler { public static final int sOffsetX = 5; public static final int sOffsetY = 11; @@ -45,16 +46,9 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { GuiContainerManager.addTooltipHandler(new GT_RectHandler()); } - protected final GT_Recipe.GT_Recipe_Map mRecipeMap; - public GT_NEI_DefaultHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) { - this.mRecipeMap = aRecipeMap; + super(aRecipeMap); this.transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(65, 13, 36, 18), getOverlayIdentifier())); - if (!NEI_GT_Config.sIsAdded) { - FMLInterModComms.sendRuntimeMessage(GT_Values.GT, "NEIPlugins", "register-crafting-handler", "gregtech@" + getRecipeName() + "@" + getOverlayIdentifier()); - GuiCraftingRecipe.craftinghandlers.add(this); - GuiUsageRecipe.usagehandlers.add(this); - } } public List<GT_Recipe> getSortedRecipes() { @@ -98,13 +92,14 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { } } FluidStack tFluid = GT_Utility.getFluidForFilledItem(aResult, true); + FluidStack tFluidStack; if (tFluid != null) { + tFluidStack = tFluid; tResults.add(GT_Utility.getFluidDisplayStack(tFluid, false)); - for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { - if (tData.fluid.isFluidEqual(tFluid)) { - tResults.add(GT_Utility.copyOrNull(tData.filledContainer)); - } - } + } + else tFluidStack = GT_Utility.getFluidFromDisplayStack(aResult); + if (tFluidStack != null) { + tResults.addAll(GT_Utility.getContainersFromFluid(tFluidStack)); } for (GT_Recipe tRecipe : getSortedRecipes()) { if (!tRecipe.mHidden) { @@ -132,13 +127,14 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { } } FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true); + FluidStack tFluidStack; if (tFluid != null) { + tFluidStack = tFluid; tInputs.add(GT_Utility.getFluidDisplayStack(tFluid, false)); - for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { - if (tData.fluid.isFluidEqual(tFluid)) { - tInputs.add(GT_Utility.copyOrNull(tData.filledContainer)); - } - } + } + else tFluidStack = GT_Utility.getFluidFromDisplayStack(aInput); + if (tFluidStack != null) { + tInputs.addAll(GT_Utility.getContainersFromFluid(tFluidStack)); } for (GT_Recipe tRecipe : getSortedRecipes()) { if (!tRecipe.mHidden) { @@ -210,16 +206,16 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { return currenttip; } - @Override + @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(); - if (recipeDesc == null) { - if (tEUt != 0) { - drawText(10, 73, trans("152","Total: ") + GT_Utility.formatNumbers((long) tDuration * tEUt) + " EU", 0xFF000000); - drawText(10, 83, trans("153","Usage: ") + GT_Utility.formatNumbers(tEUt) + " EU/t", 0xFF000000); - if (this.mRecipeMap.mShowVoltageAmperageInNEI) { + 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(); + if (recipeDesc == null) { + if (tEUt != 0) { + drawText(10, 73, trans("152","Total: ") + GT_Utility.formatNumbers((long) tDuration * tEUt) + " EU", 0xFF000000); + drawText(10, 83, trans("153","Usage: ") + GT_Utility.formatNumbers(tEUt) + " EU/t", 0xFF000000); + if (this.mRecipeMap.mShowVoltageAmperageInNEI) { int voltage = tEUt / this.mRecipeMap.mAmperage; byte tier = GT_Utility.getTier(voltage); if (tier < 0 || tier >= 16) { @@ -229,19 +225,19 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { drawText(10, 93, trans("154","Voltage: ") + GT_Utility.formatNumbers(voltage) + " EU (" + GT_Values.VN[tier] + ")", 0xFF000000); } drawText(10, 103, trans("155","Amperage: ") + GT_Utility.formatNumbers(this.mRecipeMap.mAmperage), 0xFF000000); - } else { - drawText(10, 93, trans("156","Voltage: unspecified"), 0xFF000000); - drawText(10, 103, trans("157","Amperage: unspecified"), 0xFF000000); - } - } - if (tDuration > 0) { - drawText(10, 113, trans("158","Time: ") + GT_Utility.formatNumbers(0.05d * tDuration) + trans("161"," secs"), 0xFF000000); - } - int tSpecial = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mSpecialValue; - if (tSpecial == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { - drawText(10, 123, trans("159","Needs Low Gravity"), 0xFF000000); - } else if (tSpecial == -200 && GT_Mod.gregtechproxy.mEnableCleanroom) { - drawText(10, 123, trans("160","Needs Cleanroom"), 0xFF000000); + } else { + drawText(10, 93, trans("156","Voltage: unspecified"), 0xFF000000); + drawText(10, 103, trans("157","Amperage: unspecified"), 0xFF000000); + } + } + if (tDuration > 0) { + drawText(10, 113, trans("158","Time: ") + GT_Utility.formatNumbers(0.05d * tDuration) + trans("161"," secs"), 0xFF000000); + } + int tSpecial = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mSpecialValue; + if (tSpecial == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { + drawText(10, 123, trans("159","Needs Low Gravity"), 0xFF000000); + } else if (tSpecial == -200 && GT_Mod.gregtechproxy.mEnableCleanroom) { + drawText(10, 123, trans("160","Needs Cleanroom"), 0xFF000000); } else if (tSpecial == -201) { drawText(10, 123, trans("206","Scan for Assembly Line"), 0xFF000000); } else if (tSpecial == -300 && GT_Mod.gregtechproxy.mEnableCleanroom) { @@ -249,16 +245,16 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { } else if (tSpecial == -400) { drawText(10, 123, trans("216","Deprecated Recipe"), 0xFF000000); } else if ((GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePre)) || (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePost))) { - drawText(10, 123, this.mRecipeMap.mNEISpecialValuePre + GT_Utility.formatNumbers(tSpecial * this.mRecipeMap.mNEISpecialValueMultiplier) + this.mRecipeMap.mNEISpecialValuePost, 0xFF000000); - } - } else { - int i = 0; - for (String descLine : recipeDesc) { - drawText(10, 73 + 10 * i, descLine, 0xFF000000); - i++; - } - } - } + drawText(10, 123, this.mRecipeMap.mNEISpecialValuePre + GT_Utility.formatNumbers(tSpecial * this.mRecipeMap.mNEISpecialValueMultiplier) + this.mRecipeMap.mNEISpecialValuePost, 0xFF000000); + } + } else { + int i = 0; + for (String descLine : recipeDesc) { + drawText(10, 73 + 10 * i, descLine, 0xFF000000); + i++; + } + } + } public static class GT_RectHandler implements IContainerInputHandler, IContainerTooltipHandler { @@ -282,8 +278,8 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { public boolean canHandle(GuiContainer gui) { return (gui instanceof GT_GUIContainer_BasicMachine && GT_Utility.isStringValid(((GT_GUIContainer_BasicMachine) gui).mNEI)) - || (gui instanceof GT_GUIContainer_FusionReactor && GT_Utility.isStringValid(((GT_GUIContainer_FusionReactor) gui).mNEI)) - || (gui instanceof GT_GUIContainer_PrimitiveBlastFurnace && GT_Utility.isStringValid(((GT_GUIContainer_PrimitiveBlastFurnace) gui).mNEI)); + || (gui instanceof GT_GUIContainer_FusionReactor && GT_Utility.isStringValid(((GT_GUIContainer_FusionReactor) gui).mNEI)) + || (gui instanceof GT_GUIContainer_PrimitiveBlastFurnace && GT_Utility.isStringValid(((GT_GUIContainer_PrimitiveBlastFurnace) gui).mNEI)); } @Override @@ -409,33 +405,33 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { public CachedDefaultRecipe(GT_Recipe aRecipe) { super(); this.mRecipe = aRecipe; - List<PositionedStack> maybeIn; - List<PositionedStack> maybeOut; - - try { + List<PositionedStack> maybeIn; + List<PositionedStack> maybeOut; + + try { maybeIn = aRecipe.getInputPositionedStacks(); } catch(NullPointerException npe) { - maybeIn = null; - GT_Log.err.println("CachedDefaultRecipe - Invalid InputPositionedStacks " + aRecipe.toString()); + maybeIn = null; + GT_Log.err.println("CachedDefaultRecipe - Invalid InputPositionedStacks " + aRecipe.toString()); npe.printStackTrace(GT_Log.err); } - try { + try { maybeOut = aRecipe.getOutputPositionedStacks(); } catch (NullPointerException npe) { - maybeOut = null; + maybeOut = null; GT_Log.err.println("CachedDefaultRecipe - Invalid OutputPositionedStacks " + aRecipe.toString()); npe.printStackTrace(GT_Log.err); } - + if ( maybeIn != null && maybeOut != null) { - mInputs = maybeIn; - mOutputs = maybeOut; - return; + mInputs = maybeIn; + mOutputs = maybeOut; + return; } mOutputs = new ArrayList<>(); mInputs = new ArrayList<>(); - + int tStartIndex = 0; switch (GT_NEI_DefaultHandler.this.mRecipeMap.mUsualInputCount) { case 0: @@ -884,9 +880,9 @@ public class GT_NEI_DefaultHandler extends TemplateRecipeHandler { public List<PositionedStack> getOtherStacks() { return this.mOutputs; } - } - + } + public String trans(String aKey, String aEnglish){ - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); } } diff --git a/src/main/java/gregtech/nei/NEI_GT_Config.java b/src/main/java/gregtech/nei/NEI_GT_Config.java index 5aef5b2901..0b4476eeef 100644 --- a/src/main/java/gregtech/nei/NEI_GT_Config.java +++ b/src/main/java/gregtech/nei/NEI_GT_Config.java @@ -1,24 +1,66 @@ package gregtech.nei; import codechicken.nei.api.IConfigureNEI; +import codechicken.nei.recipe.GuiCraftingRecipe; +import codechicken.nei.recipe.GuiUsageRecipe; +import codechicken.nei.recipe.TemplateRecipeHandler; +import com.google.common.collect.ImmutableMap; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.event.FMLInterModComms; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.util.GT_Recipe; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + public class NEI_GT_Config implements IConfigureNEI { + /** + * This map determines the order in which NEI handlers will be registered and displayed in tabs. + * + * <p>Handlers will be displayed in ascending order of integer value. Any recipe map that is not + * present in this map will be assigned a value of 0. Negative values are fine. + */ + private static final ImmutableMap<GT_Recipe.GT_Recipe_Map, Integer> RECIPE_MAP_ORDERING = + ImmutableMap.<GT_Recipe.GT_Recipe_Map, Integer>builder() + .put(GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes, 1) + .put(GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes, 2) + .build(); + + private static final Comparator<RecipeMapHandler> RECIPE_MAP_HANDLER_COMPARATOR = + Comparator.comparingInt( + handler -> RECIPE_MAP_ORDERING.getOrDefault(handler.getRecipeMap(), 0)); + public static boolean sIsAdded = true; public static GT_NEI_AssLineHandler ALH; + private static void addHandler(TemplateRecipeHandler handler) { + FMLInterModComms.sendRuntimeMessage( + GT_Values.GT, "NEIPlugins", "register-crafting-handler", + "gregtech@" + handler.getRecipeName() + "@" + handler.getOverlayIdentifier()); + GuiCraftingRecipe.craftinghandlers.add(handler); + GuiUsageRecipe.usagehandlers.add(handler); + } + @Override public void loadConfig() { sIsAdded = false; - for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) { - if (tMap.mNEIAllowed) { - new GT_NEI_DefaultHandler(tMap); - } - } if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { + List<RecipeMapHandler> handlers = new ArrayList<>(); + ALH = new GT_NEI_AssLineHandler(GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes); + handlers.add(ALH); + + for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) { + if (tMap.mNEIAllowed) { + handlers.add(new GT_NEI_DefaultHandler(tMap)); + } + } + + handlers.sort(RECIPE_MAP_HANDLER_COMPARATOR); + handlers.forEach(NEI_GT_Config::addHandler); + codechicken.nei.api.API.addItemListEntry(ItemList.VOLUMETRIC_FLASK.get(1)); } sIsAdded = true; diff --git a/src/main/java/gregtech/nei/RecipeMapHandler.java b/src/main/java/gregtech/nei/RecipeMapHandler.java new file mode 100644 index 0000000000..aac322d303 --- /dev/null +++ b/src/main/java/gregtech/nei/RecipeMapHandler.java @@ -0,0 +1,20 @@ +package gregtech.nei; + +import codechicken.nei.recipe.TemplateRecipeHandler; +import gregtech.api.util.GT_Recipe; + +/** + * This abstract class represents an NEI handler that is constructed from a + * {@link GT_Recipe.GT_Recipe_Map}, and allows us to sort NEI handlers by recipe map. + */ +abstract class RecipeMapHandler extends TemplateRecipeHandler { + protected final GT_Recipe.GT_Recipe_Map mRecipeMap; + + RecipeMapHandler(GT_Recipe.GT_Recipe_Map mRecipeMap) { + this.mRecipeMap = mRecipeMap; + } + + GT_Recipe.GT_Recipe_Map getRecipeMap() { + return mRecipeMap; + } +} |
