Compare commits

...
14 Commits
Author SHA1 Message Date
Dream Master 6dcd26a978 update 2025-08-16 18:39:01 +07:00
koolkrafter5 aeb59081d9 Information Handler (#695) 2025-08-16 18:24:40 +07:00
slprime ef8706ae38 Loading items after the player to ensure the hint cache works correctly in some mods (#687) 2025-08-16 07:38:24 +07:00
Dream Master b49d066231 update 2025-08-08 19:05:06 +07:00
slprime 594fbe6f79 Allowed fill crafting grid without all ingredients (#693) 2025-08-06 13:40:52 -04:00
koolkrafter5andEthryan 3edb85b317 Allow handlers to hide the favorite and overlay buttons via IMC (#678)
Co-authored-by: Ethryan <[email protected]>
2025-07-29 20:37:37 +07:00
TotallyNotOndre 5fd0a74363 Add ability to bookmark linked items (#674) 2025-07-26 07:42:34 +07:00
Dream Master 2ae94e94a0 update 2025-07-17 22:31:09 +07:00
TotallyNotOndre fa3adde3e6 Add ability to link Item in chat (#673) 2025-07-17 10:09:43 +07:00
slprime 56941cc45d Correctly used tools in favorites (#670) 2025-07-12 07:44:34 +02:00
slprimeandCaedis cd7d014704 Bookmarks Chains: Use active Item as preferred if exists (#664)
Co-authored-by: Caedis <[email protected]>
2025-07-11 14:36:10 +00:00
slprime 0634466851 Bookmarks Chains: Optimize GTTools (#667) 2025-07-11 14:33:14 +00:00
slprimeandCaedis b87e389132 Bookmarks Hotkeys: optimization thaumcraft recipes (#663)
Co-authored-by: Caedis <[email protected]>
2025-07-11 14:25:15 +00:00
slprimeandCaedis c788a07cf5 Bookmarks Chains Math: fix infinity loop (#662)
Co-authored-by: Caedis <[email protected]>
2025-07-11 16:21:32 +02:00
37 changed files with 701 additions and 204 deletions

No files matched your search

+53
View File
@@ -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
View File
@@ -1,8 +1,8 @@
// Add your dependencies here
dependencies {
api('com.github.GTNewHorizons:CodeChickenCore:1.4.3:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.36: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')
+1 -1
View File
@@ -151,7 +151,7 @@ modrinthProjectId = notenoughitems-unofficial
# type can be one of [project, version],
# and the name is the Modrinth project or version slug/id of the other mod.
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
modrinthRelations = required-project\:codechickencore-unofficial
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.41'
}
@@ -9,6 +9,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -306,18 +307,33 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
if (recipeId == null || !removeFullRecipe) {
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
return true;
}
if (group.crafting != null && group.crafting.recipeRelations.containsKey(recipeId)) {
boolean removed = false;
if (group.crafting != null && group.collapsed && removeFullRecipe) {
this.grid.removeGroup(groupId);
return true;
} else if (group.crafting != null) {
Set<RecipeId> recipes = group.crafting.recipeRelations.getOrDefault(recipeId, Collections.emptySet());
for (RecipeId relRecipeId : group.crafting.recipeRelations.get(recipeId)) {
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
if (removeFullRecipe && recipes.isEmpty()) {
for (Map.Entry<RecipeId, Set<RecipeId>> entry : group.crafting.recipeRelations.entrySet()) {
if (entry.getValue().contains(recipeId)) {
recipes = entry.getValue();
break;
}
}
}
return removed;
if (!recipes.isEmpty()) {
boolean removed = false;
for (RecipeId relRecipeId : recipes) {
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
}
return removed;
}
}
return this.grid.removeRecipe(recipeId, groupId);
@@ -9,9 +9,11 @@ import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -32,6 +34,7 @@ import codechicken.nei.util.NBTJson;
public class FavoriteRecipes {
private static final Set<NBTTagCompound> tools = new HashSet<>();
private static final Map<NBTTagCompound, RecipeId> items = new HashMap<>();
private static final Map<String, RecipeId> fluids = new HashMap<>();
private static File favoriteFile;
@@ -123,6 +126,10 @@ public class FavoriteRecipes {
}
items.put(itemStackNBT, recipeId);
if (NEIServerUtils.isItemTool(stack)) {
tools.add(itemStackNBT);
}
}
} catch (IllegalArgumentException | JsonSyntaxException | IllegalStateException e) {
@@ -143,7 +150,19 @@ public class FavoriteRecipes {
recipeId = fluids.get(getFluidKey(stack));
}
return recipeId;
if (recipeId != null) {
return recipeId;
}
if (NEIServerUtils.isItemTool(stack)
&& (stack.stackTagCompound == null || !stack.stackTagCompound.hasKey("GT.ToolStats"))) {
for (NBTTagCompound nbt : tools) {
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(stack, StackInfo.loadFromNBT(nbt))) {
return items.get(nbt);
}
}
}
}
return null;
@@ -176,6 +195,10 @@ public class FavoriteRecipes {
if (recipeId != null) {
items.put(itemStackNBT, recipeId);
if (NEIServerUtils.isItemTool(stack)) {
tools.add(itemStackNBT);
}
if (fluidKey != null) {
fluids.put(fluidKey, recipeId);
}
+5 -2
View File
@@ -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);
}
}
@@ -186,6 +186,12 @@ public class NEICPH implements IClientPacketHandler {
packet.sendToServer();
}
public static void sendChatLink(ItemStack stackover) {
PacketCustom packet = new PacketCustom(channel, C2S.SEND_CHAT_ITEM_LINK);
packet.writeItemStack(stackover);
packet.sendToServer();
}
public static void sendOpenEnchantmentWindow() {
PacketCustom packet = new PacketCustom(channel, C2S.REQUEST_ENCHANTMENT_GUI);
packet.sendToServer();
@@ -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;
@@ -769,6 +770,7 @@ public class NEIClientConfig {
API.addKeyBind("world.creative", 0);
API.addHashBind("gui.copy_name", Keyboard.KEY_C + NEIClientUtils.CTRL_HASH);
API.addHashBind("gui.copy_oredict", Keyboard.KEY_D + NEIClientUtils.CTRL_HASH);
API.addHashBind("gui.chat_link_item", Keyboard.KEY_L + NEIClientUtils.CTRL_HASH);
}
public static OptionList getOptionList() {
@@ -898,6 +900,7 @@ public class NEIClientConfig {
LayoutManager.load();
NEIController.load();
BookmarkContainerInfo.load();
InformationHandler.load();
mainNEIConfigLoaded = true;
new Thread("NEI Plugin Loader") {
@@ -370,6 +370,10 @@ public class NEIClientUtils extends NEIServerUtils {
else sendCommand(getStringSetting("command.heal"), mc().thePlayer.getCommandSenderName());
}
public static void sendChatItemLink(ItemStack stackover) {
if (hasSMPCounterPart()) NEICPH.sendChatLink(stackover);
}
public static void toggleMagnetMode() {
if (hasSMPCounterPart()) NEICPH.sendToggleMagnetMode();
}
@@ -11,16 +11,21 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.ClientCommandHandler;
import codechicken.core.CommonUtils;
import codechicken.nei.api.API;
import codechicken.nei.api.GuiInfo;
import codechicken.nei.api.IInfiniteItemHandler;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.commands.CommandBookmarkAdd;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import codechicken.nei.guihook.IContainerSlotClickHandler;
import codechicken.nei.recipe.GuiRecipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class NEIController implements IContainerSlotClickHandler, IContainerInputHandler {
@@ -39,6 +44,8 @@ public class NEIController implements IContainerSlotClickHandler, IContainerInpu
public static void load() {
GuiContainerManager.addSlotClickHandler(instance);
GuiContainerManager.addInputHandler(instance);
if (CommonUtils.isClient()) registerClientCommands();
}
public static void load(GuiContainer gui) {
@@ -56,6 +63,11 @@ public class NEIController implements IContainerSlotClickHandler, IContainerInpu
return gui.field_147007_t && gui.field_147008_s.size() > 1;
}
@SideOnly(Side.CLIENT)
public static void registerClientCommands() {
ClientCommandHandler.instance.registerCommand(new CommandBookmarkAdd());
}
public static void updateUnlimitedItems(InventoryPlayer inventory) {
if (!NEIClientConfig.canPerformAction("item") || !NEIClientConfig.hasSMPCounterPart()) return;
@@ -88,9 +88,16 @@ public class NEISPH implements IServerPacketHandler {
case C2S.SET_DUMMY_SLOT:
handleDummySlotSet(sender, packet);
break;
case C2S.SEND_CHAT_ITEM_LINK:
handleSendChatItemLink(sender, packet);
break;
}
}
private void handleSendChatItemLink(EntityPlayerMP sender, PacketCustom packet) {
NEIServerUtils.sendChatItemLink(sender, packet.readItemStack());
}
private void handleDummySlotSet(EntityPlayerMP sender, PacketCustom packet) {
int slotNumber = packet.readShort();
ItemStack stack = packet.readItemStack(true);
@@ -17,6 +17,7 @@ import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.event.ClickEvent;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -82,6 +83,18 @@ public class NEIServerUtils {
player.extinguish();
}
public static void sendChatItemLink(EntityPlayerMP sender, ItemStack stackover) {
ServerUtils.sendChatToAll(
new ChatComponentTranslation(
"nei.chat.item_link.text",
sender.getDisplayName(),
stackover.func_151000_E().setChatStyle(
stackover.func_151000_E().getChatStyle().setChatClickEvent(
new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
"/nei_bookmark " + stackover.writeToNBT(new NBTTagCompound()))))));
}
public static long getTime(World world) {
return world.getWorldInfo().getWorldTime();
}
@@ -23,6 +23,7 @@ public final class PacketIDs {
public static final int SET_CREATIVE_PLUS_MODE = 23;
public static final int REQUEST_POTION_GUI = 24;
public static final int SET_DUMMY_SLOT = 25;
public static final int SEND_CHAT_ITEM_LINK = 26;
}
public static final class S2C {
@@ -14,6 +14,7 @@ import net.minecraftforge.oredict.OreDictionary;
import codechicken.nei.api.ItemFilter;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.StackInfo;
/**
* Simply an {@link ItemStack} with position. Mainly used in the recipe handlers.
@@ -145,7 +146,7 @@ public class PositionedStack {
* NBT-friendly version of {@link #contains(ItemStack)}
*/
public boolean containsWithNBT(ItemStack ingredient) {
for (ItemStack item : items) if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(item, ingredient)) return true;
for (ItemStack item : items) if (StackInfo.equalItemAndNBT(item, ingredient, true)) return true;
return false;
}
@@ -1,7 +1,5 @@
package codechicken.nei.api;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
@@ -20,10 +18,6 @@ public interface IStackStringifyHandler {
return null;
}
default Optional<ItemStack> getContainerItem(ItemStack stack) {
return null;
}
default void playItemDamageSound(boolean enabled) {}
default void pauseItemDamageSound(boolean pause) {}
}
@@ -9,7 +9,6 @@ import java.util.Map;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -101,6 +100,10 @@ public abstract class ShortcutInputHandler {
return copyItemStackOreDictionary(stackover);
}
if (NEIClientConfig.isKeyHashDown("gui.chat_link_item")) {
return sendItemStackChatLink(stackover);
}
if (NEIClientConfig.isKeyHashDown("gui.recipe")) {
return GuiCraftingRecipe.openRecipeGui("item", stackover);
}
@@ -149,6 +152,13 @@ public abstract class ShortcutInputHandler {
return true;
}
private static boolean sendItemStackChatLink(ItemStack stackover) {
if (stackover == null) return false;
NEIClientUtils.sendChatItemLink(stackover); // I wish clients could just send formatted messages
return true;
}
private static boolean copyItemStackOreDictionary(ItemStack stackover) {
StringBuilder builder = new StringBuilder();
@@ -296,7 +306,7 @@ public abstract class ShortcutInputHandler {
recipe.getIngredients().stream().forEach(ingr -> {
final List<ItemStack> permutations = ingr.getPermutations();
for (int index = 0; index < permutations.size(); index++) {
if (FavoriteRecipes.getFavorite(permutations.get(index)) != null) {
if (FavoriteRecipes.contains(permutations.get(index))) {
ingr.setActiveIndex(index);
break;
}
@@ -409,6 +419,9 @@ public abstract class ShortcutInputHandler {
hotkeys.put(NEIClientConfig.getKeyName("gui.copy_name"), NEIClientUtils.translate("itempanel.copy_name"));
hotkeys.put(NEIClientConfig.getKeyName("gui.copy_oredict"), NEIClientUtils.translate("itempanel.copy_oredict"));
hotkeys.put(
NEIClientConfig.getKeyName("gui.chat_link_item"),
NEIClientUtils.translate("itempanel.chat_link_item"));
if (!(gui instanceof GuiRecipe) && NEIClientConfig.canCheatItem(stack)) {
hotkeys.put(
@@ -470,15 +483,15 @@ public abstract class ShortcutInputHandler {
private static void autocraftingIgnoreInventory(RecipeChainMath math) {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final InventoryPlayer playerInventory = guiContainer.mc.thePlayer.inventory;
final List<ItemStack> playerInventory = AutoCraftingManager.getInventoryItems(guiContainer).values();
final RecipeId rootRecipeId = math.createMasterRoot();
for (BookmarkItem item : math.recipeIngredients) {
if (item.amount > 0 && rootRecipeId.equals(item.recipeId)) {
long amount = 0;
for (ItemStack stack : playerInventory.mainInventory) {
if (stack != null && NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
for (ItemStack stack : playerInventory) {
if (NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
amount += StackInfo.getAmount(stack);
}
}
@@ -494,7 +507,7 @@ public abstract class ShortcutInputHandler {
BookmarksGridSlot slot) {
if (slot != null) {
return slot.getRecipeId();
return slot.isIngredient() ? null : slot.getRecipeId();
} else if (ItemPanels.itemPanel.contains(mousex, mousey)
|| ItemPanels.itemPanel.historyPanel.contains(mousex, mousey)) {
return FavoriteRecipes.getFavorite(stack);
@@ -0,0 +1,49 @@
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;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import codechicken.nei.ItemPanels;
public class CommandBookmarkAdd extends CommandBase implements ICommand {
@Override
public String getCommandName() {
return "nei_bookmark";
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "/nei_bookmark <nbt>";
}
@Override
public int getRequiredPermissionLevel() {
return 0;
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if (args.length < 1 || args[0].length() < 3) {
sender.addChatMessage(new ChatComponentText("§c/nei_bookmark <nbt>"));
return;
}
try {
ItemPanels.bookmarkPanel.addItem(
ItemStack.loadItemStackFromNBT((NBTTagCompound) JsonToNBT.func_150315_a(String.join(" ", args))));
sender.addChatMessage(new ChatComponentTranslation("nei.chat.bookmark_added.text"));
} catch (NBTException e) {
sender.addChatMessage(new ChatComponentText(e.toString()));
}
}
}
@@ -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,14 +51,14 @@ 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");
final boolean requiresMod = tag.getBoolean("modRequired");
final String excludedModId = tag.hasKey("excludedModId") ? tag.getString("excludedModId") : null;
if (handler.equals("") || modName.equals("") || modId.equals("")) {
if (handler.isEmpty() || modName.isEmpty() || modId.isEmpty()) {
NEIClientConfig.logger.warn("Missing relevant information to registerHandlerInfo!");
return;
}
@@ -74,7 +68,7 @@ public class IMCHandler {
HandlerInfo info = new HandlerInfo(handler, modName, modId, requiresMod, excludedModId);
final String imageResource = tag.hasKey("imageResource") ? tag.getString("imageResource") : null;
if (imageResource != null && !imageResource.equals("")) {
if (imageResource != null && !imageResource.isEmpty()) {
info.setImage(
imageResource,
tag.getInteger("imageX"),
@@ -84,7 +78,7 @@ public class IMCHandler {
}
if (!info.hasImageOrItem()) {
final String itemName = tag.getString("itemName");
if (itemName != null && !itemName.equals("")) {
if (itemName != null && !itemName.isEmpty()) {
info.setItem(itemName, tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null);
}
}
@@ -100,9 +94,13 @@ 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
info.setShowFavoritesButton(!tag.hasKey("showFavoritesButton") || tag.getBoolean("showFavoritesButton"));
info.setShowOverlayButton(!tag.hasKey("showOverlayButton") || tag.getBoolean("showOverlayButton"));
GuiRecipeTab.handlerAdderFromIMC.remove(handler);
GuiRecipeTab.handlerAdderFromIMC.put(handler, info);
}
@@ -114,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);
}
@@ -126,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();
@@ -135,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) {
@@ -160,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) {
@@ -1,12 +1,12 @@
package codechicken.nei.recipe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import codechicken.nei.ItemPanels;
import codechicken.nei.ItemStackAmount;
@@ -26,19 +26,17 @@ public class AutoCraftingManager {
@Override
public void execute() {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final InventoryPlayer playerInventory = guiContainer.mc.thePlayer.inventory;
final ItemStackAmount inventory = ItemStackAmount.of(Arrays.asList(playerInventory.mainInventory));
final List<BookmarkItem> initialItems = prepareInitialItems(math, inventory);
final List<BookmarkItem> initialItems = prepareInitialItems(math, getInventoryItems(guiContainer));
boolean processed = false;
boolean changed = false;
StackInfo.playItemDamageSound(false);
StackInfo.pauseItemDamageSound(true);
do {
changed = false;
RecipeChainIterator iterator = new RecipeChainIterator(math, initialItems);
iterator.updateInventory(playerInventory.mainInventory);
iterator.updateInventory(getInventoryItems(guiContainer));
while (iterator.hasNext() && !interrupted(guiContainer)) {
final Map<RecipeId, Long> recipes = iterator.next();
@@ -64,13 +62,13 @@ public class AutoCraftingManager {
if (craft) {
changed = true;
processed = true;
iterator.updateInventory(playerInventory.mainInventory);
iterator.updateInventory(getInventoryItems(guiContainer));
}
}
} while (changed && !interrupted(guiContainer));
StackInfo.playItemDamageSound(true);
StackInfo.pauseItemDamageSound(false);
if (processed && !changed && !interrupted(guiContainer)) {
NEIClientUtils.playClickSound();
@@ -121,4 +119,16 @@ public class AutoCraftingManager {
return AutoCraftingManager.math != null && !task.interrupted();
}
public static ItemStackAmount getInventoryItems(GuiContainer guiContainer) {
final ItemStackAmount inventory = new ItemStackAmount();
for (Slot slot : guiContainer.inventorySlots.inventorySlots) {
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(guiContainer.mc.thePlayer)) {
inventory.add(slot.getStack());
}
}
return inventory;
}
}
@@ -6,7 +6,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -15,6 +14,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.nei.FastTransferManager;
@@ -82,21 +82,20 @@ public class DefaultOverlayHandler implements IOverlayHandler {
assignIngredSlots(gui, ingredients, assignedIngredients);
multiplier = Math.min(multiplier == 0 ? 64 : multiplier, calculateRecipeQuantity(assignedIngredients));
if (multiplier != 0) {
moveIngredients(gui, assignedIngredients, (int) multiplier);
}
moveIngredients(gui, assignedIngredients, Math.max(1, multiplier));
return multiplier;
return assignedIngredients.stream().anyMatch(distrib -> distrib.distrib.distributed == 0) ? 0 : multiplier;
}
@Override
public boolean canFillCraftingGrid(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
return presenceOverlay(firstGui, handler, recipeIndex).stream().allMatch(state -> state.isPresent());
return true;
}
@Override
public boolean canCraft(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
return canFillCraftingGrid(firstGui, handler, recipeIndex);
return canFillCraftingGrid(firstGui, handler, recipeIndex)
&& presenceOverlay(firstGui, handler, recipeIndex).stream().allMatch(state -> state.isPresent());
}
@Override
@@ -227,6 +226,7 @@ public class DefaultOverlayHandler implements IOverlayHandler {
for (IngredientDistribution distrib : assignedIngredients) {
final DistributedIngred istack = distrib.distrib;
if (istack.distributed == 0) continue;
if (istack.numSlots == 0) return 0;
final int maxStackSize = istack.stack.getMaxStackSize();
@@ -318,8 +318,10 @@ public class DefaultOverlayHandler implements IOverlayHandler {
}
}
if (biggestIngred == null) // not enough ingreds
return null;
if (biggestIngred == null) {
biggestIngred = new DistributedIngred(posstack.item);
permutation = InventoryUtils.copyStack(posstack.item, 0);
}
biggestIngred.distributed += permutation.stackSize;
assignedIngredients.add(new IngredientDistribution(biggestIngred, permutation));
@@ -339,9 +341,20 @@ public class DefaultOverlayHandler implements IOverlayHandler {
if (!istack.isContainerItem && pstack.getMaxStackSize() == 1
&& pstack.getItem().hasContainerItem(pstack)) {
final Optional<ItemStack> containerItem = StackInfo.getContainerItem(pstack);
if (containerItem != null && containerItem.isPresent()) {
istack.isContainerItem = pstack.getItem() == containerItem.get().getItem();
final NBTTagCompound tagCompound = pstack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("GT.ToolStats")) {
istack.isContainerItem = true;
} else {
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
StackInfo.pauseItemDamageSound(true);
final ItemStack containerItem = pstack.getItem().getContainerItem(pstack);
if (containerItem != null) {
istack.isContainerItem = pstack.getItem() == containerItem.getItem();
}
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
}
}
}
@@ -171,7 +171,7 @@ public class GuiOverlayButton extends GuiRecipeButton {
DrawableResource icon = ICON_OVERLAY;
if (this.hasOverlay && (!this.requireShiftForOverlayRecipe || NEIClientUtils.shiftKey())) {
icon = canFillCraftingGrid() ? ICON_FILL : ICON_FILL_ERROR;
icon = this.missedMaterialsTooltipLineHandler == null ? ICON_FILL : ICON_FILL_ERROR;
}
final int iconX = this.xPosition + (this.width - icon.width - 1) / 2;
@@ -462,8 +462,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
if (!cacheKey.equals(this.recipePageCacheKey)) {
this.recipePageCacheKey = cacheKey;
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
final int recipeIndex = indices.get(refIndex);
for (final int recipeIndex : indices) {
for (PositionedStack pStack : handler.original.getIngredientStacks(recipeIndex)) {
pStack.setPermutationToRender(pStack.getFilteredPermutations().get(0));
}
@@ -472,7 +471,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
final int xOffset = (limitToOneRecipe ? 0 : guiLeft) + xSize - BORDER_PADDING;
final int yOffset = (limitToOneRecipe ? -BUTTON_HEIGHT : guiTop - 18) + getRefIndexPosition(0).y;
final int height = handlerInfo.getHeight() - yShift;
final boolean showFavorites = NEIClientConfig.favoritesEnabled();
final boolean showFavorites = NEIClientConfig.favoritesEnabled() && handlerInfo.getShowFavoritesButton();
final boolean showOverlay = handlerInfo.getShowOverlayButton();
final UpdateRecipeButtonsEvent.Pre preEvent = new UpdateRecipeButtonsEvent.Pre(
this,
xOffset,
@@ -484,7 +484,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
if (MinecraftForge.EVENT_BUS.post(preEvent)) {
buttons = preEvent.buttonList;
} else {
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
final int recipeIndex = indices.get(refIndex);
@@ -493,20 +492,19 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
continue;
}
GuiRecipeButton button = new GuiOverlayButton(
firstGui,
RecipeHandlerRef.of(handler.original, recipeIndex),
xOffset - GuiRecipeButton.BUTTON_WIDTH,
yOffset + height * (refIndex + 1));
buttons.add(button);
if (showFavorites) {
int x = xOffset - GuiRecipeButton.BUTTON_WIDTH;
int y = yOffset + height * (refIndex + 1);
if (showOverlay) {
buttons.add(
new GuiFavoriteButton(
new GuiOverlayButton(
firstGui,
RecipeHandlerRef.of(handler.original, recipeIndex),
button.xPosition,
button.yPosition - button.height - 1));
x,
y));
y -= GuiRecipeButton.BUTTON_HEIGHT + 1;
}
if (showFavorites) {
buttons.add(new GuiFavoriteButton(RecipeHandlerRef.of(handler.original, recipeIndex), x, y));
}
}
@@ -522,6 +520,10 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
buttons.removeIf(GuiFavoriteButton.class::isInstance);
}
if (!showOverlay) {
buttons.removeIf(GuiOverlayButton.class::isInstance);
}
/** compatibility with old format */
this.overlayButtons = buttons.stream().filter(GuiOverlayButton.class::isInstance)
.toArray(GuiOverlayButton[]::new);
@@ -28,6 +28,8 @@ public class HandlerInfo {
private int height = DEFAULT_HEIGHT;
private int width = DEFAULT_WIDTH;
private int maxRecipesPerPage = DEFAULT_MAX_PER_PAGE;
private boolean showFavoritesButton = true;
private boolean showOverlayButton = true;
private ItemStack itemStack = null;
private DrawableResource image = null;
@@ -112,6 +114,22 @@ public class HandlerInfo {
this.yShift = yShift;
}
public boolean getShowFavoritesButton() {
return this.showFavoritesButton;
}
public void setShowFavoritesButton(boolean showFavoritesButton) {
this.showFavoritesButton = showFavoritesButton;
}
public boolean getShowOverlayButton() {
return this.showOverlayButton;
}
public void setShowOverlayButton(boolean showOverlayButton) {
this.showOverlayButton = showOverlayButton;
}
public static class Builder {
private final HandlerInfo info;
@@ -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);
}
}
}
@@ -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);
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
@@ -31,6 +30,7 @@ public class StackInfo {
private static final Map<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
private static final ItemStackMap<String> guidcache = new ItemStackMap<>();
private static final LRUCache<ItemStackKey, FluidStack> fluidcache = new LRUCache<>(200);
private static boolean isPausedItemDamageSound = false;
static {
stackStringifyHandlers.add(new DefaultStackStringifyHandler());
@@ -74,20 +74,16 @@ public class StackInfo {
return stack;
}
public static Optional<ItemStack> getContainerItem(ItemStack stack) {
Optional<ItemStack> result = null;
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && result == null; i--) {
result = stackStringifyHandlers.get(i).getContainerItem(stack);
public static void pauseItemDamageSound(boolean pause) {
if (isPausedItemDamageSound != (isPausedItemDamageSound = pause)) {
for (IStackStringifyHandler handler : stackStringifyHandlers) {
handler.pauseItemDamageSound(pause);
}
}
return result;
}
public static void playItemDamageSound(boolean enabled) {
for (IStackStringifyHandler handler : stackStringifyHandlers) {
handler.playItemDamageSound(enabled);
}
public static boolean isPausedItemDamageSound() {
return isPausedItemDamageSound;
}
public static ItemStack withAmount(ItemStack stack, long customCount) {
@@ -6,11 +6,12 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import codechicken.nei.ItemStackAmount;
import codechicken.nei.NEIClientUtils;
@@ -22,6 +23,19 @@ import codechicken.nei.recipe.StackInfo;
public class RecipeChainMath {
private static class ContainerItemResult {
public ItemStack stack;
public ItemStack containerItem;
public long leftSteps;
public ContainerItemResult(ItemStack stack, long leftSteps, ItemStack containerItem) {
this.stack = stack;
this.leftSteps = leftSteps;
this.containerItem = containerItem;
}
}
private static final ItemStack ROOT_ITEM = new ItemStack(Blocks.fire);
private static final RecipeId ROOT_RECIPE_ID = RecipeId
.of(ROOT_ITEM, "recipe-autocrafting", Collections.emptyList());
@@ -64,6 +78,7 @@ public class RecipeChainMath {
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
if (entry.getValue() > 1 || collapsedRecipes.contains(entry.getKey())) {
collectPreferredItems(entry.getKey(), this.preferredItems, new HashSet<>());
removeLoop(entry.getKey(), this.preferredItems, new HashSet<>());
this.outputRecipes.put(entry.getKey(), entry.getValue());
}
}
@@ -80,6 +95,7 @@ public class RecipeChainMath {
.noneMatch(resItem -> resItem.recipeId.equals(recipeId))) {
final Map<BookmarkItem, BookmarkItem> references = new HashMap<>(this.preferredItems);
collectPreferredItems(recipeId, references, new HashSet<>());
removeLoop(recipeId, references, new HashSet<>());
final int depth = getMaxDepth(recipeId, references);
if (maxDepth < depth || maxDepth == depth && entry.getValue() > maxMultiplier) {
@@ -121,15 +137,26 @@ public class RecipeChainMath {
for (BookmarkItem ingrItem : this.recipeIngredients) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && !preferredItems.containsKey(ingrItem)) {
BookmarkItem activeItem = null;
BookmarkItem prefItem = null;
for (BookmarkItem item : this.recipeResults) {
if (item.factor > (prefItem == null ? 0 : prefItem.factor) && item.containsItems(ingrItem)
&& !visited.contains(item.recipeId)) {
prefItem = item;
if (item.factor > 0 && !visited.contains(item.recipeId) && item.containsItems(ingrItem)) {
if ((activeItem == null || item.factor > activeItem.factor) && NEIClientUtils
.areStacksSameTypeCraftingWithNBT(ingrItem.itemStack, item.itemStack)) {
activeItem = item;
} else if (prefItem == null || item.factor > prefItem.factor) {
prefItem = item;
}
}
}
if (activeItem != null) {
prefItem = activeItem;
}
if (prefItem != null) {
preferredItems.put(ingrItem, prefItem);
collectPreferredItems(prefItem.recipeId, preferredItems, visited);
@@ -143,8 +170,8 @@ public class RecipeChainMath {
private int getMaxDepth(RecipeId recipeId, Map<BookmarkItem, BookmarkItem> preferredItems) {
int maxDepth = 0;
for (BookmarkItem ingrItem : this.recipeIngredients) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && preferredItems.containsKey(ingrItem)) {
for (BookmarkItem ingrItem : preferredItems.keySet()) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId)) {
maxDepth = Math.max(maxDepth, getMaxDepth(preferredItems.get(ingrItem).recipeId, preferredItems) + 1);
}
}
@@ -152,6 +179,24 @@ public class RecipeChainMath {
return maxDepth;
}
private void removeLoop(RecipeId recipeId, Map<BookmarkItem, BookmarkItem> preferredItems, Set<RecipeId> visited) {
visited.add(recipeId);
for (BookmarkItem ingrItem : this.recipeIngredients) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && preferredItems.containsKey(ingrItem)) {
BookmarkItem prefItem = preferredItems.get(ingrItem);
if (visited.contains(prefItem.recipeId)) {
preferredItems.remove(ingrItem);
} else {
removeLoop(prefItem.recipeId, preferredItems, visited);
}
}
}
visited.remove(recipeId);
}
public RecipeId createMasterRoot() {
final List<BookmarkItem> rootIngredients = new ArrayList<>();
@@ -255,10 +300,14 @@ public class RecipeChainMath {
for (RecipeId recipeId : this.outputRecipes.keySet()) {
collectPreferredItems(recipeId, this.preferredItems, new HashSet<>());
removeLoop(recipeId, this.preferredItems, new HashSet<>());
}
}
public RecipeChainMath refresh() {
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
StackInfo.pauseItemDamageSound(true);
resetCalculation();
if (this.outputRecipes.containsKey(ROOT_RECIPE_ID)) {
@@ -292,6 +341,7 @@ public class RecipeChainMath {
}
}
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
return this;
}
@@ -384,22 +434,13 @@ public class RecipeChainMath {
ItemStack bStack = this.containerItems.get(i);
if (bStack != null && NEIClientUtils.areStacksSameTypeCraftingWithNBT(aStack, bStack)) {
final ContainerItemResult result = getToolsContainerItems(bStack, steps);
while (bStack != null && steps > 0) {
final Optional<ItemStack> containerItem = StackInfo.getContainerItem(bStack);
bStack = result.stack;
steps = result.leftSteps;
steps--;
if (containerItem != null && containerItem.isPresent()) {
bStack = containerItem.get();
if (aStack.getItem() != bStack.getItem()) {
this.containerItems.add(bStack);
bStack = null;
}
} else {
bStack = null;
}
if (result.containerItem != null) {
this.containerItems.add(result.containerItem);
}
this.containerItems.set(i, bStack);
@@ -412,6 +453,60 @@ public class RecipeChainMath {
return steps;
}
private ContainerItemResult getToolsContainerItems(ItemStack aStack, long steps) {
final NBTTagCompound tagCompound = aStack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("GT.ToolStats")) {
final int damagePerContainerCraft = getGTToolDamagePerContainerCraft(aStack);
if (damagePerContainerCraft > 0) {
final NBTTagCompound toolStats = tagCompound.getCompoundTag("GT.ToolStats");
final long maxDamage = toolStats.getLong("MaxDamage");
final long damage = toolStats.getLong("Damage");
final long leftSteps = (maxDamage - damage) / damagePerContainerCraft;
final long availableSteps = Math.min(steps, Math.max(1, leftSteps));
steps -= availableSteps;
if ((damage + availableSteps * damagePerContainerCraft) == maxDamage || leftSteps <= 0) {
aStack = null;
} else {
toolStats.setLong("Damage", damage + availableSteps * damagePerContainerCraft);
}
return new ContainerItemResult(aStack, steps, null);
}
}
final Item item = aStack.getItem();
while (aStack != null && steps > 0) {
aStack = item.getContainerItem(aStack);
steps--;
if (aStack != null && item != aStack.getItem()) {
return new ContainerItemResult(null, steps, aStack);
}
}
return new ContainerItemResult(aStack, steps, null);
}
private int getGTToolDamagePerContainerCraft(ItemStack aStack) {
try {
final Object toolStats = aStack.getItem().getClass().getMethod("getToolStats", ItemStack.class)
.invoke(aStack.getItem(), aStack);
return (int) toolStats.getClass().getMethod("getToolDamagePerContainerCraft").invoke(toolStats);
} catch (Throwable th) {
th.printStackTrace();
}
return 0;
}
private boolean hasContainerItem(ItemStack aStack) {
if (aStack.getItem().hasContainerItem(aStack)) {
@@ -7,10 +7,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
@@ -22,6 +19,8 @@ import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.bookmark.BookmarkItem;
import codechicken.nei.recipe.AutoCraftingManager;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.StackInfo;
@@ -57,14 +56,9 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
final List<ItemStack> remainder = new ArrayList<>();
final ItemStackAmount inventory = new ItemStackAmount();
final GuiContainer currentGui = NEIClientUtils.getGuiContainer();
final EntityClientPlayerMP thePlayer = currentGui.mc.thePlayer;
if (this.lastShiftKey) {
for (Slot slot : currentGui.inventorySlots.inventorySlots) {
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(thePlayer)) {
inventory.add(slot.getStack());
}
}
if (this.lastShiftKey && !(currentGui instanceof GuiRecipe<?>)) {
inventory.putAll(AutoCraftingManager.getInventoryItems(currentGui));
}
if (!this.math.outputRecipes.isEmpty()) {
@@ -89,7 +83,10 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
if (amount >= item.amount) {
final long itemAmount = item.factor * this.math.outputRecipes.get(item.recipeId);
amount += itemAmount - amount % itemAmount;
if (itemAmount > 0) {
amount += itemAmount - amount % itemAmount;
}
this.math.outputRecipes.put(
item.recipeId,
Math.max(this.math.outputRecipes.get(item.recipeId), amount / item.factor));
@@ -1,7 +1,5 @@
package codechicken.nei.recipe.stackinfo;
import java.util.Optional;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -58,14 +56,4 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler {
return fluidStack;
}
@Override
public Optional<ItemStack> getContainerItem(ItemStack stack) {
if (stack.getItem().hasContainerItem(stack)) {
return Optional.ofNullable(stack.getItem().getContainerItem(stack));
}
return null;
}
}
@@ -2,7 +2,6 @@ package codechicken.nei.recipe.stackinfo;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Optional;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -22,7 +21,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
protected static Method getFluidFromDisplayStack = null;
public static boolean replaceAE2FCFluidDrop = false;
private static Class<?> gtMetaGeneratedTool = null;
private static Method getContainerItem = null;
private static Field playSound = null;
static {
@@ -38,13 +36,11 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
getFluidDisplayStack = gtUtility.getMethod("getFluidDisplayStack", FluidStack.class, boolean.class);
gtMetaGeneratedTool = ReflectionHelper.getClass(loader, "gregtech.api.items.MetaGeneratedTool");
getContainerItem = gtMetaGeneratedTool
.getDeclaredMethod("getContainerItem", ItemStack.class, boolean.class, boolean.class);
getContainerItem.setAccessible(true);
gtMetaGeneratedTool = ReflectionHelper.getClass(
loader,
"gregtech.api.items.MetaGeneratedTool",
"gregtech.api.items.GT_MetaGenerated_Tool");
playSound = gtMetaGeneratedTool.getDeclaredField("playSound");
playSound.setAccessible(true);
} catch (Exception ignored) {
/* Do nothing */
}
@@ -119,23 +115,10 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
}
@Override
public Optional<ItemStack> getContainerItem(ItemStack stack) {
if (getContainerItem != null && gtMetaGeneratedTool.isInstance(stack.getItem())
&& stack.getItem().hasContainerItem(stack)) {
try {
return Optional.ofNullable((ItemStack) getContainerItem.invoke(stack.getItem(), stack, false, true));
} catch (Exception ex) {}
}
return null;
}
@Override
public void playItemDamageSound(boolean enabled) {
public void pauseItemDamageSound(boolean pause) {
if (playSound != null) {
try {
playSound.setBoolean(null, enabled);
playSound.setBoolean(null, !pause);
} catch (Exception e) {}
}
@@ -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.
#
@@ -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,,,,,,
1 handler modName itemName nbtInfo modId modRequired excludedModId yShift handlerHeight handlerWidth maxRecipesPerPage imageResource imageX imageY imageWidth imageHeight itemNotes
5 codechicken.nei.recipe.ShapedRecipeHandler Minecraft minecraft:crafting_table minecraft FALSE 65 166 5
6 codechicken.nei.recipe.ShapelessRecipeHandler Minecraft minecraft:crafting_table minecraft FALSE 65 166 5
7 codechicken.nei.recipe.FuelRecipeHandler Minecraft minecraft FALSE 65 166 5 nei:textures/nei_tabbed_sprites.png 80 0 14 14
8 codechicken.nei.recipe.InformationHandler Not Enough Items nei FALSE 65 166 1 nei:textures/nei_tabbed_sprites.png 96 0 16 16
9 advsolar.client.nei.MTRecipeHandler Advanced Solar Panels AdvancedSolarPanel:BlockMolecularTransformer AdvancedSolarPanel TRUE 68 5
10 appeng.integration.modules.NEIHelpers.NEIAEShapedRecipeHandler Applied Energistics 2 appliedenergistics2:item.ItemMultiPart:380 appliedenergistics2 TRUE 65 5
11 appeng.integration.modules.NEIHelpers.NEIAEShapelessRecipeHandler Applied Energistics 2 appliedenergistics2:item.ItemMultiPart:380 appliedenergistics2 TRUE 65 5
@@ -63,6 +63,7 @@ nei.itempanel.open_crafting=Recipe to make this item
nei.itempanel.open_usage=Recipes that use this item
nei.itempanel.copy_name=Copy Item Name
nei.itempanel.copy_oredict=Copy Item OreDictionary
nei.itempanel.chat_link_item=Send item link to chat
nei.enchant=Enchant
nei.enchant.level=Level
@@ -134,6 +135,8 @@ nei.chat.chunkoverlay.0=Chunk Overlay: Off
nei.chat.chunkoverlay.1=Chunk Overlay: Chunk Corners
nei.chat.chunkoverlay.2=Chunk Overlay: Chunks
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.options=NEI Options
nei.options.back=Back
@@ -174,6 +177,7 @@ nei.options.keys.gui.next_tooltip=Next Tooltip
nei.options.keys.gui.copy_name=Copy Item Name
nei.options.keys.gui.craft_items=Craft Items
nei.options.keys.gui.copy_oredict=Copy Item OreDictionary
nei.options.keys.gui.chat_link_item=Send item link to chat
nei.options.keys.gui.itemzoom_toggle=Toggle Item Zoom
nei.options.keys.gui.itemzoom_hold=Hold to Display Item Zoom
nei.options.keys.gui.itemzoom_zoom_in=Item Zoom In
@@ -509,6 +513,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
@@ -31,6 +31,7 @@ nei.itempanel.deleteItem=Удалить предмет
nei.itempanel.collapsed.button.tip=Свернуть/Развернуть все группы предметов
nei.itempanel.collapsed.hint.expand=Развернуть группу (%d предметов)
nei.itempanel.collapsed.hint.collapse=Свернуть группу (%d предметов)
nei.itempanel.chat_link_item=Отправить ссылку на предмет в чат
nei.enchant=Зачаровать
nei.enchant.level=Уровень
@@ -100,6 +101,8 @@ nei.chat.chunkoverlay.0=Отображение чанков: Выключено
nei.chat.chunkoverlay.1=Отображение чанков: Углы чанков
nei.chat.chunkoverlay.2=Отображение чанков: Чанки
nei.chat.chunkoverlay.3=Отображение чанков: Жилы руды GT
nei.chat.item_link.text=<%s> §6Нажми чтобы добавить закладку: %s
nei.chat.bookmark_added.text=Закладка добавлена!
nei.options=Настройки NEI
nei.options.back=Назад
@@ -139,6 +142,7 @@ nei.options.keys.gui.getnextsearch=Следующий поиск
nei.options.keys.gui.next_tooltip=Следующая подсказка
nei.options.keys.gui.copy_name=Скопировать название предмета
nei.options.keys.gui.copy_oredict=Скопировать OreDictionary предмета
nei.options.keys.gui.chat_link_item=Отправить ссылку на предмет в чат
nei.options.keys.gui.itemzoom_toggle=Переключить увеличение предмета
nei.options.keys.gui.itemzoom_hold=Удерживать для отображения увеличения предмета
nei.options.keys.gui.itemzoom_zoom_in=Увеличить предмет
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB