Skip to content

Commit

Permalink
RecipeCatalyst Enhancements (#199)
Browse files Browse the repository at this point in the history
* Fix serial handlers not searching catalysts

* Prevent null stack from being added

* Prevent duplicate stack from being added

* Prevent empty handlerID from being added

* Extract code to get modded items

* Use HANDLER_ID_FUNCTION to determine handler's id
This allows mods that don't implement getOverlayIdentifier to work with

* Implement priority

* Fix typo

* Allow catalysts to be loaded from csv
Add IC2 catalysts

* minor cleanup

* Add Avaritia, BM, Forestry

* Log if TransferRects fail

* Implement removing catalyst

* Add placeholder for version controlling

* Add a BUNCH of catalysts

* Add Schematics

* Add more NASA

* Add way to resolve conflict with handlerID
resolve conflict between IC2 Compressor and Mekanism Osmium Compressor

* Add more catalysts

* Add ALL GT catalysts

* Add more

* temporary "fix" for item rendering
reverts 9bbdd7b

* enable by default

* forgot this one

* Add ability to skip search for catalysts

* resolve some todos
  • Loading branch information
miozune authored Jan 30, 2022
1 parent 3ced04b commit 7834d72
Show file tree
Hide file tree
Showing 17 changed files with 1,534 additions and 118 deletions.
5 changes: 2 additions & 3 deletions src/main/java/codechicken/nei/LayoutManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import codechicken.nei.KeyManager.IKeyStateTracker;
import codechicken.nei.api.API;
import codechicken.nei.api.GuiInfo;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.IRecipeOverlayRenderer;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.api.LayoutStyle;
Expand All @@ -16,7 +15,7 @@
import codechicken.nei.guihook.IContainerObjectHandler;
import codechicken.nei.guihook.IContainerTooltipHandler;
import codechicken.nei.recipe.GuiRecipeTab;
import cpw.mods.fml.common.Loader;
import codechicken.nei.recipe.RecipeCatalysts;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
Expand Down Expand Up @@ -63,7 +62,6 @@
import static codechicken.nei.NEIClientUtils.healPlayer;
import static codechicken.nei.NEIClientUtils.isValidGamemode;
import static codechicken.nei.NEIClientUtils.setHourForward;
import static codechicken.nei.NEIClientUtils.setItemQuantity;
import static codechicken.nei.NEIClientUtils.shiftKey;
import static codechicken.nei.NEIClientUtils.toggleMagnetMode;
import static codechicken.nei.NEIClientUtils.toggleRaining;
Expand Down Expand Up @@ -360,6 +358,7 @@ public boolean onButtonPress(boolean rightclick) {
} else {
if (Keyboard.getEventKeyState() && (Keyboard.getEventKey() == Keyboard.KEY_LSHIFT || Keyboard.getEventKey() == Keyboard.KEY_RSHIFT)) {
GuiRecipeTab.loadHandlerInfo();
RecipeCatalysts.loadCatalystInfo();
}
getOptionList().openGui(getGuiContainer(), false);
}
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/codechicken/nei/NEIClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import codechicken.nei.event.NEIConfigsLoadedEvent;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.RecipeCatalysts;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.TemplateRecipeHandler;
import codechicken.obfuscator.ObfuscationRun;
import com.google.common.base.Objects;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -62,6 +62,7 @@ public class NEIClientConfig {
new ConfigFile(new File(configDir, "client.cfg")));
public static ConfigSet world;
public static final File handlerFile = new File(configDir, "handlers.csv");
public static final File catalystFile = new File(configDir, "catalysts.csv");
public static final File serialHandlersFile = new File(configDir, "serialhandlers.cfg");
public static final File heightHackHandlersFile = new File(configDir, "heighthackhandlers.cfg");
public static final File handlerOrderingFile = new File(configDir, "handlerordering.csv");
Expand All @@ -84,11 +85,9 @@ public class NEIClientConfig {
// Function that extracts the handler ID from a handler, with special logic for
// TemplateRecipeHandler: prefer using the overlay ID if it exists.
public static final Function<IRecipeHandler, String> HANDLER_ID_FUNCTION =
handler -> handler instanceof TemplateRecipeHandler
? Objects.firstNonNull(
((TemplateRecipeHandler) handler).getOverlayIdentifier(),
handler.getHandlerId())
: handler.getHandlerId();
handler -> Objects.firstNonNull(
handler.getOverlayIdentifier(),
handler.getHandlerId());

// Comparator that compares handlers using the handlerOrdering map.
public static final Comparator<IRecipeHandler> HANDLER_COMPARATOR =
Expand Down Expand Up @@ -202,7 +201,7 @@ public boolean onClick(int button) {
API.addOption(new OptionToggleButtonBoubs("inventory.jei_style_tabs", true));
tag.getTag("inventory.jei_style_item_presence_overlay").setComment("Enable/disable JEI Style item presence overlay on ?-hover").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.jei_style_item_presence_overlay", true));
tag.getTag("inventory.jei_style_recipe_catalyst").setComment("Enable/disable JEI Style Recipe Catalysts [experimental]").getBooleanValue(false);
tag.getTag("inventory.jei_style_recipe_catalyst").setComment("Enable/disable JEI Style Recipe Catalysts").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.jei_style_recipe_catalyst", true));


Expand All @@ -218,6 +217,17 @@ public boolean onClick(int button) {
return true;
}
});

tag.getTag("tools.catalyst_load_from_config").setComment("ADVANCED: Load catalysts from config").getBooleanValue(false);
API.addOption(new OptionToggleButton("tools.catalyst_load_from_config", true) {
@Override
public boolean onClick(int button) {
super.onClick(button);
RecipeCatalysts.loadCatalystInfo();
return true;
}
});

setDefaultKeyBindings();
}

