mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-15 17:54:50 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57e865fc6f | ||
|
|
6dcd26a978 | ||
|
|
aeb59081d9 | ||
|
|
ef8706ae38 |
No files matched your search
@@ -22,6 +22,59 @@ If you have issues with NEI outside of the GTNH modpack you may report them in t
|
||||
* Cycle between Recipe, Utility, and Cheat mode by ctrl clicking on the Wrench Icon
|
||||
* GT5u Tools/Items and GT6 tools should now properly work with the Overlay Recipe Transfer
|
||||
|
||||
### Information Page Handler
|
||||
Want to add some information about a block or item without making a massive tooltip for it? You can add information about any block or item by registering it in the Information Handler.
|
||||
|
||||
Information page(s) are displayed when either the uses or recipes of a matching item are searched. All matching items will cycle at the top of the information page.
|
||||
|
||||
Your mod can call:
|
||||
```java
|
||||
FMLInterModComms.sendMessage("NotEnoughItems", "addItemInfo", nbt);
|
||||
```
|
||||
Where nbt is an NBTTagCompound formatted as described below.
|
||||
|
||||
| Tag | Type | Description |
|
||||
|------------------|----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `filter` | String | A string filter to match what items should return this information page.<br/>modname:itemname, metadata, Ore Dictionary tags, and regex can all be used. The full format may be seen in `config/NEI/collapsibleitems.cfg`. |
|
||||
| `page` / `pages` | String / String NBTTagList | The actual text to display. See below for differences between single and multi-page messages.<br/>Both formats will automatically translate provided strings. |
|
||||
|
||||
#### Single Page Format
|
||||
|
||||
Use the `"page"` string tag when you only want to add one page of information:
|
||||
```java
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString("filter", "minecraft:log 3");
|
||||
tag.setString("page", "Exotic wood found in tropical climates.");
|
||||
|
||||
FMLInterModComms.sendMessage("NotEnoughItems", "addItemInfo", tag);
|
||||
```
|
||||
|
||||
#### Multiple Page Format
|
||||
|
||||
Use the `"pages"` tag as an `NBTTagList` of strings when you want more than one page:
|
||||
```java
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setString("filter", "minecraft:diamond_sword");
|
||||
|
||||
NBTTagList pages = new NBTTagList();
|
||||
pages.appendTag(new NBTTagString("A powerful melee weapon."));
|
||||
pages.appendTag(new NBTTagString("Can be enchanted for extra effects."));
|
||||
|
||||
tag.setTag("pages", pages);
|
||||
|
||||
FMLInterModComms.sendMessage("NotEnoughItems", "addItemInfo", tag);
|
||||
```
|
||||
* Each list entry is one page.
|
||||
* Pages will appear in NEI with buttons to scroll through them.
|
||||
|
||||
#### Item Matching
|
||||
|
||||
All items that match `filter` will show your information page. See `config/NEI/collapsibleitems.cfg` for the full filter format.
|
||||
|
||||
#### Item Information Config File
|
||||
|
||||
If you're a modpack creator and want to make custom item information pages, they can easily be added in `config/NEI/informationpages.cfg`, which has a few more examples.
|
||||
|
||||
## Other items of note:
|
||||
|
||||
* Remove TMI style
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
api('com.github.GTNewHorizons:CodeChickenCore:1.4.5:dev')
|
||||
implementation('com.github.GTNewHorizons:GTNHLib:0.6.38:dev')
|
||||
api('com.github.GTNewHorizons:CodeChickenCore:1.4.7:dev')
|
||||
implementation('com.github.GTNewHorizons:GTNHLib:0.6.39:dev')
|
||||
|
||||
shadowImplementation('org.apache.commons:commons-csv:1.10.0')
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ public class FavoriteRecipes {
|
||||
try (FileOutputStream output = new FileOutputStream(favoriteFile)) {
|
||||
IOUtils.writeLines(strings, "\n", output, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save favorites list to file {}", favoriteFile, e);
|
||||
NEIClientConfig.logger.error("Failed to save favorites list to file {}", favoriteFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import codechicken.nei.ThreadOperationTimer.TimeoutException;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.recipe.InformationHandler;
|
||||
import codechicken.nei.search.TooltipFilter;
|
||||
|
||||
public class ItemList {
|
||||
@@ -289,11 +290,11 @@ public class ItemList {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// For optimization it generate itemslist, permutations, orders & collapsibleitems
|
||||
// Generate itemlist, permutations, orders, collapsibleitems, and informationhandler stacks
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void execute() {
|
||||
if (!NEIClientConfig.isEnabled()) return;
|
||||
if (!NEIClientConfig.isEnabled() || NEIClientUtils.mc().thePlayer == null) return;
|
||||
|
||||
ThreadOperationTimer timer = getTimer(NEIClientConfig.getItemLoadingTimeout());
|
||||
LayoutManager.itemsLoaded = true;
|
||||
@@ -303,6 +304,7 @@ public class ItemList {
|
||||
ItemSorter.instance.ordering.clear();
|
||||
CollapsibleItems.clearCache();
|
||||
TooltipFilter.clearCache();
|
||||
InformationHandler.clearCache();
|
||||
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create();
|
||||
@@ -329,6 +331,7 @@ public class ItemList {
|
||||
|
||||
CollapsibleItems.putItem(stack);
|
||||
TooltipFilter.getSearchTooltip(stack);
|
||||
InformationHandler.populateStacks(stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ import codechicken.nei.config.preset.GuiPresetList;
|
||||
import codechicken.nei.event.NEIConfigsLoadedEvent;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.InformationHandler;
|
||||
import codechicken.nei.recipe.RecipeCatalysts;
|
||||
import codechicken.nei.recipe.RecipeInfo;
|
||||
import codechicken.nei.util.NEIKeyboardUtils;
|
||||
@@ -899,6 +900,7 @@ public class NEIClientConfig {
|
||||
LayoutManager.load();
|
||||
NEIController.load();
|
||||
BookmarkContainerInfo.load();
|
||||
InformationHandler.load();
|
||||
mainNEIConfigLoaded = true;
|
||||
|
||||
new Thread("NEI Plugin Loader") {
|
||||
@@ -921,6 +923,7 @@ public class NEIClientConfig {
|
||||
});
|
||||
|
||||
RecipeCatalysts.loadCatalystInfo();
|
||||
SubsetWidget.loadCustomSubsets();
|
||||
SubsetWidget.loadHidden();
|
||||
CollapsibleItems.load();
|
||||
ItemSorter.loadConfig();
|
||||
|
||||
@@ -20,6 +20,7 @@ import codechicken.nei.api.IInfiniteItemHandler;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.commands.CommandBookmarkAdd;
|
||||
import codechicken.nei.commands.CommandRecipeId;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.guihook.IContainerSlotClickHandler;
|
||||
@@ -66,6 +67,7 @@ public class NEIController implements IContainerSlotClickHandler, IContainerInpu
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerClientCommands() {
|
||||
ClientCommandHandler.instance.registerCommand(new CommandBookmarkAdd());
|
||||
ClientCommandHandler.instance.registerCommand(new CommandRecipeId());
|
||||
}
|
||||
|
||||
public static void updateUnlimitedItems(InventoryPlayer inventory) {
|
||||
|
||||
@@ -236,7 +236,7 @@ public class PresetsList {
|
||||
try (FileOutputStream output = new FileOutputStream(presetsFile)) {
|
||||
IOUtils.writeLines(strings, "\n", output, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save presets list to file {}", presetsFile, e);
|
||||
NEIClientConfig.logger.error("Failed to save presets list to file {}", presetsFile, e);
|
||||
}
|
||||
|
||||
recipeFilter.cache = null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -13,16 +14,20 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import codechicken.core.gui.GuiScrollSlot;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
@@ -35,6 +40,12 @@ import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
import codechicken.nei.util.NEIMouseUtils;
|
||||
|
||||
public class SubsetWidget extends Button implements ItemFilterProvider, IContainerTooltipHandler {
|
||||
@@ -535,6 +546,68 @@ public class SubsetWidget extends Button implements ItemFilterProvider, IContain
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadCustomSubsets() {
|
||||
File dir = new File(NEIClientConfig.configDir, "subsets");
|
||||
|
||||
if (!dir.exists() || !dir.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Stream.of(dir.listFiles()).filter(file -> !file.isDirectory()).forEach(file -> {
|
||||
ClientHandler.loadSettingsFile(
|
||||
"subsets/" + file.getName(),
|
||||
lines -> parseFile(file.getName(), lines.collect(Collectors.toList())));
|
||||
});
|
||||
}
|
||||
|
||||
private static void parseFile(String resource, List<String> itemStrings) {
|
||||
final JsonParser parser = new JsonParser();
|
||||
final int dotIndex = resource.lastIndexOf('.');
|
||||
final String subsetNamespace = dotIndex > 0 ? resource.substring(0, dotIndex) : resource;
|
||||
SubsetTag processedTag = new SubsetTag(subsetNamespace, new ItemStackSet());
|
||||
|
||||
for (String itemStr : itemStrings) {
|
||||
try {
|
||||
if (itemStr.startsWith("; ")) {
|
||||
addTag(processedTag);
|
||||
|
||||
final String handlerName = itemStr.substring(2);
|
||||
final IRecipeHandler recipeHandler = Stream
|
||||
.concat(
|
||||
GuiCraftingRecipe.craftinghandlers.stream(),
|
||||
GuiCraftingRecipe.serialCraftingHandlers.stream())
|
||||
.filter(handler -> handlerName.equals(getHandlerName(handler))).findFirst().orElse(null);
|
||||
String recipeName = handlerName;
|
||||
|
||||
if (recipeHandler != null) {
|
||||
recipeName = recipeHandler.getRecipeName().trim();
|
||||
}
|
||||
|
||||
processedTag = new SubsetTag(
|
||||
subsetNamespace + "." + recipeName.replace(".", ""),
|
||||
new ItemStackSet());
|
||||
} else {
|
||||
final NBTBase nbt = NBTJson.toNbt(parser.parse(itemStr));
|
||||
|
||||
if (nbt instanceof NBTTagCompound tag) {
|
||||
((ItemStackSet) processedTag.filter).add(StackInfo.loadFromNBT(tag));
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Expected NBTTagCompound but got " + nbt.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Failed to load custom subset items from json string:\n{}", itemStr);
|
||||
}
|
||||
}
|
||||
|
||||
addTag(processedTag);
|
||||
}
|
||||
|
||||
private static String getHandlerName(ICraftingHandler handler) {
|
||||
return GuiRecipeTab.getHandlerInfo(handler).getHandlerName();
|
||||
}
|
||||
|
||||
public static void loadHidden() {
|
||||
final List<ItemStack> itemList = new LinkedList<>();
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ public class BookmarkStorage {
|
||||
IOUtils.writeLines(strings, "\n", output, StandardCharsets.UTF_8);
|
||||
NEIClientConfig.world.nbt.setTag("bookmark", navigation);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", bookmarkFile, e);
|
||||
NEIClientConfig.logger.error("Failed to save bookmarks list to file {}", bookmarkFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package codechicken.nei.commands;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
@@ -12,7 +11,7 @@ import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import codechicken.nei.ItemPanels;
|
||||
|
||||
public class CommandBookmarkAdd extends CommandBase implements ICommand {
|
||||
public class CommandBookmarkAdd extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
package codechicken.nei.commands;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import codechicken.core.CommonUtils;
|
||||
import codechicken.nei.ClientHandler;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.recipe.GuiCraftingRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.Recipe;
|
||||
import codechicken.nei.recipe.RecipeHandlerQuery;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
|
||||
public class CommandRecipeId extends CommandBase {
|
||||
|
||||
protected static class ProcessDiffThread extends Thread {
|
||||
|
||||
protected final ICommandSender sender;
|
||||
protected final File prevFile;
|
||||
protected final File currFile;
|
||||
protected final File diffFile;
|
||||
|
||||
public ProcessDiffThread(ICommandSender sender, File prevFile, File currFile, File diffFile) {
|
||||
this.sender = sender;
|
||||
this.prevFile = prevFile;
|
||||
this.currFile = currFile;
|
||||
this.diffFile = diffFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sendChatInfoMessage(sender, "nei.chat.recipeid.diff.start");
|
||||
|
||||
final Set<String> prevRecipes = loadFileContent(this.prevFile);
|
||||
final Set<String> currRecipes = loadFileContent(this.currFile);
|
||||
final Set<String> notAllowedRecipes = prevRecipes.stream().filter(recipe -> !currRecipes.contains(recipe))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
final List<String> subsetsList = new ArrayList<>();
|
||||
|
||||
generateSubsets(notAllowedRecipes).forEach((handlerName, recipes) -> {
|
||||
subsetsList.add("; " + handlerName);
|
||||
subsetsList.addAll(recipes);
|
||||
});
|
||||
|
||||
saveFile(this.diffFile, subsetsList);
|
||||
saveFile(getFile("not-allowed-recipes"), new ArrayList<>(notAllowedRecipes));
|
||||
|
||||
sendChatInfoMessage(sender, "nei.chat.recipeid.diff.finish");
|
||||
}
|
||||
|
||||
private Set<String> loadFileContent(File file) {
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
return new HashSet<>(IOUtils.readLines(reader));
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to load '{}' file {}", file.getName(), file, e);
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
private Map<String, Set<String>> generateSubsets(Set<String> notAllowedRecipes) {
|
||||
final JsonParser parser = new JsonParser();
|
||||
final Map<String, Set<String>> subsetsBuilder = new TreeMap<>();
|
||||
|
||||
for (String recipeStr : notAllowedRecipes) {
|
||||
try {
|
||||
final NBTTagCompound nbtRecipe = (NBTTagCompound) NBTJson.toNbt(parser.parse(recipeStr));
|
||||
|
||||
if (nbtRecipe.hasKey("result")) {
|
||||
final NBTTagCompound nbtStack = nbtRecipe.getCompoundTag("result");
|
||||
nbtStack.removeTag("Count");
|
||||
subsetsBuilder.computeIfAbsent(nbtRecipe.getString("handlerName"), rn -> new TreeSet<>())
|
||||
.add(NBTJson.toJson(nbtStack));
|
||||
} else {
|
||||
NEIClientConfig.logger.error("Found Broken RecipeId {}", recipeStr);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
NEIClientConfig.logger.error("Found Broken RecipeId {}", recipeStr, ex);
|
||||
}
|
||||
}
|
||||
|
||||
return subsetsBuilder;
|
||||
}
|
||||
|
||||
private void saveFile(File file, List<String> content) {
|
||||
try (FileOutputStream output = new FileOutputStream(file)) {
|
||||
IOUtils.writeLines(content, "\n", output, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Failed to save recipeid diff list to file {}", file, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class ProcessDumpThread extends Thread {
|
||||
|
||||
private ArrayList<ICraftingHandler> craftinghandlers = new ArrayList<>();
|
||||
private ArrayList<ICraftingHandler> serialCraftingHandlers = new ArrayList<>();
|
||||
protected final ICommandSender sender;
|
||||
protected final File currFile;
|
||||
|
||||
public ProcessDumpThread(ICommandSender sender, File currFile) {
|
||||
this.sender = sender;
|
||||
this.currFile = currFile;
|
||||
ClientHandler.loadSettingsFile("recipeidblacklist.cfg", lines -> {
|
||||
final Set<String> names = lines.collect(Collectors.toSet());
|
||||
|
||||
this.craftinghandlers = GuiCraftingRecipe.craftinghandlers.stream()
|
||||
.filter(h -> !names.contains(GuiRecipeTab.getHandlerInfo(h).getHandlerName()))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
this.serialCraftingHandlers = GuiCraftingRecipe.serialCraftingHandlers.stream()
|
||||
.filter(h -> !names.contains(GuiRecipeTab.getHandlerInfo(h).getHandlerName()))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NEIClientConfig.logger.info("Start processing recipe handlers!");
|
||||
sendChatInfoMessage(sender, "nei.chat.recipeid.dump.start");
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(currFile.toPath(), StandardCharsets.UTF_8)) {
|
||||
int total = ItemList.items.size();
|
||||
int count = 0;
|
||||
|
||||
for (ItemStack stack : ItemList.items) {
|
||||
|
||||
if (count % 1000 == 0) {
|
||||
NEIClientConfig.logger.info(
|
||||
"({}/{}). Processing {} crafting recipes...",
|
||||
count,
|
||||
total,
|
||||
stack.getDisplayName());
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
for (ICraftingHandler handler : getCraftingHandlers(stack)) {
|
||||
for (int index = 0, num = handler.numRecipes(); index < num; index++) {
|
||||
try {
|
||||
final Recipe recipe = Recipe.of(handler, index);
|
||||
if (!recipe.getIngredients().isEmpty() && !recipe.getResults().isEmpty()) {
|
||||
writer.write(NBTJson.toJson(recipe.getRecipeId().toJsonObject()));
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
NEIClientConfig.logger.error(
|
||||
"Found Broken RecipeId {}:{}",
|
||||
GuiRecipeTab.getHandlerInfo(handler).getHandlerName(),
|
||||
stack,
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Error dumping RecipeId", e);
|
||||
}
|
||||
|
||||
NEIClientConfig.logger.info("Finished processing recipe handlers!");
|
||||
sendChatInfoMessage(sender, "nei.chat.recipeid.dump.finish");
|
||||
}
|
||||
|
||||
private ArrayList<ICraftingHandler> getCraftingHandlers(Object... results) {
|
||||
return new RecipeHandlerQuery<>(
|
||||
h -> h.getRecipeHandler("item", results),
|
||||
this.craftinghandlers,
|
||||
this.serialCraftingHandlers,
|
||||
"Error while looking up crafting recipe",
|
||||
"outputId: item",
|
||||
"results: " + Arrays.toString(results))
|
||||
.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.crafting"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "recipeid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/recipeid dump <filename> OR /recipeid diff <prev-filename> <curr-filename> [subset name]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
final String command = args.length == 0 ? null : args[0];
|
||||
|
||||
if ("dump".equals(command)) {
|
||||
processDumpCommand(sender, args);
|
||||
} else if ("diff".equals(command)) {
|
||||
processDiffCommand(sender, args);
|
||||
} else {
|
||||
sendChatErrorMessage(sender, getCommandUsage(sender));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void processDiffCommand(ICommandSender sender, String[] args) {
|
||||
|
||||
if (args.length > 4) {
|
||||
sendChatErrorMessage(sender, "nei.chat.recipeid.many_params", getCommandUsage(sender));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
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] : "changelog");
|
||||
|
||||
if (!prevFilename.exists()) {
|
||||
sendChatErrorMessage(sender, "nei.chat.recipeid.not_found", prevFilename.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currFilename.exists()) {
|
||||
sendChatErrorMessage(sender, "nei.chat.recipeid.not_found", currFilename.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
(new ProcessDiffThread(sender, prevFilename, currFilename, diffFilename)).start();
|
||||
}
|
||||
|
||||
protected void processDumpCommand(ICommandSender sender, String[] args) {
|
||||
|
||||
if (args.length > 2) {
|
||||
sendChatErrorMessage(sender, "nei.chat.recipeid.many_params", getCommandUsage(sender));
|
||||
return;
|
||||
}
|
||||
|
||||
final File dir = new File(CommonUtils.getMinecraftDir(), "recipeid");
|
||||
final String currFilename = args.length == 2 ? args[1] : "recipeId";
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
|
||||
(new ProcessDumpThread(sender, getFile(currFilename))).start();
|
||||
}
|
||||
|
||||
private static File getFile(String filename) {
|
||||
return new File(CommonUtils.getMinecraftDir(), "recipeid/" + filename + ".json");
|
||||
}
|
||||
|
||||
private static void sendChatInfoMessage(ICommandSender sender, String translationKey, Object... args) {
|
||||
sender.addChatMessage(
|
||||
new ChatComponentTranslation(translationKey, args)
|
||||
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.AQUA)));
|
||||
}
|
||||
|
||||
private static void sendChatErrorMessage(ICommandSender sender, String translationKey, Object... args) {
|
||||
sender.addChatMessage(
|
||||
new ChatComponentTranslation(translationKey, args)
|
||||
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class HandlerDumper extends DataDumper {
|
||||
}
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
NEIClientConfig.logger.error("Filed to save dump handler list to file {}", file, e);
|
||||
NEIClientConfig.logger.error("Failed to save dump handler list to file {}", file, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package codechicken.nei.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import codechicken.core.CommonUtils;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
@@ -15,6 +15,7 @@ import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.recipe.CatalystInfo;
|
||||
import codechicken.nei.recipe.GuiRecipeTab;
|
||||
import codechicken.nei.recipe.HandlerInfo;
|
||||
import codechicken.nei.recipe.InformationHandler;
|
||||
import codechicken.nei.recipe.RecipeCatalysts;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
@@ -33,18 +34,11 @@ public class IMCHandler {
|
||||
if (type == null || type.isEmpty()) continue;
|
||||
if (CommonUtils.isClient()) {
|
||||
switch (type) {
|
||||
case "registerHandlerInfo":
|
||||
handleRegisterHandlerInfo(message);
|
||||
break;
|
||||
case "removeHandlerInfo":
|
||||
handleRemoveHandlerInfo(message);
|
||||
break;
|
||||
case "registerCatalystInfo":
|
||||
handleRegisterCatalystInfo(message);
|
||||
break;
|
||||
case "removeCatalystInfo":
|
||||
handleRemoveCatalystInfo(message);
|
||||
break;
|
||||
case "registerHandlerInfo" -> handleRegisterHandlerInfo(message);
|
||||
case "removeHandlerInfo" -> handleRemoveHandlerInfo(message);
|
||||
case "registerCatalystInfo" -> handleRegisterCatalystInfo(message);
|
||||
case "removeCatalystInfo" -> handleRemoveCatalystInfo(message);
|
||||
case "addItemInfo" -> handleAddItemInfo(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +51,7 @@ public class IMCHandler {
|
||||
}
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
final String handler = tag.getString("handler");
|
||||
NEIClientConfig.logger.info("Processing registerHandlerInfo `" + handler + "` from " + message.getSender());
|
||||
NEIClientConfig.logger.info("Processing registerHandlerInfo `{}` from {}", handler, message.getSender());
|
||||
|
||||
final String modName = tag.getString("modName");
|
||||
final String modId = tag.getString("modId");
|
||||
@@ -100,7 +94,7 @@ public class IMCHandler {
|
||||
: HandlerInfo.DEFAULT_MAX_PER_PAGE;
|
||||
info.setHandlerDimensions(imageHeight, imageWidth, maxRecipesPerPage);
|
||||
} catch (NumberFormatException ignored) {
|
||||
NEIClientConfig.logger.info("Error setting handler dimensions for " + handler);
|
||||
NEIClientConfig.logger.info("Error setting handler dimensions for {}", handler);
|
||||
}
|
||||
|
||||
// true if not set to false
|
||||
@@ -118,7 +112,7 @@ public class IMCHandler {
|
||||
}
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
final String handler = tag.getString("handler");
|
||||
NEIClientConfig.logger.info("Processing removeHandlerInfo `" + handler + "` from " + message.getSender());
|
||||
NEIClientConfig.logger.info("Processing removeHandlerInfo `{}` from {}", handler, message.getSender());
|
||||
|
||||
GuiRecipeTab.handlerRemoverFromIMC.add(handler);
|
||||
}
|
||||
@@ -130,7 +124,7 @@ public class IMCHandler {
|
||||
}
|
||||
|
||||
if (!processedCatalystSenders.contains(message.getSender())) {
|
||||
NEIClientConfig.logger.info("Processing registerCatalystInfo from " + message.getSender());
|
||||
NEIClientConfig.logger.info("Processing registerCatalystInfo from {}", message.getSender());
|
||||
processedCatalystSenders.add(message.getSender());
|
||||
}
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
@@ -139,23 +133,14 @@ public class IMCHandler {
|
||||
NEIClientConfig.logger.warn("Missing handlerID for registerCatalystInfo!");
|
||||
return;
|
||||
}
|
||||
final String itemName = tag.getString("itemName");
|
||||
final String nbtInfo = tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null;
|
||||
if (itemName.isEmpty()) {
|
||||
NEIClientConfig.logger.warn(String.format("Missing itemName for registerCatalystInfo in `%s`!", handlerID));
|
||||
return;
|
||||
}
|
||||
final ItemStack itemStack = NEIServerUtils.getModdedItem(itemName, nbtInfo);
|
||||
final ItemStack itemStack = getItemStackFromIMC(message, "registerCatalystInfo");
|
||||
if (itemStack == null) {
|
||||
NEIClientConfig.logger.warn(String.format("Cannot find item `%s`!", itemName));
|
||||
return;
|
||||
}
|
||||
final int priority = tag.getInteger("priority");
|
||||
|
||||
RecipeCatalysts
|
||||
.addOrPut(RecipeCatalysts.catalystsAdderFromIMC, handlerID, new CatalystInfo(itemStack, priority));
|
||||
NEIClientConfig.logger
|
||||
.info(String.format("Added catalyst `%s` to handler %s", itemStack.getDisplayName(), handlerID));
|
||||
NEIClientConfig.logger.info("Added catalyst `{}` to handler {}", itemStack.getDisplayName(), handlerID);
|
||||
}
|
||||
|
||||
private static void handleRemoveCatalystInfo(IMCMessage message) {
|
||||
@@ -164,33 +149,62 @@ public class IMCHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
NEIClientConfig.logger.info("Processing removeCatalystInfo from " + message.getSender());
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
final String handlerID = tag.getString("handlerID");
|
||||
if (handlerID.isEmpty()) {
|
||||
NEIClientConfig.logger.warn("Missing handlerID for registerCatalystInfo!");
|
||||
NEIClientConfig.logger.warn("Missing handlerID for removeCatalystInfo!");
|
||||
return;
|
||||
}
|
||||
final String itemName = tag.getString("itemName");
|
||||
final String nbtInfo = tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null;
|
||||
if (itemName.isEmpty()) {
|
||||
NEIClientConfig.logger.warn(String.format("Missing itemName for registerCatalystInfo in `%s`!", handlerID));
|
||||
return;
|
||||
}
|
||||
final ItemStack itemStack = NEIServerUtils.getModdedItem(itemName, nbtInfo);
|
||||
final ItemStack itemStack = getItemStackFromIMC(message, "removeCatalystInfo");
|
||||
if (itemStack == null) {
|
||||
NEIClientConfig.logger.warn(String.format("Cannot find item `%s`!", itemName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (RecipeCatalysts.catalystsRemoverFromIMC.containsKey(handlerID)) {
|
||||
RecipeCatalysts.catalystsRemoverFromIMC.get(handlerID).add(itemStack);
|
||||
} else {
|
||||
RecipeCatalysts.catalystsRemoverFromIMC
|
||||
.put(handlerID, new ArrayList<>(Collections.singletonList(itemStack)));
|
||||
RecipeCatalysts.catalystsRemoverFromIMC.computeIfAbsent(handlerID, k -> new ArrayList<>()).add(itemStack);
|
||||
NEIClientConfig.logger.info("Removed catalyst `{}` from handler {}", itemStack.getDisplayName(), handlerID);
|
||||
}
|
||||
|
||||
private static void handleAddItemInfo(IMCMessage message) {
|
||||
if (!message.isNBTMessage()) {
|
||||
logInvalidMessage(message, "NBT");
|
||||
return;
|
||||
}
|
||||
NEIClientConfig.logger
|
||||
.info(String.format("Removed catalyst `%s` from handler %s", itemStack.getDisplayName(), handlerID));
|
||||
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
if (tag.hasKey("pages")) addMultipleInfoPages(message);
|
||||
if (tag.hasKey("page")) addSingleInfoPage(message);
|
||||
}
|
||||
|
||||
private static void addMultipleInfoPages(IMCMessage message) {
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
final String filter = tag.getString("filter");
|
||||
final NBTTagList pages = tag.getTagList("pages", 8); // 8 = TAG_String
|
||||
for (int i = 0; i < pages.tagCount(); i++) {
|
||||
String page = pages.getStringTagAt(i);
|
||||
InformationHandler.addInformationPage(filter, page);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addSingleInfoPage(IMCMessage message) {
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
String filter = tag.getString("filter");
|
||||
String page = tag.getString("page");
|
||||
InformationHandler.addInformationPage(filter, page);
|
||||
}
|
||||
|
||||
private static ItemStack getItemStackFromIMC(IMCMessage message, String logAction) {
|
||||
final NBTTagCompound tag = message.getNBTValue();
|
||||
final String itemName = tag.getString("itemName");
|
||||
final String nbtInfo = tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null;
|
||||
|
||||
NEIClientConfig.logger.info("Processing {} for item `{}` from {}", logAction, itemName, message.getSender());
|
||||
final ItemStack itemStack = NEIServerUtils.getModdedItem(itemName, nbtInfo);
|
||||
|
||||
if (itemStack == null) {
|
||||
NEIClientConfig.logger.warn("Cannot find item `{}`!", itemName);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private static void logInvalidMessage(FMLInterModComms.IMCMessage message, String type) {
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import codechicken.nei.ClientHandler;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.util.ItemStackFilterParser;
|
||||
|
||||
public class InformationHandler extends TemplateRecipeHandler {
|
||||
|
||||
private static final List<InformationPage> ITEM_INFO = new ArrayList<>();
|
||||
|
||||
public static void addInformationPage(String filter, String description) {
|
||||
if (filter.isEmpty() || description.isEmpty()) return;
|
||||
ITEM_INFO.add(new InformationPage(filter, description));
|
||||
}
|
||||
|
||||
public static void populateStacks(ItemStack stack) {
|
||||
for (InformationPage page : ITEM_INFO) {
|
||||
page.addItem(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawExtras(int recipe) {
|
||||
CachedInfoPage page = (CachedInfoPage) this.arecipes.get(recipe);
|
||||
drawWrappedText(StatCollector.translateToLocal(page.getPage().info).replace("\\n", "\n"), 4, 24);
|
||||
}
|
||||
|
||||
private void drawWrappedText(String text, int x, int y) {
|
||||
FontRenderer font = Minecraft.getMinecraft().fontRenderer;
|
||||
List<String> lines = font.listFormattedStringToWidth(text, 156);
|
||||
for (String line : lines) {
|
||||
font.drawString(line, x, y, 0);
|
||||
y += 10;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
for (InformationPage page : ITEM_INFO) {
|
||||
page.items.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName() {
|
||||
return NEIClientUtils.translate("recipe.information");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOverlayIdentifier() {
|
||||
return "information";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result) {
|
||||
for (InformationPage page : ITEM_INFO) {
|
||||
if (page.filter.matches(result)) {
|
||||
arecipes.add(new CachedInfoPage(page));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUsageRecipes(ItemStack ingredient) {
|
||||
loadCraftingRecipes(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTexture() {
|
||||
return "nei:textures/gui/recipebg.png";
|
||||
}
|
||||
|
||||
private class CachedInfoPage extends CachedRecipe {
|
||||
|
||||
private final InformationPage page;
|
||||
private final PositionedStack stack;
|
||||
|
||||
public CachedInfoPage(InformationPage page) {
|
||||
this.page = page;
|
||||
stack = new PositionedStack(page.items, 75, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResult() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getIngredients() {
|
||||
return getCycledIngredients(cycleticks / 20, Collections.singletonList(this.stack));
|
||||
}
|
||||
|
||||
public InformationPage getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InformationPage {
|
||||
|
||||
final List<ItemStack> items = new ArrayList<>();
|
||||
final String info;
|
||||
final ItemFilter filter;
|
||||
|
||||
public InformationPage(String filter, String info) {
|
||||
this.filter = ItemStackFilterParser.parse(filter.trim());
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the item stack if it matches the filter.
|
||||
*/
|
||||
public void addItem(ItemStack stack) {
|
||||
if (filter.matches(stack)) items.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
ClientHandler.loadSettingsFile(
|
||||
"informationpages.cfg",
|
||||
lines -> parseFile(lines.collect(Collectors.toCollection(ArrayList::new))));
|
||||
}
|
||||
|
||||
private static void parseFile(List<String> lines) {
|
||||
for (String rawLine : lines) {
|
||||
String line = rawLine.trim();
|
||||
|
||||
int sepIndex = line.indexOf('=');
|
||||
if (sepIndex == -1) {
|
||||
NEIClientConfig.logger.warn("[NEI Info] Invalid line (no '=') in config: {}", line);
|
||||
continue;
|
||||
}
|
||||
|
||||
String filter = line.substring(0, sepIndex).trim();
|
||||
String description = line.substring(sepIndex + 1).trim();
|
||||
addInformationPage(filter, description);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,12 @@ package codechicken.nei.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
@@ -36,10 +39,15 @@ public class Recipe {
|
||||
this.result = result != null ? StackInfo.withAmount(result, 0) : null;
|
||||
this.handlerName = handlerName;
|
||||
this.ingredients = ingredients;
|
||||
|
||||
if (!isShapedRecipe()) {
|
||||
// sort to ignore ingredients position in shapeless recipes
|
||||
this.ingredients.sort(Comparator.comparing(StackInfo::getItemStackGUID));
|
||||
}
|
||||
}
|
||||
|
||||
public static RecipeId of(Object result, String handlerName, Iterable<?> ingredients) {
|
||||
return new RecipeId(extractItem(result), handlerName, extractItems(ingredients));
|
||||
return new RecipeId(extractItem(result), handlerName, extractIngredients(ingredients));
|
||||
}
|
||||
|
||||
public static RecipeId of(JsonObject json) {
|
||||
@@ -74,14 +82,14 @@ public class Recipe {
|
||||
return new ArrayList<>(this.ingredients);
|
||||
}
|
||||
|
||||
protected static List<ItemStack> extractItems(Iterable<?> items) {
|
||||
protected static List<ItemStack> extractIngredients(Iterable<?> items) {
|
||||
final List<ItemStack> list = new ArrayList<>();
|
||||
|
||||
for (Object item : items) {
|
||||
ItemStack stack = extractItem(item);
|
||||
final ItemStack stack = extractItem(item);
|
||||
|
||||
if (stack != null) {
|
||||
list.add(stack.copy());
|
||||
list.add(prepareIngredient(stack.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,15 +123,56 @@ public class Recipe {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int index = 0; index < stacks.size(); index++) {
|
||||
if (!stacks.get(index).containsWithNBT(ingredients.get(index))) {
|
||||
return false;
|
||||
if (isShapedRecipe()) {
|
||||
for (int index = 0; index < stacks.size(); index++) {
|
||||
if (!containsWithNBT(stacks.get(index), Collections.singletonList(this.ingredients.get(index)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (!containsWithNBT(pStack, this.ingredients)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean containsWithNBT(PositionedStack pStack, List<ItemStack> ingrStacks) {
|
||||
for (ItemStack item : pStack.items) {
|
||||
final ItemStack pItem = prepareIngredient(item);
|
||||
if (ingrStacks.stream().anyMatch(stack -> StackInfo.equalItemAndNBT(pItem, stack, true))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ItemStack prepareIngredient(ItemStack stack) {
|
||||
|
||||
// hack: remove metadata for "Data Stick"
|
||||
if (stack.hasTagCompound() && stack.getItemDamage() == 32708
|
||||
&& "gregtech:gt.metaitem.01".equals(Item.itemRegistry.getNameForObject(stack.getItem()))) {
|
||||
return new ItemStack(stack.getItem(), stack.getItemDamage());
|
||||
}
|
||||
|
||||
// hack: remove metadata for "Circuit Imprint"
|
||||
if (stack.hasTagCompound() && stack.getItemDamage() == 0
|
||||
&& "bartworks:gt.bwMetaGeneratedItem0"
|
||||
.equals(Item.itemRegistry.getNameForObject(stack.getItem()))) {
|
||||
return new ItemStack(stack.getItem(), stack.getItemDamage());
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public boolean isShapedRecipe() {
|
||||
return this.handlerName.equals("codechicken.nei.recipe.ShapedRecipeHandler")
|
||||
|| this.handlerName.equals("fox.spiteful.avaritia.compat.nei.ExtremeShapedRecipeHandler");
|
||||
}
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
final JsonObject json = new JsonObject();
|
||||
|
||||
@@ -142,8 +191,8 @@ public class Recipe {
|
||||
protected JsonArray convertItemsToJsonArray(List<ItemStack> items) {
|
||||
final JsonArray arr = new JsonArray();
|
||||
|
||||
for (ItemStack nbTag : items) {
|
||||
arr.add(NBTJson.toJsonObject(StackInfo.itemStackToNBT(nbTag)));
|
||||
for (ItemStack stack : items) {
|
||||
arr.add(NBTJson.toJsonObject(StackInfo.itemStackToNBT(stack)));
|
||||
}
|
||||
|
||||
return arr;
|
||||
|
||||
@@ -17,7 +17,7 @@ import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.util.AsyncTaskProfiler;
|
||||
|
||||
class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
public class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
|
||||
private final Function<T, T> recipeHandlerFunction;
|
||||
private final List<T> recipeHandlers;
|
||||
@@ -25,15 +25,15 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
|
||||
private final String[] errorMessage;
|
||||
private boolean error = false;
|
||||
|
||||
RecipeHandlerQuery(Function<T, T> recipeHandlerFunction, List<T> recipeHandlers, List<T> serialRecipeHandlers,
|
||||
String... errorMessage) {
|
||||
public RecipeHandlerQuery(Function<T, T> recipeHandlerFunction, List<T> recipeHandlers,
|
||||
List<T> serialRecipeHandlers, String... errorMessage) {
|
||||
this.recipeHandlerFunction = recipeHandlerFunction;
|
||||
this.recipeHandlers = recipeHandlers;
|
||||
this.serialRecipeHandlers = serialRecipeHandlers;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
ArrayList<T> runWithProfiling(String profilerSection) {
|
||||
public ArrayList<T> runWithProfiling(String profilerSection) {
|
||||
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
|
||||
|
||||
// Save the current config state here, as it may be altered
|
||||
|
||||
@@ -101,6 +101,8 @@ public class RecipeInfo {
|
||||
API.registerUsageHandler(new BrewingRecipeHandler());
|
||||
API.registerRecipeHandler(new FuelRecipeHandler());
|
||||
API.registerUsageHandler(new FuelRecipeHandler());
|
||||
API.registerRecipeHandler(new InformationHandler());
|
||||
API.registerUsageHandler(new InformationHandler());
|
||||
|
||||
API.registerGuiOverlay(GuiCrafting.class, "crafting");
|
||||
API.registerGuiOverlay(GuiInventory.class, "crafting2x2", 63, 20);
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -22,6 +23,7 @@ import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
import codechicken.nei.util.ItemStackKey;
|
||||
import codechicken.nei.util.NBTHelper;
|
||||
|
||||
public class StackInfo {
|
||||
|
||||
@@ -144,7 +146,7 @@ public class StackInfo {
|
||||
final NBTTagCompound nbTag = itemStackToNBT(stack, false);
|
||||
|
||||
if (nbTag == null) {
|
||||
return null;
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
nbTag.removeTag("Count");
|
||||
@@ -157,9 +159,11 @@ public class StackInfo {
|
||||
nbTag.removeTag("tag");
|
||||
}
|
||||
|
||||
if (nbTag.hasKey("strId") && guidfilters.containsKey(nbTag.getString("strId"))) {
|
||||
if (nbTag.hasKey("strId") && (guidfilters.containsKey(nbTag.getString("strId"))
|
||||
|| guidfilters.containsKey(nbTag.getString("strId") + "&" + nbTag.getShort("Damage")))) {
|
||||
final String strId = nbTag.getString("strId")
|
||||
+ (guidfilters.containsKey(nbTag.getString("strId")) ? "" : "&" + nbTag.getShort("Damage"));
|
||||
final ArrayList<String> keys = new ArrayList<>();
|
||||
final String strId = nbTag.getString("strId");
|
||||
|
||||
keys.add(strId);
|
||||
|
||||
@@ -184,7 +188,7 @@ public class StackInfo {
|
||||
}
|
||||
|
||||
if (local instanceof NBTBase item) {
|
||||
keys.add(item.toString());
|
||||
keys.add(NBTHelper.toString(item));
|
||||
} else if (local != null) {
|
||||
keys.add(String.valueOf(local));
|
||||
}
|
||||
@@ -195,7 +199,7 @@ public class StackInfo {
|
||||
}
|
||||
} else {
|
||||
synchronized (guidcache) {
|
||||
guidcache.put(stack, nbTag.toString());
|
||||
guidcache.put(stack, NBTHelper.toString(nbTag));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,13 +222,17 @@ public class StackInfo {
|
||||
}
|
||||
|
||||
public static ItemStack getItemStackWithMinimumDamage(ItemStack[] stacks) {
|
||||
int damage = Short.MAX_VALUE;
|
||||
ItemStack result = stacks[0];
|
||||
|
||||
if (stacks.length > 1) {
|
||||
for (ItemStack stack : stacks) {
|
||||
if (stack.getItem() != null && !ItemInfo.isHidden(stack) && stack.getItemDamage() < damage) {
|
||||
damage = stack.getItemDamage();
|
||||
// to optimize compare recipes from permutation, an item with a minimum strId and damage is taken so as
|
||||
// not to check everything permutation items
|
||||
if (stack.getItem() != null && !ItemInfo.isHidden(stack)
|
||||
&& (stack.getItemDamage() < result.getItemDamage()
|
||||
|| stack.getItemDamage() == result.getItemDamage()
|
||||
&& Item.itemRegistry.getNameForObject(stack.getItem())
|
||||
.compareTo(Item.itemRegistry.getNameForObject(result.getItem())) < 0)) {
|
||||
result = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package codechicken.nei.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
@@ -52,4 +56,26 @@ public class NBTHelper {
|
||||
private static NBTBase get(NBTTagList tag, int idx) {
|
||||
return idx >= 0 && idx < tag.tagList.size() ? (NBTBase) tag.tagList.get(idx) : null;
|
||||
}
|
||||
|
||||
public static String toString(NBTBase nbt) {
|
||||
|
||||
if (nbt instanceof NBTTagCompound nbtTagCompound) {
|
||||
final Map<String, NBTBase> tagMap = (Map<String, NBTBase>) nbtTagCompound.tagMap;
|
||||
return "{" + tagMap.entrySet().stream().sorted(Map.Entry.<String, NBTBase>comparingByKey())
|
||||
.map(nbtEntry -> nbtEntry.getKey() + ":" + toString(nbtEntry.getValue()))
|
||||
.collect(Collectors.joining(",")) + "}";
|
||||
} else if (nbt instanceof NBTTagList list) {
|
||||
|
||||
if (list.tagList.isEmpty()) {
|
||||
return "[]";
|
||||
} else {
|
||||
final StringJoiner arr = new StringJoiner(",");
|
||||
list.tagList.forEach(c -> arr.add(toString((NBTBase) c)));
|
||||
return "[" + arr.toString() + "]";
|
||||
}
|
||||
|
||||
} else {
|
||||
return nbt.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,12 +43,10 @@ public class NBTJson {
|
||||
// NBTTagCompound
|
||||
final NBTTagCompound nbtTagCompound = (NBTTagCompound) nbt;
|
||||
final Map<String, NBTBase> tagMap = (Map<String, NBTBase>) nbtTagCompound.tagMap;
|
||||
final JsonObject root = new JsonObject();
|
||||
|
||||
JsonObject root = new JsonObject();
|
||||
|
||||
for (Map.Entry<String, NBTBase> nbtEntry : tagMap.entrySet()) {
|
||||
root.add(nbtEntry.getKey(), toJsonObject(nbtEntry.getValue()));
|
||||
}
|
||||
tagMap.entrySet().stream().sorted(Map.Entry.<String, NBTBase>comparingByKey())
|
||||
.forEach(nbtEntry -> { root.add(nbtEntry.getKey(), toJsonObject(nbtEntry.getValue())); });
|
||||
|
||||
return root;
|
||||
} else if (nbt instanceof NBTTagByte) {
|
||||
|
||||
@@ -54,4 +54,5 @@ miscutils:personalHealingDevice
|
||||
tectech:item.em.debugContainer,tag.symbols
|
||||
tinkersdefense:Heater Shield,tag.InfiTool
|
||||
tinkersdefense:Round Shield,tag.InfiTool
|
||||
miscutils:itemCustomMetaCover.miscutils.GtMachineCasings,Damage
|
||||
miscutils:itemCustomMetaCover.miscutils.GtMachineCasings,Damage
|
||||
gregtech:gt.metaitem.01&32708,tag.output
|
||||
@@ -1,18 +1,6 @@
|
||||
# Hidden Items Filters
|
||||
#
|
||||
# parts:
|
||||
# modname:itemid - identify
|
||||
# $orename - ore dictionary
|
||||
# tag.color=red - tag
|
||||
# 0 or 0-12 - damage
|
||||
#
|
||||
# modifiers:
|
||||
# ! - logical not. exclude items that match the following expression (!minecraft:portal)
|
||||
# r/.../ - standard java regex (r/^m\w{6}ft$/ = minecraft)
|
||||
# , - logical or in token (minecraft:potion 16384-16462,!16386)
|
||||
# | - logical or multi-item search (wrench|hammer)
|
||||
#
|
||||
# example: minecraft:potion 16384-16462,!16386 | $oreiron | tag.color=red
|
||||
# Uses the same filter format at collapsibleitems.cfg
|
||||
#
|
||||
minecraft:portal
|
||||
minecraft:end_portal
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# NEI Item Information Config
|
||||
#
|
||||
# One page per line, in the format:
|
||||
# filter = description text
|
||||
#
|
||||
# The filter uses the same format as collapsibleitems.cfg.
|
||||
#
|
||||
# You can repeat the same filter on multiple lines to add extra pages.
|
||||
# Use \n to insert line breaks inside the description. Use it multiple times for a larger gap between lines.
|
||||
# Using a translation key for the description will automatically translate it.
|
||||
# Only the first '=' after the filter is treated as the separator; feel free to put them in your descriptions.
|
||||
# Spaces before and after '=' are removed from the description and are optional.
|
||||
# The same item can match filters for multiple pages, unlike collapsibleitems.cfg only putting them in the first matching group.
|
||||
#
|
||||
# Empty lines and lines starting with # are ignored.
|
||||
#
|
||||
# Examples:
|
||||
# # Jungle Wood (meta 3)
|
||||
# minecraft:log 3 = Exotic wood found in tropical climates.
|
||||
#
|
||||
# # Diamond Sword (two pages of information)
|
||||
# minecraft:diamond_sword = A powerful melee weapon. Does 8 damage total.
|
||||
# minecraft:diamond_sword = Can be enchanted for extra effects.
|
||||
#
|
||||
# # Two different ore dictionary tags. Iron ingots match both.
|
||||
# $iron = Iron is a very versatile material. It can be found below sea level in the Overworld.
|
||||
# $ingot = Ingots are the refined form of metal or clay.
|
||||
#
|
||||
@@ -0,0 +1,3 @@
|
||||
# Each line in this file should either be a comment (line starts with '#'), handler name or handler id.
|
||||
# If you delete this file, it will be regenerated with the default handlers list.
|
||||
Unknown
|
||||
@@ -5,6 +5,7 @@ codechicken.nei.recipe.FurnaceRecipeHandler,Minecraft,minecraft:furnace,,minecra
|
||||
codechicken.nei.recipe.ShapedRecipeHandler,Minecraft,minecraft:crafting_table,,minecraft,FALSE,,,65,166,5,,,,,,
|
||||
codechicken.nei.recipe.ShapelessRecipeHandler,Minecraft,minecraft:crafting_table,,minecraft,FALSE,,,65,166,5,,,,,,
|
||||
codechicken.nei.recipe.FuelRecipeHandler,Minecraft,,,minecraft,FALSE,,,65,166,5,nei:textures/nei_tabbed_sprites.png,80,0,14,14,
|
||||
codechicken.nei.recipe.InformationHandler,Not Enough Items,,,nei,FALSE,,,65,166,1,nei:textures/nei_tabbed_sprites.png,96,0,16,16,
|
||||
advsolar.client.nei.MTRecipeHandler,Advanced Solar Panels,AdvancedSolarPanel:BlockMolecularTransformer,,AdvancedSolarPanel,TRUE,,,68,,5,,,,,,
|
||||
appeng.integration.modules.NEIHelpers.NEIAEShapedRecipeHandler,Applied Energistics 2,appliedenergistics2:item.ItemMultiPart:380,,appliedenergistics2,TRUE,,,65,,5,,,,,,
|
||||
appeng.integration.modules.NEIHelpers.NEIAEShapelessRecipeHandler,Applied Energistics 2,appliedenergistics2:item.ItemMultiPart:380,,appliedenergistics2,TRUE,,,65,,5,,,,,,
|
||||
|
||||
|
@@ -138,6 +138,13 @@ nei.chat.chunkoverlay.3=Chunk Overlay: GT Ore Veins
|
||||
nei.chat.item_link.text=<%s> §6Click to add bookmark: %s
|
||||
nei.chat.bookmark_added.text=Bookmark added!
|
||||
|
||||
nei.chat.recipeid.many_params=Too many parameters! Usage: %s
|
||||
nei.chat.recipeid.not_found=File %s not found!
|
||||
nei.chat.recipeid.diff.start=Start processing recipe diff!
|
||||
nei.chat.recipeid.diff.finish=Finished processing recipe diff!
|
||||
nei.chat.recipeid.dump.start=Start processing recipe handlers!
|
||||
nei.chat.recipeid.dump.finish=Finished processing recipe handlers!
|
||||
|
||||
nei.options=NEI Options
|
||||
nei.options.back=Back
|
||||
nei.options.save=Save
|
||||
@@ -513,6 +520,8 @@ nei.recipe.favorite=Favorite
|
||||
nei.recipe.favorite.bookmark_recipe=Save Recipe Tree
|
||||
nei.recipe.favorite.change_result_index=Change Output
|
||||
|
||||
nei.recipe.information=Information
|
||||
|
||||
nei.itemsort.minecraft=Minecraft
|
||||
nei.itemsort.minecraft.tip=Sorts items from vanilla minecraft first
|
||||
nei.itemsort.mod=Mod
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 4.6 KiB |
Reference in new issue
Block a user