Files
NotEnoughItems/src/main/java/codechicken/nei/recipe/RecipeInfo.java
T
miozune 7834d72ecf RecipeCatalyst Enhancements (#199)
* 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 9bbdd7b174

* enable by default

* forgot this one

* Add ability to skip search for catalysts

* resolve some todos
2022-01-30 17:01:12 +01:00

125 lines
4.7 KiB
Java

package codechicken.nei.recipe;
import codechicken.nei.OffsetPositioner;
import codechicken.nei.api.API;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.api.IStackPositioner;
import com.google.common.base.Objects;
import net.minecraft.client.gui.inventory.GuiBrewingStand;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiCrafting;
import net.minecraft.client.gui.inventory.GuiFurnace;
import net.minecraft.client.gui.inventory.GuiInventory;
import java.util.HashMap;
public class RecipeInfo
{
private static class OverlayKey
{
final String ident;
final Class<? extends GuiContainer> guiClass;
public OverlayKey(Class<? extends GuiContainer> classz, String ident)
{
this.guiClass = classz;
this.ident = ident;
}
@Override
public boolean equals(Object obj)
{
if(!(obj instanceof OverlayKey))
return false;
OverlayKey key = (OverlayKey)obj;
return Objects.equal(ident, key.ident) && guiClass == key.guiClass;
}
@Override
public int hashCode()
{
return Objects.hashCode(ident, guiClass);
}
}
static final HashMap<OverlayKey, IOverlayHandler> overlayMap = new HashMap<>();
static final HashMap<OverlayKey, IStackPositioner> positionerMap = new HashMap<>();
static final HashMap<Class<? extends GuiContainer>, int[]> offsets = new HashMap<>();
public static void registerOverlayHandler(Class<? extends GuiContainer> classz, IOverlayHandler handler, String ident)
{
overlayMap.put(new OverlayKey(classz, ident), handler);
}
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident, IStackPositioner positioner)
{
positionerMap.put(new OverlayKey(classz, ident), positioner);
if(positioner instanceof OffsetPositioner && !offsets.containsKey(classz))
{
OffsetPositioner p = (OffsetPositioner)positioner;
setGuiOffset(classz, p.offsetx, p.offsety);
}
}
public static void setGuiOffset(Class<? extends GuiContainer> classz, int x, int y)
{
offsets.put(classz, new int[]{x, y});
}
public static boolean hasDefaultOverlay(GuiContainer gui, String ident)
{
return positionerMap.containsKey(new OverlayKey(gui.getClass(), ident));
}
public static boolean hasOverlayHandler(GuiContainer gui, String ident)
{
return overlayMap.containsKey(new OverlayKey(gui.getClass(), ident));
}
public static IOverlayHandler getOverlayHandler(GuiContainer gui, String ident)
{
return overlayMap.get(new OverlayKey(gui.getClass(), ident));
}
public static IStackPositioner getStackPositioner(GuiContainer gui, String ident)
{
return positionerMap.get(new OverlayKey(gui.getClass(), ident));
}
public static int[] getGuiOffset(GuiContainer gui)
{
int[] offset = offsets.get(gui.getClass());
return offset == null ? new int[]{5, 11} : offset;
}
public static void load()
{
API.registerRecipeHandler(new ShapedRecipeHandler());
API.registerUsageHandler(new ShapedRecipeHandler());
API.registerRecipeHandler(new ShapelessRecipeHandler());
API.registerUsageHandler(new ShapelessRecipeHandler());
API.registerRecipeHandler(new FireworkRecipeHandler());
API.registerUsageHandler(new FireworkRecipeHandler());
API.registerRecipeHandler(new FurnaceRecipeHandler());
API.registerUsageHandler(new FurnaceRecipeHandler());
API.registerRecipeHandler(new BrewingRecipeHandler());
API.registerUsageHandler(new BrewingRecipeHandler());
API.registerRecipeHandler(new FuelRecipeHandler());
API.registerUsageHandler(new FuelRecipeHandler());
API.registerGuiOverlay(GuiCrafting.class, "crafting");
API.registerGuiOverlay(GuiInventory.class, "crafting2x2", 63, 20);
API.registerGuiOverlay(GuiFurnace.class, "smelting");
API.registerGuiOverlay(GuiFurnace.class, "fuel");
API.registerGuiOverlay(GuiBrewingStand.class, "brewing");
API.registerGuiOverlayHandler(GuiCrafting.class, new DefaultOverlayHandler(), "crafting");
API.registerGuiOverlayHandler(GuiInventory.class, new DefaultOverlayHandler(63, 20), "crafting2x2");
API.registerGuiOverlayHandler(GuiBrewingStand.class, new BrewingOverlayHandler(), "brewing");
API.registerRecipeHandler(new ProfilerRecipeHandler(true));
API.registerUsageHandler(new ProfilerRecipeHandler(false));
}
}