diff options
author | Léa Gris <lea.gris@noiraude.net> | 2021-04-27 11:22:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-27 11:22:15 +0200 |
commit | f0702f969258bd01a5fc967c44d1d4805522b17f (patch) | |
tree | fbc545124a6b3c7b0ec690b491cb0ec3372fa085 /src/main | |
parent | 037fce95062f900e4e816ad103d3f70b1ae6da2a (diff) | |
download | GT5-Unofficial-f0702f969258bd01a5fc967c44d1d4805522b17f.tar.gz GT5-Unofficial-f0702f969258bd01a5fc967c44d1d4805522b17f.tar.bz2 GT5-Unofficial-f0702f969258bd01a5fc967c44d1d4805522b17f.zip |
fix(logspam): spam unification typos (#514)
Address issue: [Gregtech.log spam with 6724 lines of "Unknown Key for Unification, Typo?" #7866](https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/7866)
- Fix the logic for logging possible Typos (prioritise least cost)
- Improve reverse recipes by excluding ore names of tools early to prevent
unexpected and un needed unification lookups
- Turn off unification typo logging in reverse recipes
Reduced unification typo spam from 6724, down to 11 remaining entries:
```none
circuitGood
circuitData
circuitElite
circuitMaster
circuitUltimate
circuitSuperconductor
gearSteel
gearAluminium
gearStainlessSteel
gearTitanium
gearTungstenSteel
```
Diffstat (limited to 'src/main')
4 files changed, 89 insertions, 18 deletions
diff --git a/src/main/java/gregtech/api/enums/ToolDictNames.java b/src/main/java/gregtech/api/enums/ToolDictNames.java index d81bbeae4e..2bb1aef1bd 100644 --- a/src/main/java/gregtech/api/enums/ToolDictNames.java +++ b/src/main/java/gregtech/api/enums/ToolDictNames.java @@ -29,4 +29,14 @@ public enum ToolDictNames { craftingToolScrewdriver, craftingToolSolderingIron, craftingToolSolderingMetal; + + public static boolean contains(String aName) { + if (!aName.startsWith("craftingTool")) return false; + for (ToolDictNames tool: ToolDictNames.values()) { + if (tool.toString().equals(aName)) { + return true; + } + } + return false; + } }
\ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java index a45e002cfa..4a5ca9070b 100644 --- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java +++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java @@ -14,10 +14,16 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import javax.annotation.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; -import static gregtech.api.enums.GT_Values.*; +import static gregtech.api.enums.GT_Values.E; +import static gregtech.api.enums.GT_Values.M; +import static gregtech.api.enums.GT_Values.W; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -102,9 +108,18 @@ public class GT_OreDictUnificator { public static ItemStack get(Object aName, ItemStack aReplacement, long aAmount, boolean aMentionPossibleTypos, boolean aNoInvalidAmounts) { if (aNoInvalidAmounts && aAmount < 1) return null; - if (!sName2StackMap.containsKey(aName.toString()) && aMentionPossibleTypos) + final ItemStack stackFromName = sName2StackMap.get(aName.toString()); + if (stackFromName != null) return GT_Utility.copyAmount(aAmount, stackFromName); + if (aMentionPossibleTypos) { GT_Log.err.println("Unknown Key for Unification, Typo? " + aName); - return GT_Utility.copyAmount(aAmount, sName2StackMap.get(aName.toString()), getFirstOre(aName, aAmount), aReplacement); + // Debug callstack of entries not in sName2StackMap + // StackTraceElement[] cause = Thread.currentThread().getStackTrace(); + // GT_Log.err.println(Arrays.toString(cause)); + + } + final ItemStack stackFirstOre = getFirstOre(aName, aAmount); + if (stackFirstOre != null) return GT_Utility.copyAmount(aAmount, stackFirstOre); + return GT_Utility.copyAmount(aAmount, aReplacement); } public static ItemStack[] setStackArray(boolean aUseBlackList, ItemStack... aStacks) { diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 9558df4608..cf2d2ad2a8 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -7,12 +7,23 @@ import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.*; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SubTag; +import gregtech.api.enums.Textures; +import gregtech.api.enums.ToolDictNames; import gregtech.api.events.BlockScanningEvent; import gregtech.api.interfaces.IDebugableBlock; import gregtech.api.interfaces.IProjectileItem; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.*; +import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.interfaces.tileentity.IUpgradableMachine; import gregtech.api.items.GT_EnergyArmor_Item; import gregtech.api.items.GT_Generic_Item; import gregtech.api.items.GT_MetaGenerated_Tool; @@ -29,7 +40,11 @@ import ic2.api.recipe.RecipeOutput; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EnumCreatureAttribute; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -65,8 +80,13 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.fluids.*; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidContainerItem; +import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; import java.lang.reflect.Constructor; @@ -75,11 +95,32 @@ import java.lang.reflect.Method; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.*; +import static gregtech.api.enums.GT_Values.D1; +import static gregtech.api.enums.GT_Values.DW; +import static gregtech.api.enums.GT_Values.E; +import static gregtech.api.enums.GT_Values.GT; +import static gregtech.api.enums.GT_Values.L; +import static gregtech.api.enums.GT_Values.M; +import static gregtech.api.enums.GT_Values.NW; +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.GT_Values.W; import static gregtech.common.GT_Proxy.GTPOLLUTION; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; @@ -2739,37 +2780,42 @@ public class GT_Utility { List<ItemStack> inputs = new ArrayList<>(); for (Map.Entry<Object, Integer> o : recipeAsMap.entrySet()) { + final int amount = o.getValue(); if (o.getKey() instanceof ItemStack) { ItemStack toAdd = ((ItemStack) o.getKey()).copy(); - toAdd.stackSize = o.getValue(); + toAdd.stackSize = amount; inputs.add(toAdd); } else if (o.getKey() instanceof String) { // System.out.println("Found OreDictEntry: "+o.getKey()); - ItemStack stack = GT_OreDictUnificator.get(o.getKey(), o.getValue()); + final String dictName = (String) o.getKey(); + // Do not register tools dictName in inputs + if (ToolDictNames.contains(dictName)) continue; + ItemStack stack = GT_OreDictUnificator.get(dictName, null, amount, false, true); if (stack == null) { - Optional<ItemStack> oStack = OreDictionary.getOres((String) o.getKey()) + Optional<ItemStack> oStack = OreDictionary.getOres(dictName) .stream() .findAny(); if (oStack.isPresent()) { ItemStack copy = oStack.get().copy(); - copy.stackSize = o.getValue(); + copy.stackSize = amount; inputs.add(copy); } // else // System.out.println("OreDict Entry "+o.getKey()+" couldn't be found!"); } else { ItemStack copy = stack.copy(); - copy.stackSize = o.getValue(); + copy.stackSize = amount; inputs.add(copy); } } else if (o.getKey() instanceof Item) - inputs.add(new ItemStack((Item) o.getKey(), o.getValue())); + inputs.add(new ItemStack((Item) o.getKey(), amount)); else if (o.getKey() instanceof Block) - inputs.add(new ItemStack((Block) o.getKey(), o.getValue())); + inputs.add(new ItemStack((Block) o.getKey(), amount)); else throw new IllegalStateException("A Recipe contains an invalid input! Output: " + output); } + // Remove tools from inputs in case a recipe has one as a direct Item or ItemStack reference inputs.removeIf(x -> x.getItem() instanceof GT_MetaGenerated_Tool); return Optional.of( diff --git a/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java b/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java index 73248fb2c7..bfb1eae59d 100644 --- a/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java +++ b/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java @@ -487,7 +487,7 @@ public class GT_MachineRecipeLoader implements Runnable { GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_IV.get(1L), GT_OreDictUnificator.get(OrePrefixes.circuit.get(Materials.Elite), 2L), GT_Utility.getIntegratedCircuit(1)}, GT_Values.NF, ItemList.FluidRegulator_IV.get(1L), 200, 7680); GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_LuV.get(1L), GT_OreDictUnificator.get(OrePrefixes.circuit.get(Materials.Master), 2L), GT_Utility.getIntegratedCircuit(1)}, GT_Values.NF, ItemList.FluidRegulator_LuV.get(1L), 150, 30720); GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_ZPM.get(1L), GT_OreDictUnificator.get(OrePrefixes.circuit.get(Materials.Ultimate), 2L), GT_Utility.getIntegratedCircuit(1)}, GT_Values.NF, ItemList.FluidRegulator_ZPM.get(1L), 100, 122880); - GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_UV.get(1L), GT_OreDictUnificator.get(OrePrefixes.circuit.get(Materials.Superconductor), 2L), GT_Utility.getIntegratedCircuit(1)}, GT_Values.NF, ItemList.FluidRegulator_UV.get(1L), 50, 500000); + GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_UV.get(1L), GT_OreDictUnificator.get(OrePrefixes.circuit.get(Materials.SuperconductorUHV), 2L), GT_Utility.getIntegratedCircuit(1)}, GT_Values.NF, ItemList.FluidRegulator_UV.get(1L), 50, 500000); GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_LV.get(1L), ItemList.Electric_Motor_LV.get(1L), GT_OreDictUnificator.get(OrePrefixes.gear.get(Materials.Steel), 2L), GT_Utility.getIntegratedCircuit(2)}, GT_Values.NF, ItemList.Steam_Valve_LV.get(1L), 400, 30); GT_Values.RA.addAssemblerRecipe(new ItemStack[]{ItemList.Electric_Pump_MV.get(1L), ItemList.Electric_Motor_MV.get(1L), GT_OreDictUnificator.get(OrePrefixes.gear.get(Materials.Aluminium), 2L), GT_Utility.getIntegratedCircuit(2)}, GT_Values.NF, ItemList.Steam_Valve_MV.get(1L), 350, 120); |