From 080e49e2bb5915c4146cbd8a56cd31e4855b5c12 Mon Sep 17 00:00:00 2001 From: slprime Date: Sat, 2 Aug 2025 22:56:03 +0300 Subject: [PATCH] Optimization --- .../nei/commands/CommandRecipeId.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/codechicken/nei/commands/CommandRecipeId.java b/src/main/java/codechicken/nei/commands/CommandRecipeId.java index 4f6cd5f7..8c482ba8 100644 --- a/src/main/java/codechicken/nei/commands/CommandRecipeId.java +++ b/src/main/java/codechicken/nei/commands/CommandRecipeId.java @@ -23,7 +23,6 @@ import net.minecraft.util.EnumChatFormatting; import org.apache.commons.io.IOUtils; -import com.google.gson.JsonObject; import com.google.gson.JsonParser; import codechicken.core.CommonUtils; @@ -34,8 +33,6 @@ import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiRecipeTab; import codechicken.nei.recipe.ICraftingHandler; import codechicken.nei.recipe.Recipe; -import codechicken.nei.recipe.Recipe.RecipeId; -import codechicken.nei.recipe.StackInfo; import codechicken.nei.util.NBTJson; public class CommandRecipeId extends CommandBase { @@ -95,12 +92,16 @@ public class CommandRecipeId extends CommandBase { for (String recipe : notAllowedRecipes) { try { - final RecipeId recipeId = RecipeId.of((JsonObject) parser.parse(recipe)); - final NBTTagCompound nbtStack = StackInfo.itemStackToNBT(recipeId.getResult(), false); - nbtStack.removeTag("Count"); + final NBTTagCompound nbtRecipe = (NBTTagCompound) NBTJson.toNbt(parser.parse(recipe)); - subsetsBuilder.computeIfAbsent(recipeId.getHandleName(), rn -> new HashSet<>()) - .add(NBTJson.toJson(nbtStack)); + if (nbtRecipe.hasKey("result")) { + final NBTTagCompound nbtStack = nbtRecipe.getCompoundTag("result"); + nbtStack.removeTag("Count"); + subsetsBuilder.computeIfAbsent(nbtRecipe.getString("handlerName"), rn -> new HashSet<>()) + .add(NBTJson.toJson(nbtStack)); + } else { + NEIClientConfig.logger.error("Found Blocken RecipeId {}", recipe); + } } catch (Exception ex) { NEIClientConfig.logger.error("Found Blocken RecipeId {}", recipe, ex); } @@ -212,7 +213,7 @@ public class CommandRecipeId extends CommandBase { } else if ("diff".equals(command)) { processDiffCommand(sender, args); } else { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + getCommandUsage(sender))); + sendChatErrorMessage(sender, getCommandUsage(sender)); } } @@ -220,28 +221,26 @@ public class CommandRecipeId extends CommandBase { protected void processDiffCommand(ICommandSender sender, String[] args) { if (args.length > 4) { - sender.addChatMessage(new ChatComponentText("Too many parameters! Usage: " + getCommandUsage(sender))); + sendChatErrorMessage(sender, "Too many parameters! Usage: " + getCommandUsage(sender)); return; } if (args.length < 3) { - sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + getCommandUsage(sender))); + sendChatErrorMessage(sender, getCommandUsage(sender)); return; } final File prevFilename = getFile(args[1]); final File currFilename = getFile(args[2]); - final File diffFilename = getFile(args.length > 3 ? args[3] : "subsets"); + final File diffFilename = getFile(args.length > 3 ? args[3] : "changelog"); if (!prevFilename.exists()) { - sender.addChatMessage( - new ChatComponentText("File `" + args[1] + "` not found! Usage: " + getCommandUsage(sender))); + sendChatErrorMessage(sender, "File `" + prevFilename.getName() + "` not found!"); return; } if (!currFilename.exists()) { - sender.addChatMessage( - new ChatComponentText("File `" + args[2] + "` not found! Usage: " + getCommandUsage(sender))); + sendChatErrorMessage(sender, "File `" + currFilename.getName() + "` not found!"); return; } @@ -249,8 +248,9 @@ public class CommandRecipeId extends CommandBase { } protected void processDumpCommand(ICommandSender sender, String[] args) { + if (args.length > 2) { - sender.addChatMessage(new ChatComponentText("Too many parameters! Usage: " + getCommandUsage(sender))); + sendChatErrorMessage(sender, "Too many parameters! Usage: " + getCommandUsage(sender)); return; } @@ -265,4 +265,8 @@ public class CommandRecipeId extends CommandBase { return new File(CommonUtils.getMinecraftDir(), "recipeid/" + filename + ".json"); } + private static void sendChatErrorMessage(ICommandSender sender, String message) { + sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + message)); + } + }