Expand Down Expand Up @@ -338,6 +348,7 @@ public static void bootNEI(World world) {
RecipeInfo.load();
LayoutManager.load();
NEIController.load();
RecipeCatalysts.loadCatalystInfo();

configLoaded = true;

Expand Down Expand Up @@ -419,6 +430,9 @@ public static boolean isEnabled() {
public static boolean loadHandlersFromJar() {
return !getBooleanSetting("tools.handler_load_from_config");
}
public static boolean loadCatalystsFromJar() {
return !getBooleanSetting("tools.catalyst_load_from_config");
}

public static void setEnabled(boolean flag) {
getSetting("inventory.widgetsenabled").setBooleanValue(flag);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codechicken/nei/NEIModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import codechicken.nei.asm.NEICorePlugin;
import codechicken.nei.config.IMCHandler;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.RecipeCatalysts;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.client.FMLFileResourcePack;
import cpw.mods.fml.client.FMLFolderResourcePack;
import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.MetadataCollection;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
Expand Down Expand Up @@ -107,6 +107,7 @@ public void init(FMLInitializationEvent event) {
public void postInit(FMLPostInitializationEvent event) {
if (CommonUtils.isClient()) {
GuiRecipeTab.loadHandlerInfo();
RecipeCatalysts.loadCatalystInfo();
ClientHandler.postInit();
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/codechicken/nei/NEIServerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import codechicken.lib.inventory.InventoryRange;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.lib.packet.PacketCustom;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.command.ICommandSender;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -14,6 +16,9 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
Expand All @@ -24,6 +29,7 @@
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.logging.log4j.Level;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -387,6 +393,50 @@ public static void logOnce(Throwable t, Set<String> stackTraces, String message,
}
}

public static ItemStack getModdedItem(String itemId, String nbtString) {
int meta = -1;
ItemStack itemStack;

if (!itemId.contains(":")) {
NEIClientConfig.logger.info(String.format("Item ID %s is missing colon", itemId));
return null;
}
final String[] split = itemId.split(":");
// ModID:ItemID
String itemLookupId = split[0] + ":" + split[1];

if (split.length >= 3) {
int mIdx = -1;
if (split[2].matches("\\d+")) {
mIdx = 2;
} else {
itemLookupId += ":" + split[2];
if (split.length >= 4) mIdx = 3;
}
if (mIdx != -1) meta = Integer.parseInt(split[mIdx]);
}

if (meta != -1) {
itemStack = GameRegistry.makeItemStack(itemLookupId, meta, 1, nbtString == null ? "" : nbtString);
} else {
itemStack = GameRegistry.findItemStack(split[0], split[1], 1);
if (nbtString != null && !nbtString.isEmpty()) {
try {
final NBTBase nbttag = JsonToNBT.func_150315_a(nbtString);
if (!(nbttag instanceof NBTTagCompound)) {
NEIClientConfig.logger.info("Unexpected NBT string - multiple values {}", nbtString);
return null;
}
itemStack.setTagCompound((NBTTagCompound) nbttag);
} catch (NBTException e) {
FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
return null;
}
}
}
return itemStack;
}

public static NBTTagCompound readNBT(File file) throws IOException {
if(!file.exists()) return null;
FileInputStream in = new FileInputStream(file);
Expand Down
59 changes: 37 additions & 22 deletions src/main/java/codechicken/nei/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
import codechicken.nei.config.Option;
import codechicken.nei.config.OptionKeyBind;
import codechicken.nei.recipe.CatalystInfo;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.ICraftingHandler;
Expand Down Expand Up @@ -299,45 +300,59 @@ public static void registerStackStringifyHandler(IStackStringifyHandler handler)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
* @param stack the ingredient that can craft recipes (like a furnace or crafting table)
* @param handler the recipe category handled by the ingredient
* @param priority higher priority comes first, default to 0
*/
public static void addRecipeCatalyst(ItemStack stack, IRecipeHandler handler) {
addRecipeCatalyst(Collections.singletonList(stack), handler);
public static void addRecipeCatalyst(ItemStack stack, IRecipeHandler handler, int priority) {
String handlerID = RecipeCatalysts.getRecipeID(handler);
addRecipeCatalyst(stack, handlerID, priority);
}

/**
* Adds an association between an ingredient and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
* @param stacks the ingredients that can craft recipes (like a furnace or crafting table)
* @param handler the recipe category handled by the ingredient
* See {@link API#addRecipeCatalyst(ItemStack, IRecipeHandler, int)}
*/
public static void addRecipeCatalyst(List<ItemStack> stacks, IRecipeHandler handler) {
String handlerID = handler.getOverlayIdentifier();
if (handlerID != null) {
addRecipeCatalyst(stacks, handler.getOverlayIdentifier());
}
else {
NEIClientConfig.logger.warn(String.format("failed to add recipe catalyst, implement IRecipeHandler#getOverlayIdentifier for your handler %s", handler.getClass().getName()));
}
public static void addRecipeCatalyst(ItemStack stack, IRecipeHandler handler) {
addRecipeCatalyst(stack, handler, 0);
}

/**
* Adds an association between an ingredient and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
* @param stack the ingredient that can craft recipes (like a furnace or crafting table)
* @param handlerID recipe category identifier (see {@link IRecipeHandler#getOverlayIdentifier()})
* @param handlerID recipe category identifier (see also {@link RecipeCatalysts#getRecipeID(IRecipeHandler)})
* @param priority higher priority comes first, default to 0
*/
public static void addRecipeCatalyst(ItemStack stack, String handlerID) {
addRecipeCatalyst(Collections.singletonList(stack), handlerID);
public static void addRecipeCatalyst(ItemStack stack, String handlerID, int priority) {
RecipeCatalysts.addRecipeCatalyst(handlerID, new CatalystInfo(stack, priority));
}

/**
* Adds an association between an ingredient and what it can craft. (i.e. Furnace ItemStack -> Smelting and Fuel Recipes)
* Allows players to see what ingredient they need to craft in order to make recipes from a recipe category.
* @param stacks the ingredients that can craft recipes (like a furnace or crafting table)
* @param handlerID recipe category identifier (see {@link IRecipeHandler#getOverlayIdentifier()})
* See {@link API#addRecipeCatalyst(ItemStack, String, int)}
*/
public static void addRecipeCatalyst(ItemStack stack, String handlerID) {
addRecipeCatalyst(stack, handlerID, 0);
}

public static void removeRecipeCatalyst(ItemStack stack, IRecipeHandler handler) {
String handlerID = RecipeCatalysts.getRecipeID(handler);
removeRecipeCatalyst(stack, handlerID);
}

public static void removeRecipeCatalyst(ItemStack stack, String handlerID) {
RecipeCatalysts.removeRecipeCatalyst(handlerID, stack);
}

@Deprecated
public static void addRecipeCatalyst(List<ItemStack> stacks, IRecipeHandler handler) {
for (ItemStack stack : stacks) {
addRecipeCatalyst(stack, handler);
}
}

@Deprecated
public static void addRecipeCatalyst(List<ItemStack> stacks, String handlerID) {
RecipeCatalysts.addRecipeCatalyst(stacks, handlerID);
for (ItemStack stack : stacks) {
addRecipeCatalyst(stack, handlerID);
}
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer font
private static final HashSet<String> stackTraces = new HashSet<>();

public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer fontRenderer, boolean smallAmount) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
enable3DRender();
float zLevel = drawItems.zLevel += 100F;
try {
Expand Down Expand Up @@ -230,7 +229,6 @@ public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer font

enable2DRender();
drawItems.zLevel = zLevel - 100;
GL11.glPopAttrib();
}

//copy from appeng.client.render.AppEngRenderItem
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/codechicken/nei/recipe/CatalystInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package codechicken.nei.recipe;

import net.minecraft.item.ItemStack;

public class CatalystInfo {
private final ItemStack stack;
private final int priority;

public CatalystInfo(ItemStack stack, int priority) {
this.stack = stack;
this.priority = priority;
}

public ItemStack getStack() {
return stack;
}

public int getPriority() {
return priority;
}
}
Loading

0 comments on commit 7834d72

Please sign in to comment.