Add RecipeCatalyst system

This commit is contained in:
miozune committed 2022-01-09 18:48:33 +09:00
1 parent 98c9f03e74
commit 98b6e552c4
16 files changed
+474 -18

No files matched your search

@@ -408,4 +408,8 @@ public class NEIServerUtils
CompressedStreamTools.writeCompressed(tag, out);
out.close();
}
public static int divideCeil(int numerator, int denominator) {
return (int) Math.ceil((float) numerator / denominator);
}
}
+22 -8
View File
@@ -15,12 +15,7 @@ import codechicken.nei.SubsetWidget.SubsetTag;
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
import codechicken.nei.config.Option;
import codechicken.nei.config.OptionKeyBind;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.ICraftingHandler;
import codechicken.nei.recipe.IUsageHandler;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.*;
import net.minecraft.block.Block;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
@@ -28,8 +23,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import java.util.Collections;
import java.util.Comparator;
import java.util.*;
/**
* This is the main class that handles item property configuration.
@@ -291,4 +285,24 @@ public class API
StackInfo.stackStringifyHandlers.add(handler);
}
/**
* 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 handler the recipe category handled by the ingredient
*/
public static void addRecipeCatalyst(ItemStack stack, Class<? extends IRecipeHandler> handler) {
addRecipeCatalyst(Collections.singletonList(stack), handler);
}
/**
* 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
*/
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {
RecipeCatalysts.addRecipeCatalyst(stacks, handler);
}
}
@@ -3,11 +3,11 @@ package codechicken.nei.api;
import codechicken.nei.NEIChestGuiHandler;
import codechicken.nei.NEICreativeGuiHandler;
import codechicken.nei.NEIDummySlotHandler;
import codechicken.nei.recipe.GuiRecipeCatalyst;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -24,6 +24,7 @@ public class GuiInfo {
API.registerNEIGuiHandler(new NEICreativeGuiHandler());
API.registerNEIGuiHandler(new NEIChestGuiHandler());
API.registerNEIGuiHandler(new NEIDummySlotHandler());
API.registerNEIGuiHandler(new GuiRecipeCatalyst(null));
customSlotGuis.add(GuiContainerCreative.class);
}
@@ -0,0 +1,128 @@
package codechicken.nei.drawable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
/*
* Taken from Just Enough Items 1.12 under the MIT License
*
* The MIT License (MIT) Copyright (c) 2014-2015 mezz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* Breaks a texture into 9 pieces so that it can be scaled to any size.
* Draws the corners and then repeats any middle textures to fill the remaining area.
*/
public class DrawableNineSliceTexture {
private final TextureInfo info;
private final int T_SIZE = 256;
public DrawableNineSliceTexture(TextureInfo info) {
this.info = info;
}
public void draw(int xOffset, int yOffset, int width, int height) {
ResourceLocation location = info.getLocation();
int leftWidth = info.getSliceLeft();
int rightWidth = info.getSliceRight();
int topHeight = info.getSliceTop();
int bottomHeight = info.getSliceBottom();
int textureWidth = info.getWidth();
int textureHeight = info.getHeight();
Minecraft.getMinecraft().renderEngine.bindTexture(location);
float uMin = (float) xOffset / T_SIZE;
float uMax = (float) (xOffset + textureWidth) / T_SIZE;
float vMin = (float) yOffset / T_SIZE;
float vMax = (float) (yOffset + textureHeight) / T_SIZE;
float uSize = uMax - uMin;
float vSize = vMax - vMin;
float uLeft = uMin + uSize * (leftWidth / (float) textureWidth);
float uRight = uMax - uSize * (rightWidth / (float) textureWidth);
float vTop = vMin + vSize * (topHeight / (float) textureHeight);
float vBottom = vMax - vSize * (bottomHeight / (float) textureHeight);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
// left top
draw(tessellator, uMin, vMin, uLeft, vTop, xOffset, yOffset, leftWidth, topHeight);
// left bottom
draw(tessellator, uMin, vBottom, uLeft, vMax, xOffset, yOffset + height - bottomHeight, leftWidth, bottomHeight);
// right top
draw(tessellator, uRight, vMin, uMax, vTop, xOffset + width - rightWidth, yOffset, rightWidth, topHeight);
// right bottom
draw(tessellator, uRight, vBottom, uMax, vMax, xOffset + width - rightWidth, yOffset + height - bottomHeight, rightWidth, bottomHeight);
int middleWidth = textureWidth - leftWidth - rightWidth;
int middleHeight = textureWidth - topHeight - bottomHeight;
int tiledMiddleWidth = width - leftWidth - rightWidth;
int tiledMiddleHeight = height - topHeight - bottomHeight;
if (tiledMiddleWidth > 0) {
// top edge
drawTiled(tessellator, uLeft, vMin, uRight, vTop, xOffset + leftWidth, yOffset, tiledMiddleWidth, topHeight, middleWidth, topHeight);
// bottom edge
drawTiled(tessellator, uLeft, vBottom, uRight, vMax, xOffset + leftWidth, yOffset + height - bottomHeight, tiledMiddleWidth, bottomHeight, middleWidth, bottomHeight);
}
if (tiledMiddleHeight > 0) {
// left side
drawTiled(tessellator, uMin, vTop, uLeft, vBottom, xOffset, yOffset + topHeight, leftWidth, tiledMiddleHeight, leftWidth, middleHeight);
// right side
drawTiled(tessellator, uRight, vTop, uMax, vBottom, xOffset + width - rightWidth, yOffset + topHeight, rightWidth, tiledMiddleHeight, rightWidth, middleHeight);
}
if (tiledMiddleHeight > 0 && tiledMiddleWidth > 0) {
// middle area
drawTiled(tessellator, uLeft, vTop, uRight, vBottom, xOffset + leftWidth, yOffset + topHeight, tiledMiddleWidth, tiledMiddleHeight, middleWidth, middleHeight);
}
tessellator.draw();
}
private void drawTiled(Tessellator tessellator, float uMin, float vMin, float uMax, float vMax, int xOffset, int yOffset, int tiledWidth, int tiledHeight, int width, int height) {
int xTileCount = tiledWidth / width;
int xRemainder = tiledWidth - (xTileCount * width);
int yTileCount = tiledHeight / height;
int yRemainder = tiledHeight - (yTileCount * height);
int yStart = yOffset + tiledHeight;
float uSize = uMax - uMin;
float vSize = vMax - vMin;
for (int xTile = 0; xTile <= xTileCount; xTile++) {
for (int yTile = 0; yTile <= yTileCount; yTile++) {
int tileWidth = (xTile == xTileCount) ? xRemainder : width;
int tileHeight = (yTile == yTileCount) ? yRemainder : height;
int x = xOffset + (xTile * width);
int y = yStart - ((yTile + 1) * height);
if (tileWidth > 0 && tileHeight > 0) {
int maskRight = width - tileWidth;
int maskTop = height - tileHeight;
float uOffset = (maskRight / (float) width) * uSize;
float vOffset = (maskTop / (float) height) * vSize;
draw(tessellator, uMin, vMin + vOffset, uMax - uOffset, vMax, x, y + maskTop, tileWidth, tileHeight);
}
}
}
}
private static void draw(Tessellator tessellator, float minU, double minV, float maxU, float maxV, int xOffset, int yOffset, int width, int height) {
tessellator.addVertexWithUV(xOffset, yOffset + height, 0, minU, minV);
tessellator.addVertexWithUV(xOffset + width, yOffset + height, 0, maxU, maxV);
tessellator.addVertexWithUV(xOffset + width, yOffset, 0, maxU, minV);
tessellator.addVertexWithUV(xOffset, yOffset, 0, minU, minV);
}
}
@@ -0,0 +1,98 @@
package codechicken.nei.drawable;
import net.minecraft.util.ResourceLocation;
/*
* Taken from Just Enough Items 1.12 under the MIT License
*
* The MIT License (MIT) Copyright (c) 2014-2015 mezz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class TextureInfo {
private final ResourceLocation location;
private final int width;
private final int height;
private int sliceLeft;
private int sliceRight;
private int sliceTop;
private int sliceBottom;
private int trimLeft;
private int trimRight;
private int trimTop;
private int trimBottom;
public TextureInfo(ResourceLocation location, int width, int height) {
this.location = location;
this.width = width;
this.height = height;
}
public TextureInfo slice(int left, int right, int top, int bottom) {
this.sliceLeft = left;
this.sliceRight = right;
this.sliceTop = top;
this.sliceBottom = bottom;
return this;
}
public TextureInfo trim(int left, int right, int top, int bottom) {
this.trimLeft = sliceLeft;
this.trimRight = sliceRight;
this.trimTop = sliceTop;
this.trimBottom = sliceBottom;
return this;
}
public ResourceLocation getLocation() {
return location;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getSliceLeft() {
return sliceLeft;
}
public int getSliceRight() {
return sliceRight;
}
public int getSliceTop() {
return sliceTop;
}
public int getSliceBottom() {
return sliceBottom;
}
public int getTrimLeft() {
return trimLeft;
}
public int getTrimRight() {
return trimRight;
}
public int getTrimTop() {
return trimTop;
}
public int getTrimBottom() {
return trimBottom;
}
}
@@ -8,7 +8,6 @@ import net.minecraft.item.crafting.FurnaceRecipes;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import static codechicken.nei.NEIClientUtils.translate;
@@ -78,6 +77,11 @@ public class FuelRecipeHandler extends FurnaceRecipeHandler
}
@Override
public String specifyTransferRect() {
return "fuel";
}
public String getOverlayIdentifier() {
return "fuel";
}
@@ -115,6 +115,11 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler
}
}
@Override
public String specifyTransferRect() {
return "smelting";
}
@Override
public String getGuiTexture() {
return "textures/gui/container/furnace.png";
@@ -30,11 +30,7 @@ import org.lwjgl.opengl.GL11;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -76,6 +72,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
private final Rectangle area = new Rectangle();
private final GuiRecipeTabs recipeTabs;
private final GuiRecipeCatalyst guiRecipeCatalyst;
private IRecipeHandler handler;
private HandlerInfo handlerInfo;
@@ -84,6 +81,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
protected GuiRecipe(GuiScreen prevgui) {
super(new ContainerRecipe());
recipeTabs = new GuiRecipeTabs(this);
guiRecipeCatalyst = new GuiRecipeCatalyst(this);
slotcontainer = (ContainerRecipe) inventorySlots;
this.prevGui = prevgui;
@@ -267,7 +265,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
return handler.getIngredientStacks(idx);
}
}
return null;
}
@@ -454,6 +452,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
}
public void refreshPage() {
RecipeCatalysts.updatePosition(ySize - BG_TOP_HEIGHT - (GuiRecipeCatalyst.fullBorder * 2));
refreshSlots();
final int recipesPerPage = getRecipesPerPage();
final boolean multiplepages = handler.numRecipes() > recipesPerPage;
@@ -503,6 +502,13 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
PositionedStack result = handler.getResultStack(i);
if (result != null)
slotcontainer.addSlot(result, p.x, p.y);
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler.getClass());
for (PositionedStack catalyst : catalysts) {
int xOffset = -GuiRecipeCatalyst.ingredientSize;
int yOffset = BG_TOP_Y + GuiRecipeCatalyst.fullBorder;
slotcontainer.addSlot(catalyst, xOffset, yOffset);
}
}
}
@@ -587,6 +593,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve
RenderHelper.enableGUIStandardItemLighting();
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
recipeTabs.draw(mouseX, mouseY);
guiRecipeCatalyst.draw();
RenderHelper.disableStandardItemLighting();
}
@@ -0,0 +1,75 @@
package codechicken.nei.recipe;
import codechicken.nei.api.INEIGuiAdapter;
import codechicken.nei.drawable.DrawableNineSliceTexture;
import codechicken.nei.drawable.TextureInfo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.util.Rectangle;
public class GuiRecipeCatalyst extends INEIGuiAdapter {
private final DrawableNineSliceTexture catalystTabImage = new DrawableNineSliceTexture(getTextureInfo("catalyst_tab.png", 28, 28).slice(6, 6, 6, 6));
private final DrawableNineSliceTexture slotImage = new DrawableNineSliceTexture(getTextureInfo("slot.png", 18, 18).slice(1, 1, 1, 1));
private GuiRecipe guiRecipe;
public static final int ingredientSize = 16;
public static final int ingredientBorder = 1;
public static final int tabBorder = 5;
public static final int fullBorder = ingredientBorder + tabBorder;
private static final Rectangle catalystRect = new Rectangle();
private static final Rectangle targetRect = new Rectangle();
public GuiRecipeCatalyst(GuiRecipe guiRecipe) {
this.guiRecipe = guiRecipe;
}
public void draw() {
if (guiRecipe == null) return;
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler().getClass()).size();
if (catalystsSize == 0) return;
int availableHeight = RecipeCatalysts.getHeight();
int columnCount = RecipeCatalysts.getColumnCount(availableHeight, catalystsSize);
int rowCount = RecipeCatalysts.getRowCount(availableHeight, catalystsSize);
int width, height, xOffset, yOffset;
width = (ingredientBorder * 2) + (tabBorder * 2) + (columnCount * ingredientSize);
height = (ingredientBorder * 2) + (tabBorder * 2) + (rowCount * ingredientSize);
xOffset = guiRecipe.guiLeft - width + tabBorder;
yOffset = guiRecipe.guiTop;
catalystTabImage.draw(xOffset, yOffset, width, height);
width = (ingredientBorder * 2) + (columnCount * ingredientSize);
height = (ingredientBorder * 2) + (rowCount * ingredientSize);
xOffset = guiRecipe.guiLeft - width + ingredientBorder;
yOffset = guiRecipe.guiTop + fullBorder - ingredientBorder;
slotImage.draw(xOffset, yOffset, width, height);
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
if (!(gui instanceof GuiRecipe)) return false;
guiRecipe = (GuiRecipe) gui;
int catalystsSize = RecipeCatalysts.getRecipeCatalysts(guiRecipe.getHandler().getClass()).size();
if (catalystsSize == 0) return false;
int availableHeight = RecipeCatalysts.getHeight();
int columnCount = RecipeCatalysts.getColumnCount(availableHeight, catalystsSize);
int rowCount = RecipeCatalysts.getRowCount(availableHeight, catalystsSize);
int margin = 4;
int width = (ingredientBorder * 2) + (tabBorder * 2) + (columnCount * ingredientSize) + margin;
int height = (ingredientBorder * 2) + (tabBorder * 2) + (rowCount * ingredientSize) + margin;
int xOffset = guiRecipe.guiLeft - width + tabBorder;
int yOffset = guiRecipe.guiTop;
catalystRect.setBounds(xOffset, yOffset, width, height);
targetRect.setBounds(x, y, w, h);
return targetRect.intersects(catalystRect);
}
private TextureInfo getTextureInfo(String name, int width, int height) {
ResourceLocation location = new ResourceLocation("nei:textures/" + name);
return new TextureInfo(location, width, height);
}
}
@@ -30,7 +30,7 @@ public class GuiUsageRecipe extends GuiRecipe
.collect(Collectors.toCollection(ArrayList::new));
handlers.addAll(ItemList.forkJoinPool.submit(() -> usagehandlers.parallelStream()
.map(h -> h.getUsageHandler(inputId, ingredients))
.map(h -> h.getUsageAndCatalystHandler(inputId, ingredients))
.filter(h -> h.numRecipes() > 0)
.collect(Collectors.toCollection(ArrayList::new))).get());
} catch (InterruptedException | ExecutionException e) {
@@ -15,5 +15,12 @@ public interface IUsageHandler extends IRecipeHandler
* @param ingredients Objects representing the ingredients that matching recipes must contain.
* @return An instance of {@link IUsageHandler} configured with a list of recipes that contain matching input
*/
public IUsageHandler getUsageHandler(String inputId, Object... ingredients);
IUsageHandler getUsageHandler(String inputId, Object... ingredients);
/**
* See {@link TemplateRecipeHandler#getUsageAndCatalystHandler} for implementation
*/
default IUsageHandler getUsageAndCatalystHandler(String inputId, Object... ingredients) {
return getUsageHandler(inputId, ingredients);
}
}
@@ -0,0 +1,72 @@
package codechicken.nei.recipe;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import net.minecraft.item.ItemStack;
import java.util.*;
public class RecipeCatalysts {
private static final Map<Class<? extends IRecipeHandler>, List<ItemStack>> recipeCatalystMap = new HashMap<>();
private static Map<Class<? extends IRecipeHandler>, List<PositionedStack>> positionedRecipeCatalystMap = new HashMap<>();
private static int heightCache;
public static void addRecipeCatalyst(List<ItemStack> stacks, Class<? extends IRecipeHandler> handler) {
if (recipeCatalystMap.containsKey(handler)) {
recipeCatalystMap.get(handler).addAll(stacks);
} else {
recipeCatalystMap.put(handler, new ArrayList<>(stacks));
}
}
public static Map<Class<? extends IRecipeHandler>, List<PositionedStack>> getPositionedRecipeCatalystMap() {
return positionedRecipeCatalystMap;
}
public static List<PositionedStack> getRecipeCatalysts(Class<? extends IRecipeHandler> handler) {
if (!NEIClientConfig.areJEIStyleTabsVisible()) return Collections.emptyList();
return positionedRecipeCatalystMap.getOrDefault(handler, Collections.emptyList());
}
public static boolean containsCatalyst(Class<? extends IRecipeHandler> handler, ItemStack candidate) {
return recipeCatalystMap.getOrDefault(handler, Collections.emptyList()).stream()
.anyMatch(s -> NEIServerUtils.areStacksSameType(s, candidate));
}
public static void updatePosition(int availableHeight) {
if (availableHeight == heightCache) return;
Map<Class<? extends IRecipeHandler>, List<PositionedStack>> newMap = new HashMap<>();
for (Map.Entry<Class<? extends IRecipeHandler>, List<ItemStack>> entry : recipeCatalystMap.entrySet()) {
List<ItemStack> catalysts = entry.getValue();
List<PositionedStack> newStacks = new ArrayList<>();
int rowCount = getRowCount(availableHeight, catalysts.size());
for (int index = 0; index < catalysts.size(); index++) {
ItemStack catalyst = catalysts.get(index);
int column = index / rowCount;
int row = index % rowCount;
newStacks.add(new PositionedStack(catalyst, -column * GuiRecipeCatalyst.ingredientSize, row * GuiRecipeCatalyst.ingredientSize));
}
newMap.put(entry.getKey(), newStacks);
}
positionedRecipeCatalystMap = newMap;
heightCache = availableHeight;
}
public static int getHeight() {
return heightCache;
}
public static int getColumnCount(int availableHeight, int catalystsSize) {
int maxItemsPerColumn = availableHeight / GuiRecipeCatalyst.ingredientSize;
return NEIServerUtils.divideCeil(catalystsSize, maxItemsPerColumn);
}
public static int getRowCount(int availableHeight, int catalystsSize) {
int columnCount = getColumnCount(availableHeight, catalystsSize);
return NEIServerUtils.divideCeil(catalystsSize, columnCount);
}
}
@@ -10,6 +10,9 @@ 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 net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import java.util.HashMap;
@@ -119,6 +122,13 @@ public class RecipeInfo
API.registerRecipeHandler(new ProfilerRecipeHandler(true));
API.registerUsageHandler(new ProfilerRecipeHandler(false));
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), ShapedRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), ShapelessRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.crafting_table), FireworkRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.furnace), FurnaceRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Items.brewing_stand), BrewingRecipeHandler.class);
API.addRecipeCatalyst(new ItemStack(Blocks.furnace), FuelRecipeHandler.class);
}
}
@@ -550,6 +550,37 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
return handler;
}
/**
* First look up {@link RecipeCatalysts} whether target ingredient is registered for it.
* If so, load all recipes for this handler.
* Fallback to {@link TemplateRecipeHandler#getUsageHandler}.
*/
public IUsageHandler getUsageAndCatalystHandler(String inputId, Object... ingredients) {
if (!NEIClientConfig.areJEIStyleTabsVisible()) return this.getUsageHandler(inputId, ingredients);
TemplateRecipeHandler handler = newInstance();
if (inputId.equals("item")) {
ItemStack candidate = (ItemStack) ingredients[0];
if (RecipeCatalysts.containsCatalyst(handler.getClass(), candidate)) {
for (RecipeTransferRect rect : transferRects) {
if (specifyTransferRect() == null || Objects.equals(rect.outputId, specifyTransferRect())) {
handler.loadCraftingRecipes(rect.outputId, rect.results);
return handler;
}
}
}
}
return this.getUsageHandler(inputId, ingredients);
}
/**
* Override this if you have multiple {@link RecipeTransferRect}s.
* Used for {@link TemplateRecipeHandler#getUsageAndCatalystHandler}.
*/
public String specifyTransferRect() {
return null;
}
public int numRecipes() {
return arecipes.size();
}