diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2022-09-30 16:04:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 10:04:46 +0200 |
commit | 3c7a1788d733ddf39061c6ceb6254dfc5b1ef3b8 (patch) | |
tree | 94f5a6d639a23fd171a2b1a38d67f17c5e5a97cc /src/main | |
parent | f32a9c19bd787225c06253c3ff126fc03e25580b (diff) | |
download | GT5-Unofficial-3c7a1788d733ddf39061c6ceb6254dfc5b1ef3b8.tar.gz GT5-Unofficial-3c7a1788d733ddf39061c6ceb6254dfc5b1ef3b8.tar.bz2 GT5-Unofficial-3c7a1788d733ddf39061c6ceb6254dfc5b1ef3b8.zip |
fix inconsistency between oredict recipe and naive recipe (#1423)
also unified the logic for two recipes as much as it makes sense
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_RecipeRegistrator.java | 100 |
1 files changed, 42 insertions, 58 deletions
diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java index 48f09bb71f..713380972f 100644 --- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java +++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java @@ -490,13 +490,13 @@ public class GT_RecipeRegistrator { filter.put(list, shape); } } - List<Integer> emptySlotIndexes = new ArrayList<>(9); + List<Integer> buffer = new ArrayList<>(9); for (IRecipe tRecipe : allRecipeList) { if (tRecipe instanceof ShapelessRecipes || tRecipe instanceof ShapelessOreRecipe) { // we don't target shapeless recipes continue; } - emptySlotIndexes.clear(); + buffer.clear(); ItemStack tStack = tRecipe.getRecipeOutput(); if (GT_Utility.isStackValid(tStack) && tStack.getMaxStackSize() == 1 @@ -506,68 +506,24 @@ public class GT_RecipeRegistrator { && !GT_ModHandler.isElectricItem(tStack) && !GT_Utility.isStackInList(tStack, GT_ModHandler.sNonReplaceableItems)) { if (tRecipe instanceof ShapedOreRecipe) { - boolean allValid = true; ShapedOreRecipe tShapedRecipe = (ShapedOreRecipe) tRecipe; - Object[] input = tShapedRecipe.getInput(); - int tRecipeWidth = getRecipeWidth(tShapedRecipe); - int tRecipeHeight = getRecipeHeight(tShapedRecipe); - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 3; x++) { - if (x >= tRecipeWidth || y >= tRecipeHeight) { - emptySlotIndexes.add(x + y * 3); - continue; - } - Object tObject = input[x + y * tRecipeWidth]; - if (tObject != null) { - if (tObject instanceof ItemStack - && (((ItemStack) tObject).getItem() == null - || ((ItemStack) tObject).getMaxStackSize() < 2 - || ((ItemStack) tObject).getMaxDamage() > 0 - || ((ItemStack) tObject).getItem() instanceof ItemBlock)) { - allValid = false; - break; - } - if (tObject instanceof List && ((List<?>) tObject).isEmpty()) { - allValid = false; - break; - } - } else { - emptySlotIndexes.add(x + y * 3); - } - } - } - if (allValid) { - for (RecipeShape s : filter.get(emptySlotIndexes)) { + if (checkRecipeShape( + buffer, + tShapedRecipe.getInput(), + getRecipeWidth(tShapedRecipe), + getRecipeHeight(tShapedRecipe))) { + for (RecipeShape s : filter.get(buffer)) { result.computeIfAbsent(s, k -> new ArrayList<>()).add(tRecipe); } } } else if (tRecipe instanceof ShapedRecipes) { - boolean allValid = true; ShapedRecipes tShapedRecipe = (ShapedRecipes) tRecipe; - ItemStack[] recipeItems = tShapedRecipe.recipeItems; - int tRecipeWidth = getRecipeWidth(tShapedRecipe); - int tRecipeHeight = getRecipeHeight(tShapedRecipe); - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 3; x++) { - if (x >= tRecipeWidth || y >= tRecipeHeight) { - emptySlotIndexes.add(x + y * 3); - continue; - } - ItemStack tObject = recipeItems[x + y * tRecipeWidth]; - if (tObject != null - && (tObject.getItem() == null - || tObject.getMaxStackSize() < 2 - || tObject.getMaxDamage() > 0 - || tObject.getItem() instanceof ItemBlock)) { - allValid = false; - break; - } else { - emptySlotIndexes.add(x + y * 3); - } - } - } - if (allValid) { - for (RecipeShape s : filter.get(emptySlotIndexes)) { + if (checkRecipeShape( + buffer, + tShapedRecipe.recipeItems, + getRecipeWidth(tShapedRecipe), + getRecipeHeight(tShapedRecipe))) { + for (RecipeShape s : filter.get(buffer)) { result.computeIfAbsent(s, k -> new ArrayList<>()).add(tRecipe); } } @@ -583,6 +539,34 @@ public class GT_RecipeRegistrator { return result; } + private static boolean checkRecipeShape( + List<Integer> emptySlotIndexesBuffer, Object[] input, int tRecipeWidth, int tRecipeHeight) { + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + if (x >= tRecipeWidth || y >= tRecipeHeight) { + emptySlotIndexesBuffer.add(x + y * 3); + continue; + } + Object tObject = input[x + y * tRecipeWidth]; + if (tObject == null) { + emptySlotIndexesBuffer.add(x + y * 3); + continue; + } + if (tObject instanceof ItemStack + && (((ItemStack) tObject).getItem() == null + || ((ItemStack) tObject).getMaxStackSize() < 2 + || ((ItemStack) tObject).getMaxDamage() > 0 + || ((ItemStack) tObject).getItem() instanceof ItemBlock)) { + return false; + } + if (tObject instanceof List && ((List<?>) tObject).isEmpty()) { + return false; + } + } + } + return true; + } + private static synchronized void registerStickStuff(String aPlate, ItemData aItemData, boolean aRecipeReplacing) { ItemStack tStack; for (Materials tMaterial : sRodMaterialList) { |