diff options
Diffstat (limited to 'src/main')
13 files changed, 225 insertions, 61 deletions
diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index e8640431b5..1fc7c0c3af 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -55,7 +55,7 @@ public enum OrePrefixes { @Deprecated ingotQuad("4x Ingots", "Quadruple ", " Ingot", false, false, false, false, false, false, false, false, false, false, B[1], -1, 16, 15), ingotTriple("3x Ingots", "Triple ", " Ingot", true, true, false, false, false, false, true, false, false, false, B[1], M * 3, 21, 14), // A triple Ingot. ingotDouble("2x Ingots", "Double ", " Ingot", true, true, false, false, false, false, true, true, false, false, B[1], M * 2, 32, 13), // A double Ingot. Introduced by TerraFirmaCraft - ingotHot("Hot Ingots", "Hot ", " Ingot", true, true, false, false, false, false, false, true, false, false, B[1], M * 1, 16, 12), // A hot Ingot, which has to be cooled down by a Vacuum Freezer. + ingotHot("Hot Ingots", "Hot ", " Ingot", true, true, false, false, false, false, false, true, false, false, B[1], M * 1, 64, 12), // A hot Ingot, which has to be cooled down by a Vacuum Freezer. ingot("Ingots", "", " Ingot", true, true, false, false, false, false, false, true, false, false, B[1], M * 1, 64, 11), // A regular Ingot. Introduced by Eloraam gemChipped("Chipped Gemstones", "Chipped ", "", true, true, true, false, false, false, true, true, false, false, B[2], M / 4, 64, 59), // A regular Gem worth one small Dust. Introduced by TerraFirmaCraft gemFlawed("Flawed Gemstones", "Flawed ", "", true, true, true, false, false, false, true, true, false, false, B[2], M / 2, 64, 60), // A regular Gem worth two small Dusts. Introduced by TerraFirmaCraft diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java index f500e8027e..2490b37eb1 100644 --- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java +++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java @@ -504,6 +504,8 @@ public interface IGT_RecipeAdder { boolean addVacuumFreezerRecipe(ItemStack aInput1, ItemStack aOutput1, int aDuration, int aEUt); + boolean addVacuumFreezerRecipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt); + /** * Adds a Fuel for My Generators * diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index cfb4d33150..5a0a2b680f 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -8,6 +8,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ClientPreference; import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gregtech.api.util.extensions.ArrayExt; @@ -23,6 +24,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { public GT_Recipe_Map mRecipeMap = null; public boolean disableSort; public boolean disableFilter = false; + public boolean disableLimited = true; public GT_MetaTileEntity_Hatch_InputBus(int id, String name, String nameRegional, int tier) { this(id, name, nameRegional, tier, getSlots(tier)); @@ -162,6 +164,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { super.saveNBTData(aNBT); aNBT.setBoolean("disableSort", disableSort); aNBT.setBoolean("disableFilter", disableFilter); + aNBT.setBoolean("disableLimited", disableLimited); } @Override @@ -169,6 +172,8 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { super.loadNBTData(aNBT); disableSort = aNBT.getBoolean("disableSort"); disableFilter = aNBT.getBoolean("disableFilter"); + if(aNBT.hasKey("disableLimited")) + disableLimited = aNBT.getBoolean("disableLimited"); } @Override @@ -176,8 +181,18 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) return; if (aPlayer.isSneaking()) { - disableSort = !disableSort; - GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Sort mode: " + (disableSort ? "Disabled" : "Enabled"))); + if(disableSort) { + disableSort = false; + } else { + if(disableLimited) { + disableLimited = false; + } else { + disableSort = true; + disableLimited = true; + } + } + GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableSort." + disableSort) + " " + + StatCollector.translateToLocal("GT5U.hatch.disableLimited." + disableLimited)); } else { disableFilter = !disableFilter; GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableFilter." + disableFilter)); @@ -196,6 +211,15 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { @Override public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return aSide == getBaseMetaTileEntity().getFrontFacing() && (mRecipeMap == null || disableFilter || mRecipeMap.containsInput(aStack)); + return aSide == getBaseMetaTileEntity().getFrontFacing() + && (mRecipeMap == null || disableFilter || mRecipeMap.containsInput(aStack)) + && (disableLimited || limitedAllowPutStack(aIndex, aStack)); + } + + protected boolean limitedAllowPutStack(int aIndex, ItemStack aStack) { + for (int i = 0; i < getSizeInventory(); i++) + if (GT_Utility.areStacksEqual(GT_OreDictUnificator.get_nocopy(aStack), mInventory[i])) + return i == aIndex; + return mInventory[aIndex] == null; } } diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index f941a86f5c..9b0bfb970a 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -302,6 +302,13 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } } + public GT_Recipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt) { + this(false, null, null, null, null, new FluidStack[]{aInput1}, new FluidStack[]{aOutput1}, Math.max(aDuration, 1), aEUt, 0); + if (mFluidInputs.length > 0 && mFluidOutputs[0] != null) { + GT_Recipe_Map.sVacuumRecipes.addRecipe(this); + } + } + //Dummy GT_Recipe maker... public GT_Recipe(ItemStack[] aInputs, ItemStack[] aOutputs, Object aSpecialItems, int[] aChances, FluidStack[] aFluidInputs, FluidStack[] aFluidOutputs, int aDuration, int aEUt, int aSpecialValue){ this(true, aInputs, aOutputs, aSpecialItems, aChances, aFluidInputs, aFluidOutputs, aDuration, aEUt, aSpecialValue); @@ -609,7 +616,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public static final GT_Recipe_Map sBlastRecipes = new GT_Recipe_Map(new HashSet<>(800), "gt.recipe.blastfurnace", "Blast Furnace", null, RES_PATH_GUI + "basicmachines/Default", 2, 2, 1, 0, 1, "Heat Capacity: ", 1, " K", false, true); public static final GT_Recipe_Map sPrimitiveBlastRecipes = new GT_Recipe_Map(new HashSet<>(200), "gt.recipe.primitiveblastfurnace", "Primitive Blast Furnace", null, RES_PATH_GUI + "basicmachines/Default", 3, 3, 1, 0, 1, E, 1, E, false, true); public static final GT_Recipe_Map sImplosionRecipes = new GT_Recipe_Map(new HashSet<>(900), "gt.recipe.implosioncompressor", "Implosion Compressor", null, RES_PATH_GUI + "basicmachines/Default", 2, 2, 2, 0, 1, E, 1, E, true, true); - public static final GT_Recipe_Map sVacuumRecipes = new GT_Recipe_Map(new HashSet<>(305), "gt.recipe.vacuumfreezer", "Vacuum Freezer", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 1, 0, 1, E, 1, E, false, true); + public static final GT_Recipe_Map sVacuumRecipes = new GT_Recipe_Map(new HashSet<>(305), "gt.recipe.vacuumfreezer", "Vacuum Freezer", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 0, 1, E, 1, E, false, true); public static final GT_Recipe_Map sChemicalRecipes = new GT_Recipe_Map(new HashSet<>(1170), "gt.recipe.chemicalreactor", "Chemical Reactor", null, RES_PATH_GUI + "basicmachines/ChemicalReactor", 2, 2, 1, 0, 1, E, 1, E, true, true); public static final GT_Recipe_Map sMultiblockChemicalRecipes = new GT_Recipe_Map_LargeChemicalReactor(); public static final GT_Recipe_Map sDistillationRecipes = new GT_Recipe_Map_DistillationTower(); diff --git a/src/main/java/gregtech/common/GT_RecipeAdder.java b/src/main/java/gregtech/common/GT_RecipeAdder.java index cdf3bf38b7..7e996be264 100644 --- a/src/main/java/gregtech/common/GT_RecipeAdder.java +++ b/src/main/java/gregtech/common/GT_RecipeAdder.java @@ -10,11 +10,8 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.interfaces.internal.IGT_RecipeAdder; import gregtech.api.objects.GT_FluidStack; import gregtech.api.objects.ItemData; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Recipe; +import gregtech.api.util.*; import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine; -import gregtech.api.util.GT_Utility; import gregtech.common.items.GT_IntegratedCircuit_Item; import mods.railcraft.common.blocks.aesthetics.cube.EnumCube; import mods.railcraft.common.items.RailcraftToolItems; @@ -660,6 +657,11 @@ public class GT_RecipeAdder implements IGT_RecipeAdder { return false; } new GT_Recipe(aInput1, aOutput1, aDuration, aEUt, 0);//Since all other methods are taken + FluidStack tInputFluid = GT_Utility.getFluidForFilledItem(aInput1, true); + FluidStack tOutputFluid = GT_Utility.getFluidForFilledItem(aOutput1, true); + if (tInputFluid != null && tOutputFluid != null) { + addVacuumFreezerRecipe(tInputFluid, tOutputFluid, aDuration, aEUt); + } return true; } @@ -672,6 +674,20 @@ public class GT_RecipeAdder implements IGT_RecipeAdder { return false; } new GT_Recipe(aInput1, aOutput1, aDuration); + FluidStack tInputFluid = GT_Utility.getFluidForFilledItem(aInput1, true); + FluidStack tOutputFluid = GT_Utility.getFluidForFilledItem(aOutput1, true); + if (tInputFluid != null && tOutputFluid != null) { + addVacuumFreezerRecipe(tInputFluid, tOutputFluid, aDuration, 120); + } + return true; + } + + @Override + public boolean addVacuumFreezerRecipe(FluidStack aInput1, FluidStack aOutput1, int aDuration, int aEUt) { + if ((aInput1 == null) || (aOutput1 == null)) { + return false; + } + new GT_Recipe(aInput1, aOutput1, aDuration, aEUt); return true; } diff --git a/src/main/java/gregtech/common/items/GT_FluidDisplayItem.java b/src/main/java/gregtech/common/items/GT_FluidDisplayItem.java index a8487651b4..ad4e1f6bdd 100644 --- a/src/main/java/gregtech/common/items/GT_FluidDisplayItem.java +++ b/src/main/java/gregtech/common/items/GT_FluidDisplayItem.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; import gregtech.api.items.GT_Generic_Item; import gregtech.api.util.GT_Utility; import net.minecraft.client.renderer.texture.IIconRegister; @@ -16,13 +17,20 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Stream; @SuppressWarnings({"rawtypes","unchecked"}) public class GT_FluidDisplayItem extends GT_Generic_Item { + + private static final Map<Fluid, String> sFluidTooltips = new HashMap<>(); + public GT_FluidDisplayItem() { super("GregTech_FluidDisplay", "Fluid Display", null); ItemList.Display_Fluid.set(this); @@ -30,6 +38,10 @@ public class GT_FluidDisplayItem extends GT_Generic_Item { @Override protected void addAdditionalToolTips(List aList, ItemStack aStack, EntityPlayer aPlayer) { + if (FluidRegistry.getFluid(aStack.getItemDamage()) != null) { + String tChemicalFormula = getChemicalFormula(new FluidStack(FluidRegistry.getFluid(aStack.getItemDamage()), 1)); + if (!tChemicalFormula.isEmpty()) aList.add(EnumChatFormatting.GRAY + tChemicalFormula + EnumChatFormatting.GRAY); + } NBTTagCompound aNBT = aStack.getTagCompound(); if (GT_Values.D1) { Fluid tFluid = FluidRegistry.getFluid(aStack.getItemDamage()); @@ -40,7 +52,7 @@ public class GT_FluidDisplayItem extends GT_Generic_Item { if (aNBT != null) { long tToolTipAmount = aNBT.getLong("mFluidDisplayAmount"); if (tToolTipAmount > 0L) { - aList.add(EnumChatFormatting.BLUE + String.format(trans("016", "Amount: %s L"), "" + tToolTipAmount) + EnumChatFormatting.GRAY); + aList.add(EnumChatFormatting.BLUE + String.format(trans("016", "Amount: %s L"), "" + tToolTipAmount) + EnumChatFormatting.GRAY); } aList.add(EnumChatFormatting.RED + String.format(trans("017", "Temperature: %s K"), "" + aNBT.getLong("mFluidDisplayHeat")) + EnumChatFormatting.GRAY); aList.add(EnumChatFormatting.GREEN + String.format(trans("018", "State: %s"), aNBT.getBoolean("mFluidState") ? "Gas" : "Liquid") + EnumChatFormatting.GRAY); @@ -90,6 +102,37 @@ public class GT_FluidDisplayItem extends GT_Generic_Item { return ""; } + @SideOnly(Side.CLIENT) + public String getChemicalFormula(FluidStack aRealFluid) { + return sFluidTooltips.computeIfAbsent(aRealFluid.getFluid(), + fluid -> { + for(ItemStack tContainer : GT_Utility.getContainersFromFluid(aRealFluid)) { + if (isCell(tContainer)) { + Materials tMaterial = getMaterialFromCell(tContainer); + if (!tMaterial.equals(Materials._NULL)) { + if (tMaterial.mChemicalFormula.equals("?")) { + return ""; + } + else { + return tMaterial.mChemicalFormula; + } + } + else { + // For GT++ Fluid Display + // GT++ didn't register a Material in GT, so I have too find the Chemical Formula in its cell's tooltip + List tTooltip = tContainer.getTooltip(null, true); + for (Object tInfo : tTooltip) { + if (!((String) tInfo).contains(" ") && !((String) tInfo).contains(":") && tTooltip.indexOf(tInfo) != 0) { + return (String) tInfo; + } + } + } + } + } + return ""; + }); + } + @Override @SideOnly(Side.CLIENT) public void getSubItems(Item aItem, CreativeTabs aTab, List aList) { @@ -103,4 +146,26 @@ public class GT_FluidDisplayItem extends GT_Generic_Item { } } } + + public static boolean isCell(ItemStack tItemStack) { + for (int tOreDict : OreDictionary.getOreIDs(tItemStack)) { + String tOreDictName = OreDictionary.getOreName(tOreDict); + if (tOreDictName.startsWith("cell")) return true; + } + return false; + } + + public static Materials getMaterialFromCell(ItemStack tItemStack) { + for (int tOreDict : OreDictionary.getOreIDs(tItemStack)) { + String tOreDictName = OreDictionary.getOreName(tOreDict); + if (tOreDictName.startsWith("cell")) { + return Materials.getRealMaterial( + tOreDictName.replace("cell", "") + .replace("Molten", "") + .replace("Plasma", "") + ); + } + } + return Materials._NULL; + } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java index 774639401a..480367095c 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java @@ -5,7 +5,6 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_Utility; import gregtech.common.gui.GT_Container_ChestBuffer; import gregtech.common.gui.GT_GUIContainer_ChestBuffer; import net.minecraft.entity.player.InventoryPlayer; @@ -70,7 +69,7 @@ public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer { protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { if (aTimer % tickRate[mTier] > 0) return; - if(aBaseMetaTileEntity.hasInventoryBeenModified()) { + if(this.bSortStacks && aBaseMetaTileEntity.hasInventoryBeenModified()) { fillStacksIntoFirstSlots(); } // mSuccess will be negative if the call is caused by the %200 aTimer, always try to push. Otherwise it will be positive. diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java index b7f24f7e7a..843f2ff337 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java @@ -14,8 +14,7 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; - -import java.util.ArrayList; +import net.minecraftforge.fluids.FluidStack; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE; @@ -49,6 +48,8 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_CubicMult .addCasingInfo("Frost Proof Machine Casing", 16) .addEnergyHatch("Any casing", 1) .addMaintenanceHatch("Any casing", 1) + .addInputHatch("Any casing", 1) + .addOutputHatch("Any casing", 1) .addInputBus("Any casing", 1) .addOutputBus("Any casing", 1) .toolTipFinisher("Gregtech"); @@ -93,29 +94,29 @@ public class GT_MetaTileEntity_VacuumFreezer extends GT_MetaTileEntity_CubicMult @Override public boolean checkRecipe(ItemStack aStack) { - ArrayList<ItemStack> tInputList = getStoredInputs(); - for (ItemStack tInput : tInputList) { - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sVacuumRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], null, tInput); - if (tRecipe != null) { - if (tRecipe.isRecipeInputEqual(true, null, tInput)) { - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - - calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; - updateSlots(); - return true; + ItemStack[] tInputList = getCompactedInputs(); + FluidStack[] tFluidList = getCompactedFluids(); + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + GT_Recipe tRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluidList, tInputList); + if (tRecipe != null) { + if (tRecipe.isRecipeInputEqual(true, tFluidList, tInputList)) { + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return false; + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; + this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; + updateSlots(); + return true; } } return false; 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 337c82e67f..f51acd9a77 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.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.ItemList; @@ -38,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; @@ -47,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() { 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; + } +} diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index e173f9cfea..fba0af15df 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -72,6 +72,10 @@ GT5U.machines.voidoveflow.disabled=Overflow voiding disabled GT5U.hatch.disableFilter.true=Input Filter Off GT5U.hatch.disableFilter.false=Input Filter On +GT5U.hatch.disableSort.true=Sorting mode: OFF +GT5U.hatch.disableSort.false=Sorting mode: ON +GT5U.hatch.disableLimited.true=Limiting mode: OFF +GT5U.hatch.disableLimited.false=Limiting mode: ON GT5U.multiblock.pollution=Pollution reduced to GT5U.multiblock.energy=Stored Energy |