Compare commits

...
Author SHA1 Message Date
slprime 550e85c456 Fix -@mod and !@mod search syntax in Extended mode (#1071) 2026-10-10 14:58:17 +03:00
slprime 1673079cbb ItemZoom: Add side priority option (#1070) 2026-10-10 14:36:28 +03:00
slprime e6174c446a Add options for vertical line count in chain tooltips (#1068) 2026-10-09 21:14:11 +03:00
slprime 869b4571b0 Add recipe cycle freeze option (#1067) 2026-10-09 19:47:38 +03:00
slprime 35f5400ecb Fix Crafting Tree NPE (#1064) 2026-10-06 19:57:10 +03:00
micvog 1e2801c891 Fix crash when returning to the crafting tree after its bookmark group was removed (#1063) 2026-10-06 19:46:37 +03:00
Ressedandslprime 1b3b495fec Fix crash while dragging bookmark group to another grid (#1062)
Co-authored-by: slprime <[email protected]>
2026-10-05 20:07:52 +03:00
slprime 2844ea35bc Fix Old Handlers Hack (#1061) 2026-10-04 22:07:41 +03:00
slprime c020ecbf1f Add Custom Renderer API for Fluids (#1059) 2026-10-02 01:22:58 +03:00
slprime a105a60a1a Fix Subset Width Calculation (#1058) 2026-10-01 23:16:35 +03:00
slprime 3a4a6734dc Fix NPE on GT fluid display without NBT (#1057) 2026-09-29 22:30:43 +03:00
slprime 11f9194de9 Fix EnderIo Tank (#1056) 2026-09-29 20:00:29 +03:00
slprimeandgithub-actions[bot] a685efb3b7 Recipe Group Optimization (#1054)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-09-28 00:19:29 +03:00
danyadevandMartin Robertz 9f3697bb67 fix cycling for fluid permutations (#1048)
Co-authored-by: Martin Robertz <[email protected]>
2026-09-27 18:21:56 +03:00
slprime 18abb880f8 Add widget size to recipe event (#1053) 2026-09-27 14:13:27 +03:00
34 changed files with 1095 additions and 388 deletions

No files matched your search

@@ -572,7 +572,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
return;
} else if (this.sortableGroup != null) {
final int overRowIndex = grid.getRowIndex(mousey);
final int overRowIndex = Math.min(grid.getRowIndex(mousey), grid.getRows() - 1);
if (overRowIndex >= 0 && this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) {
this.grid.moveGroup(this.sortableGroup, overRowIndex);
@@ -1105,7 +1105,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
}
if (super.onMouseWheel(shift, mousex, mousey)) {
final int overRowIndex = grid.getRowIndex(mousey);
final int overRowIndex = Math.min(grid.getRowIndex(mousey), grid.getRows() - 1);
if (this.sortableGroup != null && overRowIndex >= 0
&& this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) {
@@ -316,6 +316,10 @@ public class FavoriteRecipes {
load();
}
public static boolean hasManual() {
return manualFavorites.size() > 0;
}
public static boolean containsManual(ItemStack stack) {
return getManualFavorite(stack) != null;
}
+24 -2
View File
@@ -111,8 +111,14 @@ public class ItemZoom extends Widget implements IContainerInputHandler {
this.xPosition = (availableAreaWidth - this.scale * SLOT_SIZE) / 2;
this.availableAreaWidth = (int) (availableAreaWidth / screenScale);
if (availableAreaWidth / screenScale >= mouse.x) {
this.xPosition += gui.width * screenScale - availableAreaWidth;
final float rightSideShift = gui.width * screenScale - availableAreaWidth;
final boolean leftSideFree = availableAreaWidth / screenScale < mouse.x;
final boolean rightSideFree = mouse.x < gui.width - availableAreaWidth / screenScale;
final boolean showOnRight = leftSideFree && rightSideFree ? !preferLeftSide() : !leftSideFree;
if (showOnRight) {
this.xPosition += rightSideShift;
}
try {
@@ -128,6 +134,22 @@ public class ItemZoom extends Widget implements IContainerInputHandler {
}
}
private boolean preferLeftSide() {
switch (NEIClientConfig.getIntSetting("inventory.itemzoom.preferredSide")) {
case 1:
return true;
case 2:
return false;
}
final int leftCount = NEIClientConfig.isBookmarkPanelHidden()
|| ItemPanels.bookmarkPanel.getGrid().getPerPage() == 0 ? 0 : ItemPanels.bookmarkPanel.getGrid().size();
final int rightCount = ItemPanels.itemPanel.getGrid().getPerPage() == 0 ? 0
: ItemPanels.itemPanel.getGrid().size();
return leftCount <= rightCount;
}
private float getPointSize(GuiContainer gui) {
final float screenScale = 1.0f / getScreenScale();
final float availableAreaWidth = (gui.width - (gui.xSize + gui.width) / 2) * screenScale;
@@ -167,7 +167,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
protected int activeStackIndex = -1;
protected Dimension size = new Dimension();
protected final boolean showNames;
protected int maxNamedRows = Integer.MAX_VALUE;
protected int length = 0;
protected int rows = 0;
@@ -175,29 +175,25 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
protected int gridColumns = 0;
protected int gridCount = 0;
public static ItemsTooltipLineHandler grid(String label, List<ItemStack> items, int maxRows) {
return new ItemsTooltipLineHandler(label, items, true, maxRows, false);
}
public static ItemsTooltipLineHandler list(String label, List<ItemStack> items, int maxRows) {
return new ItemsTooltipLineHandler(label, items, true, maxRows, true);
public static ItemsTooltipLineHandler of(String label, List<ItemStack> items, int maxRows, int maxNamedRows) {
return new ItemsTooltipLineHandler(label, items, true, maxRows, maxNamedRows);
}
public ItemsTooltipLineHandler(String label, List<ItemStack> items) {
this(label, items, true, DEFAULT_MAX_ROWS, false);
this(label, items, true, DEFAULT_MAX_ROWS, 0);
}
public ItemsTooltipLineHandler(String label, List<ItemStack> items, boolean saveStackSize, int maxRows) {
this(label, items, saveStackSize, maxRows, false);
this(label, items, saveStackSize, maxRows, 0);
}
protected ItemsTooltipLineHandler(String label, List<ItemStack> items, boolean saveStackSize, int maxRows,
boolean showNames) {
int maxNamedRows) {
this.label = label;
this.items = groupingItemStacks(items);
this.amountRenderer = saveStackSize ? new TotalAmountRenderer() : new NoAmountRenderer();
this.length = this.items.size();
this.showNames = showNames;
this.maxNamedRows = maxNamedRows;
setMaxRows(maxRows);
}
@@ -214,7 +210,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
this.names.clear();
this.nameRows = 0;
if (!this.showNames || !layoutWithNames(maxRows)) {
if (!layoutWithNames(maxRows)) {
layoutAsGrid(maxRows);
}
@@ -228,7 +224,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
}
protected boolean layoutWithNames(int maxRows) {
final int maxNames = this.length <= maxRows ? this.length : maxRows - 1;
final int maxNames = Math.min(this.maxNamedRows, this.length <= maxRows ? this.length : maxRows - 1);
final int[] lineWidth = new int[maxNames + 1];
lineWidth[0] = labelWidth();
@@ -200,6 +200,11 @@ public class NEIClientConfig {
tag.getTag("inventory.bookmarks.showRecipeMarkerMode").setComment("Show Recipe Marker").getIntValue(0);
API.addOption(new OptionCycled("inventory.bookmarks.showRecipeMarkerMode", 3, true));
tag.getTag("inventory.bookmarks.maxVerticalTooltipRows")
.setComment("Max rows in vertical crafting chain tooltip lists (0 - disable, always use grid)")
.getIntValue(12);
API.addOption(new OptionIntegerField("inventory.bookmarks.maxVerticalTooltipRows", 0, 50));
tag.getTag("inventory.bookmarks.recipeMarkerColor").setComment("Color of the icon marker")
.getHexValue(0xADADAD);
API.addOption(
@@ -267,6 +272,11 @@ public class NEIClientConfig {
.getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.guirecipe.scrollPages", true));
tag.getTag("inventory.guirecipe.freezeCycleOnHover")
.setComment("Stop cycling the recipe while hovering over an ingredient or a button")
.getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.guirecipe.freezeCycleOnHover", true));
tag.getTag("inventory.guirecipe.profile").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.guirecipe.profile", true));
@@ -372,6 +382,11 @@ public class NEIClientConfig {
tag.getTag("inventory.itemzoom.onlySolid").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.itemzoom.onlySolid", true));
tag.getTag("inventory.itemzoom.preferredSide")
.setComment("Which side to prefer showing the zoomed item on, when both sides are free.")
.getIntValue(0);
API.addOption(new OptionCycled("inventory.itemzoom.preferredSide", 3, true));
tag.getTag("inventory.itemzoom.helpText")
.setComment("Display name \"Item Zoom\" and the hotkey to toggle this mod below the zoomed item.")
.getBooleanValue(true);
@@ -1106,6 +1121,10 @@ public class NEIClientConfig {
return getIntSetting("inventory.bookmarks.showRecipeMarkerMode");
}
public static int getMaxVerticalTooltipRows() {
return getIntSetting("inventory.bookmarks.maxVerticalTooltipRows");
}
public static boolean showItemQuantityWidget() {
return getBooleanSetting("inventory.showItemQuantityWidget");
}
@@ -1166,6 +1185,10 @@ public class NEIClientConfig {
return getBooleanSetting("inventory.guirecipe.cycledIngredientsTooltip");
}
public static boolean freezeCycleOnHover() {
return getBooleanSetting("inventory.guirecipe.freezeCycleOnHover");
}
public static boolean requireShiftForOverlayRecipe() {
return getBooleanSetting("inventory.guirecipe.shiftOverlayRecipe");
}
@@ -163,7 +163,7 @@ public class PositionedStack implements Cloneable {
}
public List<ItemStack> getFilteredPermutations(ItemFilter additionalFilter) {
List<ItemStack> items = Arrays.asList(this.items);
List<ItemStack> items = new ArrayList<>(Arrays.asList(this.items));
items = filteringPermutations(items, item -> !ItemInfo.isHidden(item));
items = filteringPermutations(items, PresetsList.getItemFilter());
@@ -361,7 +361,7 @@ public class PositionedStack implements Cloneable {
return;
}
FluidDrawer.drawFluid(
FluidDrawer.drawTank(
this.relx,
this.rely,
this.width,
@@ -445,7 +445,7 @@ public class SearchTokenParser {
final char ch = input.charAt(index);
if (!insideQuotes && delimiters.indexOf(ch) >= 0
&& (!space || index == 0 || input.charAt(index - 1) == ' ')) {
&& (!space || index == 0 || input.charAt(index - 1) == ' ' || lastEnd == index)) {
if (lastEnd == index) {
token += String.valueOf(ch);
@@ -160,7 +160,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
// 1 - partitial hidden
// 2 - enabled
public int state = 2;
public int calculatedWidth;
public volatile int calculatedWidth = -1;
public final List<ItemStack> items;
public final List<SubsetTag> children = new ArrayList<>();
protected final SubsetSlot slot = new SubsetSlot();
@@ -206,7 +206,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
this.state = 2;
this.items.clear();
this.children.clear();
this.calculatedWidth = 0;
this.calculatedWidth = -1;
}
public void updateVisiblity(int mx, int my) {
@@ -261,6 +261,10 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
}
public void resize(Rectangle4i screen, Rectangle4i parent, boolean dropRight) {
if (calculatedWidth < 0) {
calculatedWidth = this.children.stream().mapToInt(SubsetTag::nameWidth).max().orElse(0);
}
int height = Math.min(slot.contentHeight(), screen.h);
int width = Math.max(calculatedWidth + 2, this.items.isEmpty() ? 0 : 16 + MARGIN * 2);
int scrollbarWidth = slot.scrollbarDim().width;
@@ -686,12 +690,12 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
for (SubsetTag tag : list) {
tag.children.sort(Comparator.comparing(SubsetTag::displayName));
tag.calculatedWidth = tag.children.stream().mapToInt(SubsetTag::nameWidth).max().orElse(0);
tag.calculatedWidth = -1;
}
root.children.removeIf(child -> child.children.isEmpty() && child.items.isEmpty());
root.children.sort(Comparator.comparing(SubsetTag::displayName));
root.calculatedWidth = root.children.stream().mapToInt(SubsetTag::nameWidth).max().orElse(0);
root.calculatedWidth = -1;
calculateVisibility(root);
} catch (Throwable e) {
@@ -12,6 +12,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import org.lwjgl.input.Keyboard;
@@ -33,6 +34,7 @@ import codechicken.nei.SubsetWidget.SubsetTag;
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
import codechicken.nei.config.Option;
import codechicken.nei.item.FluidDrawer;
import codechicken.nei.recipe.CatalystInfo;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
@@ -375,6 +377,16 @@ public class API {
StackInfo.stackStringifyHandlers.add(handler);
}
/**
* Replaces the default rendering of a fluid in NEI fluid display slots and fluid tanks.
*
* @param fluid the fluid to render
* @param renderer the renderer, or null to restore the default rendering
*/
public static void registerFluidRenderer(Fluid fluid, IFluidRenderer renderer) {
FluidDrawer.registerFluidRenderer(fluid, renderer);
}
/**
* 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
@@ -0,0 +1,17 @@
package codechicken.nei.api;
import net.minecraftforge.fluids.Fluid;
/**
* Custom renderer for a fluid, used by NEI fluid display slots and fluid tanks in recipes.
* <p>
* Register with {@link API#registerFluidRenderer(Fluid, IFluidRenderer)}.
*/
public interface IFluidRenderer {
/**
* Renders one 16x16 tile of the fluid. Partial tiles of a tank are clipped by NEI. The amount overlay is drawn by
* NEI.
*/
void renderFluid(Fluid fluid, int x, int y);
}
@@ -799,6 +799,7 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
sortableGroup.groupId = groupId;
this.onItemsChanged();
this.getMask();// force generate grid
overGroupId = getRowGroupId(overRowIndex);
}
if (sortableGroup.groupId == overGroupId) {
@@ -144,7 +144,7 @@ public class BookmarkItem {
private static synchronized String getItemGUID(ItemStack stack) {
final FluidStack fluidStack = StackInfo.getFluid(stack);
if (fluidStack != null) {
if (fluidStack != null && (fluidStack.amount > 0 || !StackInfo.isFluidContainer(stack))) {
return fluidStack.getFluid().getName() + ":" + fluidStack.tag;
} else {
@@ -198,6 +198,11 @@ public class BookmarkStorage {
final BookmarkItem item = BookmarkItem.of(parser.parse(itemStr).getAsJsonObject());
if (item != null) {
if (!grid.groups.containsKey(item.groupId)) {
item.groupId = BookmarkGrid.DEFAULT_GROUP_ID;
}
grid.addItem(item, false);
} else {
wasError = true;
@@ -162,7 +162,7 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
final ItemTreeSlot replaceNode = this.uiState.replaceRecipeNode;
this.uiState.replaceRecipeNode = null;
if (recipe != null) {
if (recipe != null && this.grid.getGroup(this.groupId) != null) {
final RecipeId recipeId = recipe.getRecipeId();
boolean changed = false;
@@ -190,6 +190,13 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
@Override
public void initGui() {
// the group can be removed from the bookmark panel while a recipe screen opened from this tree is shown
if (this.grid.getGroup(this.groupId) == null) {
this.mc.displayGuiScreen(this.prevGui);
return;
}
this.xSize = this.width;
this.ySize = this.height;
@@ -2,15 +2,14 @@ package codechicken.nei.item;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import org.lwjgl.opengl.GL11;
import codechicken.nei.item.FluidDrawer.FillDirection;
import codechicken.nei.util.ReadableNumberConverter;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -34,37 +33,13 @@ public class FluidDisplayRenderer implements IItemRenderer {
return;
}
renderIcon(item, fluidDisplay);
renderIcon(item);
renderAmountOverlay(item, fluidDisplay);
}
private void renderIcon(ItemStack item, ItemFluidDisplay fluidDisplay) {
final IIcon icon = fluidDisplay.getIconIndex(item);
if (icon == null) {
return;
}
final int color = fluidDisplay.getColorFromItemStack(item, 0);
final float red = (color >> 16 & 0xFF) / 255F;
final float green = (color >> 8 & 0xFF) / 255F;
final float blue = (color & 0xFF) / 255F;
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
GL11.glColor4f(red, green, blue, 1F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper
.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
final Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(0, 16, 0, icon.getMinU(), icon.getMaxV());
tessellator.addVertexWithUV(16, 16, 0, icon.getMaxU(), icon.getMaxV());
tessellator.addVertexWithUV(16, 0, 0, icon.getMaxU(), icon.getMinV());
tessellator.addVertexWithUV(0, 0, 0, icon.getMinU(), icon.getMinV());
tessellator.draw();
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glDisable(GL11.GL_BLEND);
private void renderIcon(ItemStack item) {
final Fluid fluid = FluidRegistry.getFluid(item.getItemDamage());
FluidDrawer.drawFluidArea(fluid != null ? fluid : FluidRegistry.WATER, 0, 0, 16, 16, false, FillDirection.UP);
}
private void renderAmountOverlay(ItemStack item, ItemFluidDisplay fluidDisplay) {
@@ -1,14 +1,21 @@
package codechicken.nei.item;
import java.util.IdentityHashMap;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import codechicken.nei.api.IFluidRenderer;
import codechicken.nei.scroll.GuiHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -27,28 +34,32 @@ public class FluidDrawer {
return this == LEFT || this == RIGHT;
}
public FillDirection resolve(FluidStack fluidStack) {
public FillDirection resolve(Fluid fluid) {
if (this != AUTO) return this;
return fluidStack.getFluid().isGaseous(fluidStack) ? DOWN : UP;
return fluid.isGaseous() ? DOWN : UP;
}
}
private static final Map<Fluid, IFluidRenderer> fluidRenderers = new IdentityHashMap<>();
private FluidDrawer() {}
public static void drawFluid(int x, int y, int width, int height, int capacity, FluidStack fluidStack,
boolean flowing, FillDirection direction) {
final Fluid fluid = fluidStack.getFluid();
IIcon icon = flowing ? fluid.getFlowingIcon() : null;
if (icon == null) {
icon = fluid.getIcon(fluidStack);
public static void registerFluidRenderer(Fluid fluid, IFluidRenderer renderer) {
if (renderer == null) {
fluidRenderers.remove(fluid);
} else {
fluidRenderers.put(fluid, renderer);
}
}
if (icon == null || fluidStack.amount <= 0) {
public static void drawTank(int x, int y, int width, int height, int capacity, FluidStack fluidStack,
boolean flowing, FillDirection direction) {
if (fluidStack.amount <= 0) {
return;
}
direction = direction.resolve(fluidStack);
final Fluid fluid = fluidStack.getFluid();
direction = direction.resolve(fluid);
final int tankSize = direction.isHorizontal() ? width : height;
final int tankCapacity = capacity > 0 ? capacity : fluidStack.amount;
@@ -59,38 +70,109 @@ public class FluidDrawer {
final int fillHeight = direction.isHorizontal() ? height : Math.min(fillSize, height);
final int fillX = direction == FillDirection.LEFT ? x + width - fillWidth : x;
final int fillY = direction == FillDirection.DOWN ? y : y + height - fillHeight;
GL11.glDisable(GL11.GL_LIGHTING);
drawFluidArea(fluid, fillX, fillY, fillWidth, fillHeight, flowing, direction);
GL11.glEnable(GL11.GL_LIGHTING);
}
/**
* Fills the area with fluid tiles. The tiles start from the side the fluid fills from, so a partial tile ends up at
* the fluid surface.
*/
public static void drawFluidArea(Fluid fluid, int x, int y, int width, int height, boolean flowing,
FillDirection direction) {
direction = direction.resolve(fluid);
final boolean anchorRight = direction == FillDirection.LEFT;
final boolean anchorBottom = direction != FillDirection.DOWN;
final IFluidRenderer renderer = fluidRenderers.get(fluid);
final int color = fluid.getColor(fluidStack);
if (renderer == null) {
drawDefaultFluid(fluid, x, y, width, height, flowing, anchorRight, anchorBottom);
} else {
drawCustomFluid(renderer, fluid, x, y, width, height, anchorRight, anchorBottom);
}
}
private static void drawCustomFluid(IFluidRenderer renderer, Fluid fluid, int x, int y, int width, int height,
boolean anchorRight, boolean anchorBottom) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
GL11.glDisable(GL11.GL_LIGHTING);
final boolean clip = width % 16 != 0 || height % 16 != 0;
if (clip) {
GuiHelper.pushScissorFrame(x, y, width, height);
}
try {
for (int tx = 0; tx < width; tx += 16) {
final int tileX = anchorRight ? x + width - tx - 16 : x + tx;
for (int ty = 0; ty < height; ty += 16) {
final int tileY = anchorBottom ? y + height - ty - 16 : y + ty;
renderer.renderFluid(fluid, tileX, tileY);
}
}
} finally {
if (clip) {
GuiHelper.popScissorFrame();
}
GL11.glPopAttrib();
GL11.glColor4f(1F, 1F, 1F, 1F);
}
}
private static void drawDefaultFluid(Fluid fluid, int x, int y, int width, int height, boolean flowing,
boolean anchorRight, boolean anchorBottom) {
IIcon icon = flowing ? fluid.getFlowingIcon() : null;
if (icon == null) {
icon = fluid.getStillIcon();
}
if (icon == null) {
icon = FluidRegistry.WATER.getStillIcon();
}
if (icon == null) {
return;
}
final int color = fluid.getColor();
final float red = (color >> 16 & 0xFF) / 255F;
final float green = (color >> 8 & 0xFF) / 255F;
final float blue = (color & 0xFF) / 255F;
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
GL11.glColor3f(red, green, blue);
GL11.glColor4f(red, green, blue, 1F);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_LIGHTING);
OpenGlHelper
.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
final double iconMinU = icon.getMinU();
final double iconMaxU = icon.getMaxU();
final double iconMinV = icon.getMinV();
final double iconMaxV = icon.getMaxV();
final Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
for (int tx = 0; tx < fillWidth; tx += 16) {
final int tileWidth = Math.min(16, fillWidth - tx);
for (int tx = 0; tx < width; tx += 16) {
final int tileWidth = Math.min(16, width - tx);
// a cropped tile keeps the texture edge that stays seamless against the neighbouring tile
final double uSize = (icon.getMaxU() - icon.getMinU()) * tileWidth / 16D;
final double uMin = anchorRight ? icon.getMaxU() - uSize : icon.getMinU();
final double uMax = anchorRight ? icon.getMaxU() : icon.getMinU() + uSize;
final int leftX = anchorRight ? fillX + fillWidth - tx - tileWidth : fillX + tx;
final double uSize = (iconMaxU - iconMinU) * tileWidth / 16D;
final double uMin = anchorRight ? iconMaxU - uSize : iconMinU;
final double uMax = anchorRight ? iconMaxU : iconMinU + uSize;
final int leftX = anchorRight ? x + width - tx - tileWidth : x + tx;
final int rightX = leftX + tileWidth;
for (int ty = 0; ty < fillHeight; ty += 16) {
final int tileHeight = Math.min(16, fillHeight - ty);
final double vSize = (icon.getMaxV() - icon.getMinV()) * tileHeight / 16D;
final double vMin = anchorBottom ? icon.getMaxV() - vSize : icon.getMinV();
final double vMax = anchorBottom ? icon.getMaxV() : icon.getMinV() + vSize;
final int bottomY = anchorBottom ? fillY + fillHeight - ty : fillY + ty + tileHeight;
for (int ty = 0; ty < height; ty += 16) {
final int tileHeight = Math.min(16, height - ty);
final double vSize = (iconMaxV - iconMinV) * tileHeight / 16D;
final double vMin = anchorBottom ? iconMaxV - vSize : iconMinV;
final double vMax = anchorBottom ? iconMaxV : iconMinV + vSize;
final int bottomY = anchorBottom ? y + height - ty : y + ty + tileHeight;
final int topY = bottomY - tileHeight;
tessellator.addVertexWithUV(leftX, bottomY, 0, uMin, vMax);
@@ -102,7 +184,6 @@ public class FluidDrawer {
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4f(1F, 1F, 1F, 1F);
}
}
@@ -41,6 +41,7 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
public ItemFluidDisplay() {
setUnlocalizedName("nei.fluidDisplay");
setMaxStackSize(1);
setHasSubtypes(true);
INSTANCE = this;
}
@@ -72,7 +73,7 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
@Override
public FluidStack getFluid(ItemStack stack) {
if (stack == null || !(stack.getItem() instanceof ItemFluidDisplay) || !stack.hasTagCompound()) {
if (stack == null || !(stack.getItem() instanceof ItemFluidDisplay)) {
return null;
}
@@ -85,7 +86,7 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
final NBTTagCompound nbTag = stack.getTagCompound();
final FluidStack fluidStack = new FluidStack(
fluid,
(int) Math.min(nbTag.getLong("neiFluidDisplayAmount"), Integer.MAX_VALUE));
(int) Math.min(nbTag != null ? nbTag.getLong("neiFluidDisplayAmount") : 0, Integer.MAX_VALUE));
return fluidStack;
}
@@ -4,6 +4,7 @@ import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
@@ -35,6 +36,7 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
public static GuiRecipe<?> createRecipeGui(String outputId, boolean open, Object... results) {
final Minecraft mc = NEIClientUtils.mc();
final RecipeId recipeId;
List<ItemStack> pinnedIngredients = null;
for (int i = 0; i < results.length; i++) {
if (results[i] instanceof ItemStack stack) {
@@ -46,6 +48,12 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
recipeId = getRecipeId(mc.currentScreen, (ItemStack) results[0]);
} else if ("recipeId".equals(outputId)) {
recipeId = (RecipeId) results[1];
// optional third argument: ingredients to pin the found recipe with
if (results.length > 2 && results[2] instanceof List<?>list) {
pinnedIngredients = extractIngredients(list);
}
} else {
recipeId = getCurrentRecipeId(mc.currentScreen);
}
@@ -65,13 +73,25 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
mc.displayGuiScreen(gui);
}
gui.openTargetRecipe(recipeId);
gui.openTargetRecipe(recipeId, pinnedIngredients);
return gui;
}
return null;
}
private static List<ItemStack> extractIngredients(List<?> list) {
final List<ItemStack> ingredients = new ArrayList<>(list.size());
for (Object item : list) {
if (item instanceof ItemStack stack) {
ingredients.add(stack);
}
}
return ingredients;
}
public static ArrayList<ICraftingHandler> getCraftingHandlers(String outputId, Object... results) {
ArrayList<ICraftingHandler> craftinghandlers = GuiCraftingRecipe.craftinghandlers;
ArrayList<ICraftingHandler> serialCraftingHandlers = GuiCraftingRecipe.serialCraftingHandlers;
@@ -263,7 +263,7 @@ public class GuiOverlayButton extends GuiRecipeButton {
if (!items.isEmpty()) {
this.missedMaterialsTooltipLineHandler = ItemsTooltipLineHandler
.grid(NEIClientUtils.translate("recipe.overlay.missing"), items, Integer.MAX_VALUE);
.of(NEIClientUtils.translate("recipe.overlay.missing"), items, Integer.MAX_VALUE, 0);
} else {
this.missedMaterialsTooltipLineHandler = null;
}
@@ -8,7 +8,7 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.WeakHashMap;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
@@ -295,73 +295,118 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
}
/**
* Many old mods assumed a fixed NEI window height of {@code 166} pixels. Now that this is no longer the case, their
* tooltip and click zone handling is broken. This helper class fixes these old mods by hacking the {@link #height}
* property's value so that these old mods' calculations return the correct value for the new height.
* Many old mods assumed a fixed NEI window size of {@code 176x166} pixels, with exactly one recipe shown at a time,
* flush against the top-left corner of the window. Now that none of these assumptions hold (the window has a
* flexible size, several recipes can be stacked in the same scrollable list, and the recipe area is inset from the
* window's edges), these old mods' tooltip and click zone handling is broken. This helper class fixes these old
* mods by hacking the {@link #width}, {@link #height}, {@link #guiLeft} and {@link #guiTop} properties' values so
* that these old mods' calculations return the correct value for whichever recipe they are currently being asked
* about.
*
* <p>
* New and old mods often assume that the handler is only drawn when {@link GuiRecipe} is the currently active
* screen in {@link net.minecraft.client.Minecraft}. This is no longer true since the addition of recipe tooltips
* which need to render the recipe in other containers on mouse hover, this class temporarily switches the active
* screen to {@code this} while rendering them to avoid ClassCastExceptions and other similar crashes.
* Since each recipe handled by a {@link RecipeWidget} can sit at a different real position, this must be
* constructed with that widget's top-left edge every time a legacy entry point ({@code mouseClicked},
* {@code handleTooltip}, ...) is invoked for it, rather than once per {@link GuiRecipe}.
*
* <p>
* This class is an {@link AutoCloseable} so that it can be used with try-with-resources, which will ensure that
* {@link #height} and {@link net.minecraft.client.Minecraft#currentScreen} is returned to the correct value
* {@link #width}, {@link #height}, {@link #guiLeft} and {@link #guiTop} are returned to the correct value
* afterwards.
*/
private class CompatibilityHacks implements AutoCloseable {
public static final class CompatibilityHacks implements AutoCloseable {
// The historical NEI recipe screen's fixed size: a single top paging widget 16px tall, no horizontal inset,
// and a 176x166 box. Legacy handlers either read guiLeft/guiTop directly (expecting them to point 16px above
// their recipe, flush on the left) or recompute them from width/height with these same two constants.
private static final int LEGACY_TOP_GAP = 16;
private static final int LEGACY_BOX_WIDTH = 176;
private static final int LEGACY_BOX_HEIGHT = 166;
// layoutWindow() places the recipe container at (guiLeft + 3, guiTop + 32); RecipePageManager then places
// each left-aligned recipe widget another 2px to the right of that. This is the inverse of both, undoing the
// container's own inset so a legacy handler sees its recipe flush with guiLeft as it expects.
private static final int CONTAINER_LEFT_INSET = 3 + 2;
private final GuiRecipe<?> gui;
private final int trueWidth;
private final int trueHeight;
private final int trueGuiLeft;
private final int trueGuiTop;
private CompatibilityHacks() {
trueHeight = height;
trueGuiTop = guiTop;
/**
* @param widget The recipe widget a legacy entry point ({@code mouseClicked}, {@code handleTooltip}, ...) is
* about to be invoked for.
*/
public CompatibilityHacks(GuiRecipe<?> gui, RecipeWidget widget) {
this.gui = gui;
this.trueWidth = gui.width;
this.trueHeight = gui.height;
this.trueGuiLeft = gui.guiLeft;
this.trueGuiTop = gui.guiTop;
isHeightHackApplied = NEIClientConfig.heightHackHandlerRegex.stream()
.map(pattern -> pattern.matcher(handler.original.getHandlerId())).anyMatch(Matcher::matches);
if (isHeightHackApplied) {
// guiTop is the top edge of the recipe screen on the y-axis. Old recipe
// handlers expect a single paging
// widget at the top and at the bottom of the recipe screen with a height of
// 16px each, but GTNH NEI
// moved the bottom paging widget to the top following JEI's design, increasing
// the "forbidden" zone at
// the top to 32px. To fix these old recipe handlers we move guiTop down 16px so
// that they can keep
// working with the old 16px gap.
guiTop += 16;
final String handlerId = gui.handler.original.getHandlerId();
gui.isHeightHackApplied = NEIClientConfig.heightHackHandlerRegex.stream()
.anyMatch(pattern -> pattern.matcher(handlerId).matches());
// The old NEI recipe screen had a fixed width and height and was always
// centered on the screen. Legacy
// recipe handlers use the calculation ((height - 166) / 2) to compute the
// y-value of the top edge of
// the NEI window. GTNH NEI changes the layout so that the recipe screen length
// now has a flexible
// length and is no longer centered vertically. In order for the top-of-screen
// calculation to return the
// correct result, we have to hack the height field with an inverse of the
// calculation using the actual
// top of the recipe screen stored in guiTop.
height = (2 * guiTop) + 166;
// For reference, in case we ever need to modify width as well:
// the legacy calculation used for width is ((width - 176) / 2), which should
// evaluate to be equal to
// guiWidth (the x-value of the left edge of the NEI recipe screen). So if we
// wanted to override width
// as well, we'd do this:
// width = (2 * guiWidth) + 176;
if (gui.isHeightHackApplied) {
gui.guiTop = recipeTop(widget) - LEGACY_TOP_GAP;
gui.guiLeft = widget.x - CONTAINER_LEFT_INSET;
gui.height = (2 * gui.guiTop) + LEGACY_BOX_HEIGHT;
gui.width = (2 * gui.guiLeft) + LEGACY_BOX_WIDTH;
}
}
// recipiesPerPage() == 2 is the IRecipeHandler default: a handler only ends up with this value if it never
// overrode the method, or if it overrode it and chose 2 on purpose. We only care about the latter case, so
// we require the override to actually come from the handler's own class rather than being inherited as-is.
private static final Map<Class<?>, Boolean> overridesRecipiesPerPage = new WeakHashMap<>();
/**
* The real top edge of this widget's recipe, as a legacy handler following the {@link #LEGACY_TOP_GAP}
* convention would expect to find it at guiTop. A few handlers (e.g. ImmersiveEngineering) are left over from
* the old {@code recipiesPerPage() == 2} convention, where two recipes shared one physical page: their own
* {@code mouseClicked}/{@code handleTooltip} still add a hardcoded "recipe height * (recipe % 2)" on top of
* guiTop to find the odd one of the pair. Since every recipe is its own independent widget now, we pre-subtract
* that same offset here so their own addition cancels out and lands back on this widget's real top.
*
* <p>
* This only applies when the handler itself overrides {@link IRecipeHandler#recipiesPerPage()} to return
* {@code 2}: that method defaults to {@code 2} on the interface, so most height-hacked handlers return it
* without ever having implemented this pairing (e.g. BuildCraftCompat never overrides it at all, and only reads
* it elsewhere to pick a cosmetic sub-name), and applying this compensation to them would break them. A handler
* that went out of its way to declare {@code return 2;} itself is making a deliberate statement about this
* legacy convention that a handler which simply never mentions the method isn't.
*/
private static int recipeTop(RecipeWidget widget) {
final RecipeHandlerRef ref = widget.getRecipeHandlerRef();
final HandlerInfo handlerInfo = widget.getHandlerInfo();
final int top = widget.y + handlerInfo.getYShift();
if (ref.handler.recipiesPerPage() == 2 && declaresRecipiesPerPage(ref.handler)) {
return top - handlerInfo.getHeight() * (ref.recipeIndex % 2);
}
return top;
}
private static boolean declaresRecipiesPerPage(IRecipeHandler handler) {
return overridesRecipiesPerPage.computeIfAbsent(handler.getClass(), clazz -> {
try {
return clazz.getMethod("recipiesPerPage").getDeclaringClass() != IRecipeHandler.class;
} catch (NoSuchMethodException e) {
return false;
}
});
}
@Override
public void close() {
guiTop = trueGuiTop;
height = trueHeight;
this.gui.guiLeft = this.trueGuiLeft;
this.gui.guiTop = this.trueGuiTop;
this.gui.width = this.trueWidth;
this.gui.height = this.trueHeight;
isHeightHackApplied = false;
this.gui.isHeightHackApplied = false;
}
}
@@ -524,6 +569,13 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
}
public int openTargetRecipe(RecipeId recipeId) {
return openTargetRecipe(recipeId, null);
}
/**
* @param pinnedIngredients when not null, the found recipe is paused with these ingredients shown
*/
public int openTargetRecipe(RecipeId recipeId, List<ItemStack> pinnedIngredients) {
int recipeIndex = -1;
int recipetype = 0;
@@ -551,6 +603,10 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
setRecipePage(recipetype);
this.handlerPages.gotoRecipeIndex(Math.max(0, recipeIndex));
if (pinnedIngredients != null && recipeIndex >= 0) {
this.handlerPages.pinRecipe(recipeIndex, pinnedIngredients);
}
return recipeIndex;
}
@@ -687,10 +743,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
return;
}
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
if (this.container.handleClick(mousex, mousey, button)) {
return;
}
if (this.container.handleClick(mousex, mousey, button)) {
return;
}
if (this.recipeTabs.mouseClicked(mousex, mousey, button)) {
@@ -738,11 +792,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
public void mouseScrolled(int scroll) {
// Height hacking is not necessary here since mouse scrolling is a new feature,
// added in
// GTNH NEI. So no old mods will use this. Though not hacking the height here
// does mean that
// the value of the height field will be different from in other mouseover
// methods, which
// could be confusing...
// GTNH NEI. So no old mods will use this.
// First, invoke scroll handling over recipe handler tabbar. Makes sure it is
// not overwritten by recipe
@@ -755,10 +805,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
return;
}
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
if (this.container.onMouseWheel(scroll, mouse.x, mouse.y)) {
return;
}
if (this.container.onMouseWheel(scroll, mouse.x, mouse.y)) {
return;
}
// If shift is held, try switching to the next recipe handler. Replicates the
@@ -810,9 +858,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
currenttip = this.recipeCatalyst.handleTooltip(mousex, mousey, currenttip);
}
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
currenttip = this.container.handleTooltip(mousex, mousey, currenttip);
}
currenttip = this.container.handleTooltip(mousex, mousey, currenttip);
this.recipeTabs.handleTooltip(mousex, mousey, currenttip);
@@ -858,9 +904,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
hotkeys = this.recipeCatalyst.handleHotkeys(mousex, mousey, hotkeys);
}
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
hotkeys = this.container.handleHotkeys(mousex, mousey, hotkeys);
}
hotkeys = this.container.handleHotkeys(mousex, mousey, hotkeys);
return hotkeys;
}
@@ -16,11 +16,15 @@ public abstract class GuiRecipeButton extends GuiNEIButton {
public List<GuiRecipeButton> buttonList;
public RecipeHandlerRef handlerRef;
public int width;
public int height;
public UpdateRecipeButtonsEvent(GuiRecipe<?> gui, RecipeHandlerRef handlerRef,
public UpdateRecipeButtonsEvent(GuiRecipe<?> gui, RecipeHandlerRef handlerRef, int width, int height,
List<GuiRecipeButton> buttonList) {
super(gui);
this.handlerRef = handlerRef;
this.width = width;
this.height = height;
this.buttonList = new ArrayList<>(buttonList);
}
@@ -29,16 +33,17 @@ public abstract class GuiRecipeButton extends GuiNEIButton {
public HandlerInfo handlerInfo;
public Pre(GuiRecipe<?> gui, RecipeHandlerRef handlerRef, HandlerInfo handlerInfo) {
super(gui, handlerRef, new ArrayList<>());
public Pre(GuiRecipe<?> gui, RecipeHandlerRef handlerRef, int width, int height, HandlerInfo handlerInfo) {
super(gui, handlerRef, width, height, new ArrayList<>());
this.handlerInfo = handlerInfo;
}
}
public static class Post extends UpdateRecipeButtonsEvent {
public Post(GuiRecipe<?> gui, RecipeHandlerRef handlerRef, List<GuiRecipeButton> buttonList) {
super(gui, handlerRef, buttonList);
public Post(GuiRecipe<?> gui, RecipeHandlerRef handlerRef, int width, int height,
List<GuiRecipeButton> buttonList) {
super(gui, handlerRef, width, height, buttonList);
}
}
}
@@ -21,6 +21,7 @@ import codechicken.nei.ItemStackAmount;
import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.ItemsTooltipLineHandler.StacksAmountRenderer;
import codechicken.nei.ItemsTooltipLineHandler.TotalAmountRenderer;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IGuiContainerOverlay;
@@ -163,9 +164,9 @@ public class RecipeItemsTooltipLineHandler extends CompositeTooltipLineHandler {
protected void addResultLine(List<ItemStack> items, Set<NBTTagCompound> approximate) {
final String label = NEIClientUtils.translate("recipe.items.results");
final ItemsTooltipLineHandler line = items.size() == 1
? ItemsTooltipLineHandler.list(label, items, maxLineRows())
: ItemsTooltipLineHandler.grid(label, items, maxLineRows());
final int maxRows = maxLineRows();
final int maxNamedRows = items.size() == 1 ? NEIClientConfig.getMaxVerticalTooltipRows() : 0;
final ItemsTooltipLineHandler line = ItemsTooltipLineHandler.of(label, items, maxRows, maxNamedRows);
if (line.isEmpty()) {
return;
@@ -188,7 +189,9 @@ public class RecipeItemsTooltipLineHandler extends CompositeTooltipLineHandler {
protected void addRequiredLine(List<ItemStack> items, Set<NBTTagCompound> approximate) {
final String label = NEIClientUtils.translate("recipe.items.ingredients");
final ItemsTooltipLineHandler line = ItemsTooltipLineHandler.list(label, items, maxLineRows());
final int maxRows = maxLineRows();
final int maxNamedRows = NEIClientConfig.getMaxVerticalTooltipRows();
final ItemsTooltipLineHandler line = ItemsTooltipLineHandler.of(label, items, maxRows, maxNamedRows);
if (line.isEmpty()) {
return;
@@ -211,8 +214,9 @@ public class RecipeItemsTooltipLineHandler extends CompositeTooltipLineHandler {
protected void addNeededLine(List<ItemStack> items, Set<NBTTagCompound> approximate, boolean vertical) {
final String label = NEIClientUtils.translate("recipe.items.ingredients_needed");
final ItemsTooltipLineHandler line = vertical ? ItemsTooltipLineHandler.list(label, items, maxLineRows())
: ItemsTooltipLineHandler.grid(label, items, maxLineRows());
final int maxRows = maxLineRows();
final int maxNamedRows = vertical ? NEIClientConfig.getMaxVerticalTooltipRows() : 0;
final ItemsTooltipLineHandler line = ItemsTooltipLineHandler.of(label, items, maxRows, maxNamedRows);
if (line.isEmpty()) {
return;
@@ -6,6 +6,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.item.ItemStack;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.Widget;
import codechicken.nei.recipe.widget.RecipeWidget;
@@ -42,6 +44,8 @@ public class RecipePageManager {
}
this.cacheKey = cacheKey;
final List<RecipeWidget> pausedWidgets = getPausedWidgets();
this.pageWidgets.clear();
final boolean allowOverflowY = this.handlerInfo.isAllowOverflowY();
@@ -76,6 +80,15 @@ public class RecipePageManager {
for (int groupIndex = 0; groupIndex < groupedRecipes.size(); groupIndex++) {
final RecipeWidget widget = new RecipeWidget(this.handler.original, groupedRecipes.get(groupIndex));
// keep the pause of the rebuilt widgets
for (RecipeWidget paused : pausedWidgets) {
final int pausedIndex = paused.getRecipeHandlerRef().recipeIndex;
if (widget.containsRecipeIndex(pausedIndex)) {
widget.pinRecipe(pausedIndex, paused.getPinnedIngredients());
}
}
widget.w = width;
if (allowOverflowY) {
@@ -144,6 +157,33 @@ public class RecipePageManager {
return false;
}
private List<RecipeWidget> getPausedWidgets() {
final List<RecipeWidget> paused = new ArrayList<>();
for (List<Widget> widgets : this.pageWidgets) {
for (Widget widget : widgets) {
if (widget instanceof RecipeWidget recipeWidget && recipeWidget.isPaused()) {
paused.add(recipeWidget);
}
}
}
return paused;
}
public boolean pinRecipe(int recipeIndex, List<ItemStack> ingredients) {
for (List<Widget> widgets : this.pageWidgets) {
for (Widget widget : widgets) {
if (widget instanceof RecipeWidget recipeWidget && recipeWidget.containsRecipeIndex(recipeIndex)) {
return recipeWidget.pinRecipe(recipeIndex, ingredients);
}
}
}
return false;
}
public List<Widget> getCurrentPageWidgets() {
if (this.pageWidgets.isEmpty()) {
return Collections.emptyList();
@@ -131,7 +131,14 @@ public class StackInfo {
}
if (isFluidDisplayItem(stackA)) {
return isFluidDisplayItem(stackB) && getFluid(stackA).isFluidEqual(getFluid(stackB));
if (isFluidDisplayItem(stackB)) {
final FluidStack fluidA = getFluid(stackA);
final FluidStack fluidB = getFluid(stackB);
return fluidA != null && fluidA.isFluidEqual(fluidB);
}
return false;
}
if (stackA.getItem() != stackB.getItem()) {
@@ -25,6 +25,7 @@ import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.ItemsTooltipLineHandler.AmountRenderer;
import codechicken.nei.ItemsTooltipLineHandler.StacksAmountRenderer;
import codechicken.nei.ItemsTooltipLineHandler.TotalAmountRenderer;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.bookmark.BookmarkItem;
import codechicken.nei.drawable.DrawableResource;
@@ -354,8 +355,8 @@ public class RecipeChainTooltipLineHandler extends CompositeTooltipLineHandler {
protected void addLine(String label, List<ItemStack> items, boolean vertical, EnumChatFormatting labelColor,
AmountRenderer amountRenderer) {
final ItemsTooltipLineHandler line = vertical ? ItemsTooltipLineHandler.list(label, items, maxLineRows())
: ItemsTooltipLineHandler.grid(label, items, maxLineRows());
final int maxNamedRows = vertical ? NEIClientConfig.getMaxVerticalTooltipRows() : 0;
final ItemsTooltipLineHandler line = ItemsTooltipLineHandler.of(label, items, maxLineRows(), maxNamedRows);
if (line.isEmpty()) {
return;
@@ -21,6 +21,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
protected static Method getFluidFromDisplayStack = null;
protected static Class<?> gtMetaGeneratedTool = null;
protected static Field playSound = null;
private static boolean loggedNoNbtDisplay = false;
static {
try {
@@ -88,6 +89,12 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
return (FluidStack) obj;
}
final Fluid fluid = FluidRegistry.getFluid(stack.getItemDamage());
if (fluid != null) {
return new FluidStack(fluid, 0);
}
} else if (item == GameRegistry.findItem("ae2fc", "fluid_packet")) {
NBTTagCompound nbtTag = stack.getTagCompound();
@@ -1,6 +1,7 @@
package codechicken.nei.recipe.widget;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@@ -50,6 +51,11 @@ public class PermutationsCycler<K> {
return false;
}
public void invalidate() {
this.favoriteRevision = -1;
validate();
}
public boolean contains(K key) {
validate();
return this.permutations.containsKey(key);
@@ -79,6 +85,11 @@ public class PermutationsCycler<K> {
return items;
}
public int getFavoriteCount(K key) {
get(key);
return this.favoriteCounts.getOrDefault(key, 0);
}
public ItemStack getCycled(K key, int cycle) {
final List<ItemStack> items = get(key);
final int favoriteCount = this.favoriteCounts.getOrDefault(key, 0);
@@ -96,4 +107,10 @@ public class PermutationsCycler<K> {
return -1;
}
// Hash key with the same equality as NEIServerUtils.areStacksSameType
public static Object getStackKey(ItemStack stack) {
return Arrays
.asList(stack.getItem(), stack.getHasSubtypes() ? stack.getItemDamage() : 0, stack.stackTagCompound);
}
}
@@ -2,23 +2,109 @@ package codechicken.nei.recipe.widget;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import codechicken.nei.FavoriteRecipes;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.HandlerInfo;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.StackInfo;
public class RecipeGroup {
// position and items of a stack at load time, the handler may change the stack later
protected static class StackState {
public final int relx;
public final int rely;
public final ItemStack[] items;
public StackState(PositionedStack pStack) {
this.relx = pStack.relx;
this.rely = pStack.rely;
this.items = pStack.items;
}
}
// filtered permutations of a slot, favorites first, with their indices in PositionedStack.items
protected static class FilteredSlot {
public final List<ItemStack> items;
public final int[] indices;
public final int favoriteCount;
public FilteredSlot(PositionedStack pStack) {
this.items = pStack.getFilteredPermutations();
this.indices = new int[this.items.size()];
// filtering keeps the original instances, so an identity lookup finds the source index
for (int i = 0; i < this.indices.length; i++) {
this.indices[i] = indexOfInstance(pStack.items, this.items.get(i));
}
int favoriteCount = 0;
while (this.items.size() > 1 && favoriteCount < this.items.size()
&& FavoriteRecipes.containsManual(this.items.get(favoriteCount))) {
favoriteCount++;
}
this.favoriteCount = favoriteCount;
}
private static int indexOfInstance(ItemStack[] items, ItemStack stack) {
for (int i = 0; i < items.length; i++) {
if (items[i] == stack) {
return i;
}
}
return 0;
}
}
protected static class MemberStacks {
public final List<PositionedStack> inputs;
public final List<PositionedStack> outputs;
public final List<PositionedStack> auxiliaries;
public final List<PositionedStack> cycling;
public final List<StackState> states = new ArrayList<>();
public final Map<Point, PositionedStack> slots = new HashMap<>();
public final Map<Point, FilteredSlot> filtered = new HashMap<>();
public MemberStacks(List<PositionedStack> inputs, List<PositionedStack> outputs,
List<PositionedStack> auxiliaries) {
this.inputs = inputs;
this.outputs = outputs;
this.auxiliaries = auxiliaries;
if (auxiliaries.isEmpty()) {
this.cycling = inputs;
} else {
this.cycling = new ArrayList<>(inputs);
this.cycling.addAll(auxiliaries);
}
for (PositionedStack pStack : this.cycling) {
this.slots.putIfAbsent(new Point(pStack.relx, pStack.rely), pStack);
}
for (PositionedStack pStack : inputs) this.states.add(new StackState(pStack));
for (PositionedStack pStack : outputs) this.states.add(new StackState(pStack));
for (PositionedStack pStack : auxiliaries) this.states.add(new StackState(pStack));
}
}
private static final List<Integer> SINGLE_MEMBER = Collections.singletonList(0);
private final IRecipeHandler handler;
@@ -26,16 +112,33 @@ public class RecipeGroup {
private final HandlerInfo handlerInfo;
private final PermutationsCycler<Point> slotPermutations;
private final MemberStacks[] memberStacks;
private Map<Point, PositionedStack[]> slotStacks = null;
private final Set<Point> sharedSlots = new HashSet<>();
private List<Integer> allowedMembers = null;
private Boolean cycling = null;
public RecipeGroup(IRecipeHandler handler, List<Integer> recipeIndices) {
this.handler = handler;
this.recipeIndices = new ArrayList<>(recipeIndices);
this.handlerInfo = GuiRecipeTab.getHandlerInfo(handler);
this.memberStacks = new MemberStacks[this.recipeIndices.size()];
this.slotPermutations = new PermutationsCycler<Point>(
new HashMap<>(),
new HashMap<>(),
this::collectSlotPermutations).onInvalidate(() -> this.allowedMembers = null);
this::collectSlotPermutations).onInvalidate(() -> {
this.allowedMembers = null;
this.cycling = null;
this.slotStacks = null;
for (MemberStacks stacks : this.memberStacks) {
if (stacks != null) {
stacks.filtered.clear();
}
}
this.sharedSlots.clear();
});
}
public int size() {
@@ -58,34 +161,49 @@ public class RecipeGroup {
return this.recipeIndices.contains(recipeIndex);
}
public int indexOf(int recipeIndex) {
return this.recipeIndices.indexOf(recipeIndex);
}
public List<ItemStack> getPermutations(Point slotKey) {
return this.slotPermutations.get(slotKey);
}
public boolean hasPermutation(int member, Point slotKey, ItemStack stack) {
this.slotPermutations.validate();
if (stack == null) {
return false;
}
final List<ItemStack> permutations = getFilteredPermutations(member, slotKey);
return permutations != null && PermutationsCycler.indexOf(permutations, stack) != -1;
}
// the given member if it has the item in the slot, otherwise the next member that has it
public int findMember(Point slotKey, ItemStack stack, int from) {
for (int step = 0; step < size(); step++) {
final int member = (from + step) % size();
if (hasPermutation(member, slotKey, stack)) {
return member;
}
}
return -1;
}
public List<PositionedStack> getInputs(int member) {
return this.handler.getIngredientStacks(getRecipeIndex(member));
return getStacks(member).inputs;
}
public List<PositionedStack> getOutputs(int member) {
final int recipeIndex = getRecipeIndex(member);
final PositionedStack pStackResult = this.handler.getResultStack(recipeIndex);
return pStackResult != null ? Arrays.asList(pStackResult) : this.handler.getOtherStacks(recipeIndex);
}
public List<PositionedStack> getCatalysts(int member) {
final int recipeIndex = getRecipeIndex(member);
if (this.handler.getResultStack(recipeIndex) == null) {
return Collections.emptyList();
}
return this.handler.getOtherStacks(recipeIndex);
return getStacks(member).outputs;
}
public List<PositionedStack> getCyclingStacks(int member) {
final List<PositionedStack> stacks = new ArrayList<>(getInputs(member));
stacks.addAll(getCatalysts(member));
return stacks;
return getStacks(member).cycling;
}
public Point getSlotKey(PositionedStack pStack) {
@@ -93,39 +211,108 @@ public class RecipeGroup {
}
public PositionedStack getSlot(int member, Point slotKey) {
for (PositionedStack pStack : getCyclingStacks(member)) {
if (pStack.relx == slotKey.x && pStack.rely == slotKey.y) {
return pStack;
}
}
return null;
return getStacks(member).slots.get(slotKey);
}
public PositionedStack getOutputSlot(int member, Point slotKey) {
protected MemberStacks getStacks(int member) {
for (PositionedStack pStack : getOutputs(member)) {
if (pStack.relx == slotKey.x && pStack.rely == slotKey.y) {
return pStack;
}
if (this.memberStacks[member] == null) {
this.memberStacks[member] = loadStacks(member);
}
return null;
return this.memberStacks[member];
}
public List<ItemStack> getOutputVariants(Point slotKey) {
final List<ItemStack> items = new ArrayList<>();
protected MemberStacks loadStacks(int member) {
final int recipeIndex = getRecipeIndex(member);
final List<PositionedStack> inputs = new ArrayList<>(this.handler.getIngredientStacks(recipeIndex));
final PositionedStack pStackResult = this.handler.getResultStack(recipeIndex);
final List<PositionedStack> others = new ArrayList<>(this.handler.getOtherStacks(recipeIndex));
for (int member = 0; member < size(); member++) {
final PositionedStack slot = getOutputSlot(member, slotKey);
if (pStackResult != null) {
return new MemberStacks(inputs, Collections.singletonList(pStackResult), others);
}
if (slot != null && PermutationsCycler.indexOf(items, slot.item) == -1) {
items.add(slot.item);
return new MemberStacks(inputs, others, Collections.emptyList());
}
// re-reads the member stacks from the handler, keeps the cached instances when nothing changed
public void refresh(int member) {
if (this.memberStacks[member] == null) {
return;
}
final MemberStacks stacks = loadStacks(member);
if (!isSameStacks(this.memberStacks[member], stacks)) {
this.memberStacks[member] = stacks;
this.slotPermutations.invalidate();
}
}
// index into PositionedStack.items of the permutation to render, -1 when the slot is unknown
public int getCycledPermutationIndex(int member, Point slotKey, int index) {
this.slotPermutations.validate();
final FilteredSlot filtered = getFilteredSlot(member, slotKey);
if (filtered == null || filtered.indices.length == 0) {
return -1;
}
final int size = filtered.favoriteCount > 0 ? filtered.favoriteCount : filtered.indices.length;
return filtered.indices[index % size];
}
protected boolean isSameStacks(MemberStacks stacksA, MemberStacks stacksB) {
if (stacksA.inputs.size() != stacksB.inputs.size() || stacksA.outputs.size() != stacksB.outputs.size()
|| stacksA.auxiliaries.size() != stacksB.auxiliaries.size()) {
return false;
}
for (int i = 0; i < stacksA.states.size(); i++) {
final StackState stateA = stacksA.states.get(i);
final StackState stateB = stacksB.states.get(i);
if (stateA.relx != stateB.relx || stateA.rely != stateB.rely || !isSameItems(stateA.items, stateB.items)) {
return false;
}
}
return items;
return true;
}
protected boolean isSameItems(ItemStack[] itemsA, ItemStack[] itemsB) {
if (itemsA == itemsB) {
return true;
}
if (itemsA.length != itemsB.length) {
return false;
}
for (int i = 0; i < itemsA.length; i++) {
if (!isSameStack(itemsA[i], itemsB[i])) {
return false;
}
}
return true;
}
// true when the group has something to cycle: several members or a slot with several permutations
public boolean canCycle() {
this.slotPermutations.validate();
if (this.cycling == null) {
this.cycling = size() > 1 || getStacks(0).slots.keySet().stream()
.anyMatch(slotKey -> getFilteredPermutations(0, slotKey).size() > 1);
}
return this.cycling;
}
public List<Integer> getAllowedMembers() {
@@ -135,17 +322,20 @@ public class RecipeGroup {
return SINGLE_MEMBER;
}
if (this.allowedMembers == null) {
final Set<Point> favoriteSlots = new HashSet<>();
if (this.allowedMembers == null && !FavoriteRecipes.hasManual()) {
this.allowedMembers = new ArrayList<>(size());
for (int member = 0; member < size(); member++) {
for (PositionedStack pStack : getCyclingStacks(member)) {
final Point slotKey = getSlotKey(pStack);
final List<ItemStack> items = getPermutations(slotKey);
this.allowedMembers.add(member);
}
if (items.size() > 1 && items.stream().anyMatch(FavoriteRecipes::containsManual)) {
favoriteSlots.add(slotKey);
}
} else if (this.allowedMembers == null) {
final Set<Point> favoriteSlots = new HashSet<>();
for (Point slotKey : getSlotStacks().keySet()) {
// a shared slot gives every member the same misses, so it can't affect the filter
if (!this.sharedSlots.contains(slotKey) && this.slotPermutations.getFavoriteCount(slotKey) > 0) {
favoriteSlots.add(slotKey);
}
}
@@ -155,6 +345,72 @@ public class RecipeGroup {
return this.allowedMembers;
}
protected Map<Point, PositionedStack[]> getSlotStacks() {
if (this.slotStacks == null) {
this.slotStacks = new LinkedHashMap<>();
for (int member = 0; member < size(); member++) {
for (PositionedStack pStack : getCyclingStacks(member)) {
final PositionedStack[] stacks = this.slotStacks
.computeIfAbsent(getSlotKey(pStack), key -> new PositionedStack[size()]);
if (stacks[member] == null) {
stacks[member] = pStack;
}
}
}
for (Map.Entry<Point, PositionedStack[]> entry : this.slotStacks.entrySet()) {
if (isSharedSlot(entry.getValue())) {
this.sharedSlots.add(entry.getKey());
}
}
}
return this.slotStacks;
}
// all members hold the same permutations in this slot
protected boolean isSharedSlot(PositionedStack[] stacks) {
ItemStack[] first = null;
for (PositionedStack pStack : stacks) {
if (pStack == null) {
continue;
}
if (first == null) {
first = pStack.items;
} else if (!isSameItems(first, pStack.items)) {
return false;
}
}
return true;
}
protected boolean isSameStack(ItemStack stackA, ItemStack stackB) {
return stackA == stackB || NEIServerUtils.areStacksSameType(stackA, stackB)
&& StackInfo.getAmount(stackA) == StackInfo.getAmount(stackB);
}
protected List<ItemStack> getFilteredPermutations(int member, Point slotKey) {
final FilteredSlot filtered = getFilteredSlot(member, slotKey);
return filtered != null ? filtered.items : null;
}
protected FilteredSlot getFilteredSlot(int member, Point slotKey) {
final MemberStacks stacks = getStacks(member);
final PositionedStack slot = stacks.slots.get(slotKey);
if (slot == null) {
return null;
}
return stacks.filtered.computeIfAbsent(slotKey, key -> new FilteredSlot(slot));
}
protected List<Integer> filterMembers(Set<Point> favoriteSlots) {
final List<Integer> indices = new ArrayList<>();
int minMisses = Integer.MAX_VALUE;
@@ -179,9 +435,9 @@ public class RecipeGroup {
int misses = 0;
for (Point slotKey : favoriteSlots) {
final PositionedStack slot = getSlot(member, slotKey);
final List<ItemStack> permutations = getFilteredPermutations(member, slotKey);
if (slot != null && slot.getFilteredPermutations().stream().noneMatch(FavoriteRecipes::containsManual)) {
if (permutations != null && permutations.stream().noneMatch(FavoriteRecipes::containsManual)) {
misses++;
}
}
@@ -190,21 +446,31 @@ public class RecipeGroup {
}
protected List<ItemStack> collectSlotPermutations(Point slotKey) {
final List<ItemStack> items = new ArrayList<>();
if (!getSlotStacks().containsKey(slotKey)) {
return Collections.emptyList();
}
final Map<Object, ItemStack> items = new LinkedHashMap<>();
final boolean shared = this.sharedSlots.contains(slotKey);
for (int member = 0; member < size(); member++) {
final PositionedStack slot = getSlot(member, slotKey);
final List<ItemStack> permutations = getFilteredPermutations(member, slotKey);
if (slot != null) {
for (ItemStack stack : slot.getFilteredPermutations()) {
if (PermutationsCycler.indexOf(items, stack) == -1) {
items.add(stack);
if (permutations != null) {
for (ItemStack stack : permutations) {
if (stack != null) {
items.putIfAbsent(PermutationsCycler.getStackKey(stack), stack);
}
}
if (shared) {
break;
}
}
}
return items;
return new ArrayList<>(items.values());
}
}
@@ -2,6 +2,7 @@ package codechicken.nei.recipe.widget;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -21,7 +22,6 @@ import org.lwjgl.opengl.GL12;
import codechicken.lib.gui.GuiDraw;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.FavoriteRecipes;
import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.KeyManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
@@ -29,6 +29,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.Widget;
import codechicken.nei.api.IGuiContainerOverlay;
import codechicken.nei.api.ShortcutInputHandler;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler;
import codechicken.nei.recipe.Badge;
@@ -47,28 +49,35 @@ import codechicken.nei.util.NEIMouseUtils;
public class RecipeWidget extends Widget {
protected static final int TICKS_PER_CYCLE = 20;
protected static final DrawableResource PAUSE_MARKER = new DrawableBuilder(
"nei:textures/pinned_pause.png",
0,
0,
8,
8).setTextureSize(8, 8).build();
protected static final int PAUSE_MARKER_OFFSET = 1;
protected final RecipeGroup group;
protected final IRecipeHandler handler;
protected final HandlerInfo handlerInfo;
protected final PermutationsCycler<PositionedStack> renderPermutations;
protected final Map<PositionedStack, List<Badge>> badgeCache = new WeakHashMap<>();
protected final Map<Integer, List<GuiRecipeButton>> buttonCache = new HashMap<>();
protected AcceptsFollowingTooltipLineHandler acceptsTooltip;
protected ItemsTooltipLineHandler variantsTooltip;
protected Point variantsSlotKey;
protected int activeMember = 0;
protected int memberCursor = -1;
protected int slotCycle = 0;
// single state counter: member = allowed[cycle % size], permutation index = cycle / size
protected int cycle = 0;
protected int cycleticks = 0;
protected int lastcycle = -1;
protected int favoriteRevision = FavoriteRecipes.getRevision();
protected boolean showAsWidget = false;
protected boolean update = true;
protected boolean paused = false;
protected List<ItemStack> pinnedIngredients = null;
protected Map<Point, ItemStack> pinnedSlots = Collections.emptyMap();
public RecipeWidget(RecipeHandlerRef handlerRef) {
this(handlerRef.handler, Collections.singletonList(handlerRef.recipeIndex));
@@ -82,13 +91,6 @@ public class RecipeWidget extends Widget {
this.group = group;
this.handler = group.getHandler();
this.handlerInfo = group.getHandlerInfo();
this.renderPermutations = new PermutationsCycler<PositionedStack>(
new WeakHashMap<>(),
new WeakHashMap<>(),
PositionedStack::getFilteredPermutations).onInvalidate(() -> {
this.badgeCache.clear();
this.acceptsTooltip = null;
});
update();
}
@@ -117,6 +119,104 @@ public class RecipeWidget extends Widget {
this.showAsWidget = show;
}
public boolean isPaused() {
return this.paused;
}
public List<ItemStack> getPinnedIngredients() {
return this.pinnedIngredients;
}
public void setPaused(boolean paused) {
final boolean wasPaused = this.paused;
this.paused = paused && this.group.canCycle();
if (!this.paused) {
this.pinnedIngredients = null;
this.pinnedSlots = Collections.emptyMap();
if (wasPaused) {
syncCycle();
}
}
}
/**
* Pauses the widget on the recipe. Every given ingredient needs an input slot of its own that accepts it, otherwise
* the recipe is not pinned.
*/
public boolean pinRecipe(int recipeIndex, List<ItemStack> ingredients) {
final int member = this.group.indexOf(recipeIndex);
if (member < 0 || !this.group.canCycle()) {
return false;
}
final Map<Point, ItemStack> slots = ingredients != null
? matchIngredients(this.group.getInputs(member), ingredients)
: Collections.emptyMap();
if (slots == null) {
return false;
}
this.pinnedIngredients = ingredients;
this.pinnedSlots = slots;
this.paused = true;
setActiveMember(member);
updatePermutations();
return true;
}
// assigns each ingredient to its own slot (bipartite matching), null when some ingredient has no slot
private Map<Point, ItemStack> matchIngredients(List<PositionedStack> stacks, List<ItemStack> ingredients) {
final int[] slotOwners = new int[stacks.size()];
Arrays.fill(slotOwners, -1);
for (int ingredient = 0; ingredient < ingredients.size(); ingredient++) {
if (!assignIngredient(ingredient, stacks, ingredients, slotOwners, new boolean[stacks.size()])) {
return null;
}
}
final Map<Point, ItemStack> slots = new HashMap<>();
for (int slot = 0; slot < slotOwners.length; slot++) {
if (slotOwners[slot] != -1) {
slots.put(this.group.getSlotKey(stacks.get(slot)), ingredients.get(slotOwners[slot]));
}
}
return slots;
}
private boolean assignIngredient(int ingredient, List<PositionedStack> stacks, List<ItemStack> ingredients,
int[] slotOwners, boolean[] visited) {
for (int slot = 0; slot < stacks.size(); slot++) {
if (!visited[slot] && stacks.get(slot).getPermutationIndex(ingredients.get(ingredient)) != -1) {
visited[slot] = true;
if (slotOwners[slot] == -1
|| assignIngredient(slotOwners[slot], stacks, ingredients, slotOwners, visited)) {
slotOwners[slot] = ingredient;
return true;
}
}
}
return false;
}
private void applyPinnedIngredient(PositionedStack pStack) {
final ItemStack ingredient = this.pinnedSlots.get(this.group.getSlotKey(pStack));
if (ingredient != null) {
pStack.setPermutationToRender(ingredient);
}
}
@Override
public void update() {
@@ -142,11 +242,11 @@ public class RecipeWidget extends Widget {
return this.buttonCache.computeIfAbsent(this.activeMember, this::createButtons);
}
protected List<GuiRecipeButton> getRecipeButtonsIfInit() {
private List<GuiRecipeButton> getRecipeButtonsIfInit() {
return this.buttonCache.getOrDefault(this.activeMember, Collections.emptyList());
}
protected List<GuiRecipeButton> createButtons(int member) {
private List<GuiRecipeButton> createButtons(int member) {
if (this.group.getOutputs(member).isEmpty()) {
return Collections.emptyList();
@@ -156,13 +256,15 @@ public class RecipeWidget extends Widget {
.unmodifiableList(initButtons(RecipeHandlerRef.of(this.handler, this.group.getRecipeIndex(member))));
}
protected List<GuiRecipeButton> initButtons(RecipeHandlerRef ref) {
private List<GuiRecipeButton> initButtons(RecipeHandlerRef ref) {
final GuiRecipe<?> guiRecipe = getGuiRecipe();
if (guiRecipe != null) {
final UpdateRecipeButtonsEvent.Pre preEvent = new UpdateRecipeButtonsEvent.Pre(
guiRecipe,
ref,
this.w,
this.h,
this.handlerInfo);
if (MinecraftForge.EVENT_BUS.post(preEvent)) {
@@ -171,6 +273,8 @@ public class RecipeWidget extends Widget {
final UpdateRecipeButtonsEvent.Post postEvent = new UpdateRecipeButtonsEvent.Post(
guiRecipe,
ref,
this.w,
this.h,
getDefaultButtons(ref));
MinecraftForge.EVENT_BUS.post(postEvent);
return postEvent.buttonList;
@@ -182,7 +286,7 @@ public class RecipeWidget extends Widget {
}
protected List<GuiRecipeButton> getDefaultButtons(RecipeHandlerRef ref) {
private List<GuiRecipeButton> getDefaultButtons(RecipeHandlerRef ref) {
GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final List<GuiRecipeButton> buttons = new ArrayList<>();
final boolean showFavorites = NEIClientConfig.favoritesEnabled() && handlerInfo.getShowFavoritesButton();
@@ -213,13 +317,17 @@ public class RecipeWidget extends Widget {
if (this.update) {
this.update = false;
if (tickCycle()) {
if (this.showAsWidget || !contains(mouseX, mouseY)) {
nextMember();
}
updatePermutations(this.lastcycle);
if (this.lastcycle == -1) {
this.lastcycle = 0;
applyCycle();
} else if (tickCycle() && !isCycleFrozen(mouseX, mouseY)) {
this.cycle++;
applyCycle();
} else if (this.favoriteRevision != FavoriteRecipes.getRevision()) {
this.favoriteRevision = FavoriteRecipes.getRevision();
this.badgeCache.clear();
this.acceptsTooltip = null;
updatePermutations();
}
for (GuiRecipeButton button : getRecipeButtons()) {
@@ -240,21 +348,7 @@ public class RecipeWidget extends Widget {
GuiContainerManager.enableMatrixStackLogging();
for (PositionedStack pStack : getInputs()) {
if (!this.renderPermutations.contains(pStack)) {
updatePermutationsFor(pStack);
}
drawItem(pStack, mouseX, mouseY, yShift, true);
}
for (PositionedStack pStack : getCatalysts()) {
if (!this.renderPermutations.contains(pStack)) {
updatePermutationsFor(pStack);
}
for (PositionedStack pStack : getCyclingStacks()) {
drawItem(pStack, mouseX, mouseY, yShift, true);
}
@@ -279,6 +373,10 @@ public class RecipeWidget extends Widget {
GL11.glTranslatef(-this.x, -this.y - yShift, 0);
GL11.glPopAttrib();
if (this.paused) {
NEIClientUtils.gl2DRenderContext(this::drawPauseMarker);
}
if (!this.showAsWidget) {
final Minecraft mc = NEIClientUtils.mc();
for (GuiRecipeButton button : getRecipeButtons()) {
@@ -293,7 +391,22 @@ public class RecipeWidget extends Widget {
DebugHandlerWidget.instance.drawGuiPlaceholder(this);
}
protected void drawItem(PositionedStack pStack, int mouseX, int mouseY, int yShift, boolean input) {
private void drawPauseMarker() {
GL11.glColor4f(1, 1, 1, 1);
PAUSE_MARKER.draw(this.x + PAUSE_MARKER_OFFSET, this.y + PAUSE_MARKER_OFFSET);
}
private boolean isPauseMarkerMouseOver(int mouseX, int mouseY) {
final int left = this.x + PAUSE_MARKER_OFFSET;
final int top = this.y + PAUSE_MARKER_OFFSET;
return this.paused && mouseX >= left
&& mouseX < left + PAUSE_MARKER.getWidth()
&& mouseY >= top
&& mouseY < top + PAUSE_MARKER.getHeight();
}
private void drawItem(PositionedStack pStack, int mouseX, int mouseY, int yShift, boolean input) {
pStack.draw(mouseX - this.x, mouseY - this.y - yShift);
if (this.handlerInfo.getShowBadge()) {
@@ -306,7 +419,7 @@ public class RecipeWidget extends Widget {
}
}
protected List<Badge> getBadges(PositionedStack pStack, boolean input) {
private List<Badge> getBadges(PositionedStack pStack, boolean input) {
return this.badgeCache.computeIfAbsent(pStack, k -> {
final List<Badge> badges = k.getBadges();
@@ -335,7 +448,7 @@ public class RecipeWidget extends Widget {
}
protected void drawBadge(PositionedStack pStack, boolean input) {
private void drawBadge(PositionedStack pStack, boolean input) {
final List<Badge> badges = getBadges(pStack, input);
for (Badge badge : badges) {
@@ -353,6 +466,7 @@ public class RecipeWidget extends Widget {
if (hovered != null && getPermutations(hovered).size() > 1) {
FavoriteRecipes.toggleFavoriteItem(hovered.item);
setPaused(false);
return true;
}
@@ -379,6 +493,12 @@ public class RecipeWidget extends Widget {
@Override
public boolean handleClick(int mouseX, int mouseY, int button) {
if (button == 0 && isPauseMarkerMouseOver(mouseX, mouseY)) {
NEIClientUtils.playClickSound();
setPaused(false);
return true;
}
if (ShortcutInputHandler.handleMouseClick(getStackMouseOver(mouseX, mouseY))) {
return true;
}
@@ -406,7 +526,9 @@ public class RecipeWidget extends Widget {
return false;
}
return this.handler.mouseClicked(guiRecipe, button, getRecipeIndex());
try (GuiRecipe.CompatibilityHacks hack = new GuiRecipe.CompatibilityHacks(guiRecipe, this)) {
return this.handler.mouseClicked(guiRecipe, button, getRecipeIndex());
}
}
@Override
@@ -417,6 +539,11 @@ public class RecipeWidget extends Widget {
return tooltip;
}
if (isPauseMarkerMouseOver(mouseX, mouseY)) {
tooltip.add(NEIClientUtils.translate("recipe.pinned"));
return tooltip;
}
final List<String> buttonTooltip = forEachButtons(
button -> button.contains(mouseX, mouseY) ? button.handleTooltip(tooltip) : null,
null);
@@ -425,7 +552,9 @@ public class RecipeWidget extends Widget {
return buttonTooltip;
}
return this.handler.handleTooltip(guiRecipe, tooltip, getRecipeIndex());
try (GuiRecipe.CompatibilityHacks hack = new GuiRecipe.CompatibilityHacks(guiRecipe, this)) {
return this.handler.handleTooltip(guiRecipe, tooltip, getRecipeIndex());
}
}
@Override
@@ -477,30 +606,6 @@ public class RecipeWidget extends Widget {
tooltip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.acceptsTooltip));
}
final Point outputKey = cycling == null && hovered != null && this.group.size() > 1
? this.group.getSlotKey(hovered)
: null;
if (outputKey == null || !NEIClientConfig.showCycledIngredientsTooltip()) {
this.variantsTooltip = null;
this.variantsSlotKey = null;
} else if (!outputKey.equals(this.variantsSlotKey)) {
final List<ItemStack> variants = this.group.getOutputVariants(outputKey);
this.variantsSlotKey = outputKey;
this.variantsTooltip = variants.size() > 1
? new ItemsTooltipLineHandler(NEIClientUtils.translate("recipe.group"), variants, false, 4)
: null;
if (this.variantsTooltip != null) {
this.variantsTooltip.setActiveStack(hovered.item);
}
}
if (this.variantsTooltip != null) {
tooltip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.variantsTooltip));
}
return tooltip;
}
@@ -559,7 +664,7 @@ public class RecipeWidget extends Widget {
return guiRecipe != null && this.handler.mouseScrolled(guiRecipe, scroll, getRecipeIndex());
}
protected boolean scrollPermutations(int scroll, PositionedStack hovered) {
private boolean scrollPermutations(int scroll, PositionedStack hovered) {
final Point slotKey = this.group.getSlotKey(hovered);
final List<ItemStack> items = this.group.getPermutations(slotKey);
@@ -567,46 +672,23 @@ public class RecipeWidget extends Widget {
return false;
}
final List<PositionedStack> slots = new ArrayList<>(this.group.size());
final int current = Math.max(0, PermutationsCycler.indexOf(items, hovered.item));
final int direction = scroll > 0 ? -1 : 1;
for (int member = 0; member < this.group.size(); member++) {
slots.add(this.group.getSlot(member, slotKey));
}
final int anchor = getCursorMember();
final int currentItem = PermutationsCycler.indexOf(items, hovered.item);
final List<int[]> variants = new ArrayList<>();
int current = 0;
for (int itemIndex = 0; itemIndex < items.size(); itemIndex++) {
final ItemStack stack = items.get(itemIndex);
int member = containsStack(slots.get(this.activeMember), stack) ? this.activeMember : -1;
for (int offset = 0; member == -1 && offset < slots.size(); offset++) {
if (containsStack(slots.get((anchor + offset) % slots.size()), stack)) {
member = (anchor + offset) % slots.size();
}
}
for (int step = 1; step <= items.size(); step++) {
final ItemStack stack = items.get(Math.floorMod(current + direction * step, items.size()));
final int member = this.group.findMember(slotKey, stack, this.activeMember);
if (member != -1) {
if (itemIndex == currentItem) {
current = variants.size();
}
variants.add(new int[] { itemIndex, member });
switchMember(member, stack);
return true;
}
}
if (variants.isEmpty()) {
return false;
}
final int[] next = variants.get(((current - scroll) % variants.size() + variants.size()) % variants.size());
switchMember(next[1], items.get(next[0]));
return true;
return false;
}
protected boolean scrollMembers(int scroll) {
private boolean scrollMembers(int scroll) {
final int size = this.group.size();
if (size <= 1) {
@@ -618,14 +700,19 @@ public class RecipeWidget extends Widget {
return true;
}
protected void switchMember(int member, ItemStack stack) {
private void switchMember(int member, ItemStack stack) {
final Map<Point, ItemStack> rendered = new HashMap<>();
setPaused(false);
for (PositionedStack pStack : getCyclingStacks()) {
rendered.put(this.group.getSlotKey(pStack), pStack.item);
}
setActiveMember(member);
syncCycle();
this.group.refresh(member);
this.badgeCache.clear();
for (PositionedStack pStack : getCyclingStacks()) {
final ItemStack renderStack = containsStack(pStack, stack) ? stack
@@ -633,6 +720,8 @@ public class RecipeWidget extends Widget {
if (containsStack(pStack, renderStack)) {
pStack.setPermutationToRender(renderStack);
} else {
updatePermutationsFor(pStack);
}
}
@@ -640,10 +729,9 @@ public class RecipeWidget extends Widget {
notifyPermutationsChanged();
}
protected boolean tickCycle() {
private boolean tickCycle() {
if (!NEIClientUtils.shiftKey() && (this.cycleticks++ / TICKS_PER_CYCLE) != this.lastcycle
|| this.lastcycle == -1) {
if ((this.cycleticks++ / TICKS_PER_CYCLE) != this.lastcycle) {
this.lastcycle = this.cycleticks / TICKS_PER_CYCLE;
return true;
}
@@ -651,20 +739,46 @@ public class RecipeWidget extends Widget {
return false;
}
protected void nextMember() {
final List<Integer> allowed = this.group.getAllowedMembers();
private boolean isCycleFrozen(int mouseX, int mouseY) {
this.memberCursor = (this.memberCursor + 1) % allowed.size();
setActiveMember(allowed.get(this.memberCursor));
if (this.paused || NEIClientUtils.shiftKey()) {
return true;
}
return NEIClientConfig.freezeCycleOnHover() && !this.showAsWidget
&& contains(mouseX, mouseY)
&& (getPositionedStackMouseOver(mouseX, mouseY) != null
|| forEachButtons(button -> button.contains(mouseX, mouseY) ? true : null, false));
}
protected int getCursorMember() {
final List<Integer> allowed = this.group.getAllowedMembers();
return allowed.get(Math.max(0, this.memberCursor) % allowed.size());
private void applyCycle() {
if (!this.paused) {
final List<Integer> allowed = this.group.getAllowedMembers();
setActiveMember(allowed.get(this.cycle % allowed.size()));
}
this.group.refresh(this.activeMember);
updatePermutations();
}
protected void updatePermutations(int cycle) {
this.slotCycle = cycle;
private int getPermutationIndex() {
return this.cycle / this.group.getAllowedMembers().size();
}
// keep the permutation index, move the member part of the counter to the active member
private void syncCycle() {
final List<Integer> allowed = this.group.getAllowedMembers();
final int allowedIndex = allowed.indexOf(this.activeMember);
if (allowedIndex >= 0) {
this.cycle = this.cycle / allowed.size() * allowed.size() + allowedIndex;
}
}
private void updatePermutations() {
// badges depend on the rendered item
this.badgeCache.clear();
for (PositionedStack pStack : getCyclingStacks()) {
updatePermutationsFor(pStack);
@@ -674,7 +788,7 @@ public class RecipeWidget extends Widget {
notifyPermutationsChanged();
}
protected void updateTooltipActiveStack() {
private void updateTooltipActiveStack() {
if (this.acceptsTooltip != null && this.acceptsTooltip.tooltipGUID instanceof Point slotKey) {
final PositionedStack pStack = this.group.getSlot(this.activeMember, slotKey);
@@ -684,29 +798,20 @@ public class RecipeWidget extends Widget {
}
}
if (this.variantsTooltip != null) {
final PositionedStack pStack = this.group.getOutputSlot(this.activeMember, this.variantsSlotKey);
if (pStack != null) {
this.variantsTooltip.setActiveStack(pStack.item);
}
}
}
protected void updatePermutationsFor(PositionedStack pStack) {
private void updatePermutationsFor(PositionedStack pStack) {
final int index = this.group
.getCycledPermutationIndex(this.activeMember, this.group.getSlotKey(pStack), getPermutationIndex());
if (!this.renderPermutations.contains(pStack) || this.renderPermutations.get(pStack).size() > 1) {
final ItemStack stack = this.renderPermutations.getCycled(pStack, this.slotCycle);
if (stack != null) {
pStack.setPermutationToRender(stack);
}
if (index >= 0) {
pStack.setPermutationToRender(index);
}
applyPinnedIngredient(pStack);
}
protected void setActiveMember(int member) {
private void setActiveMember(int member) {
if (member != this.activeMember) {
this.activeMember = member;
@@ -718,22 +823,21 @@ public class RecipeWidget extends Widget {
}
protected boolean containsStack(PositionedStack pStack, ItemStack stack) {
return pStack != null && stack != null
&& PermutationsCycler.indexOf(pStack.getFilteredPermutations(), stack) != -1;
private boolean containsStack(PositionedStack pStack, ItemStack stack) {
return pStack != null && this.group.hasPermutation(this.activeMember, this.group.getSlotKey(pStack), stack);
}
protected List<ItemStack> getPermutations(PositionedStack pStack) {
private List<ItemStack> getPermutations(PositionedStack pStack) {
return this.group.getPermutations(this.group.getSlotKey(pStack));
}
protected void notifyPermutationsChanged() {
private void notifyPermutationsChanged() {
for (GuiRecipeButton button : getRecipeButtonsIfInit()) {
button.onPermutationsChanged();
}
}
protected <R> R forEachButtons(Function<GuiRecipeButton, R> callback, R defaultValue) {
private <R> R forEachButtons(Function<GuiRecipeButton, R> callback, R defaultValue) {
for (GuiRecipeButton button : getRecipeButtonsIfInit()) {
button.xPosition += this.x;
@@ -769,7 +873,7 @@ public class RecipeWidget extends Widget {
return cycling != null ? cycling : getOutputStackMouseOver(mx, my);
}
protected PositionedStack getOutputStackMouseOver(int mx, int my) {
private PositionedStack getOutputStackMouseOver(int mx, int my) {
final int yShift = this.handlerInfo.getYShift();
for (PositionedStack pStack : getOutputs()) {
@@ -781,16 +885,10 @@ public class RecipeWidget extends Widget {
return null;
}
protected PositionedStack getCyclingStackMouseOver(int mx, int my) {
private PositionedStack getCyclingStackMouseOver(int mx, int my) {
final int yShift = this.handlerInfo.getYShift();
for (PositionedStack pStack : getInputs()) {
if (pStack.contains(mx - this.x, my - this.y - yShift)) {
return pStack;
}
}
for (PositionedStack pStack : getCatalysts()) {
for (PositionedStack pStack : getCyclingStacks()) {
if (pStack.contains(mx - this.x, my - this.y - yShift)) {
return pStack;
}
@@ -805,7 +903,7 @@ public class RecipeWidget extends Widget {
return pStack != null ? pStack.item : null;
}
protected GuiRecipe<?> getGuiRecipe() {
private GuiRecipe<?> getGuiRecipe() {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
if (guiContainer instanceof GuiRecipe<?>guiRecipe) {
@@ -815,18 +913,10 @@ public class RecipeWidget extends Widget {
return null;
}
protected List<PositionedStack> getInputs() {
return this.group.getInputs(this.activeMember);
}
protected List<PositionedStack> getOutputs() {
return this.group.getOutputs(this.activeMember);
}
protected List<PositionedStack> getCatalysts() {
return this.group.getCatalysts(this.activeMember);
}
protected List<PositionedStack> getCyclingStacks() {
return this.group.getCyclingStacks(this.activeMember);
}
@@ -16,6 +16,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class GuiHelper {
private static final Stack<int[]> scissorFrameStack = new Stack<>();
private static final FloatBuffer MATRIX_BUFFER = BufferUtils.createFloatBuffer(16);
public static void useScissor(int x, int y, int width, int height, Runnable codeBlock) {
pushScissorFrame(x, y, width, height);
@@ -36,7 +37,7 @@ public class GuiHelper {
return currentTopFrame;
}
private static void pushScissorFrame(int x, int y, int width, int height) {
public static void pushScissorFrame(int x, int y, int width, int height) {
int[] matrix = prepareMatrix(x, y, width, height);
int[] parentScissor = peekFirstScissorOrFullScreen();
int parentX = parentScissor[0];
@@ -110,7 +111,7 @@ public class GuiHelper {
private static int[] prepareMatrix(int x, int y, int w, int h) {
// Get the current translation component to support the Gui being drawn at any position on the screen
final FloatBuffer matBuf = BufferUtils.createFloatBuffer(16);
final FloatBuffer matBuf = MATRIX_BUFFER;
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, matBuf);
final float xScale = matBuf.get(0);
final float yScale = matBuf.get(5);
+12 -1
View File
@@ -289,6 +289,7 @@ nei.options.inventory.bookmarks.showRecipeMarkerMode=Show Recipe Marker
nei.options.inventory.bookmarks.showRecipeMarkerMode.0=None
nei.options.inventory.bookmarks.showRecipeMarkerMode.1=Text
nei.options.inventory.bookmarks.showRecipeMarkerMode.2=Background
nei.options.inventory.bookmarks.maxVerticalTooltipRows=Max Vertical Tooltip Rows (0 - disable)
nei.options.inventory.bookmarks.showRecipeHandlerIcon=Show Handler Icon
nei.options.inventory.bookmarks.showRecipeHandlerIcon.true=Yes
nei.options.inventory.bookmarks.showRecipeHandlerIcon.false=No
@@ -427,6 +428,9 @@ nei.options.inventory.autocrafting.false=Disabled
nei.options.inventory.guirecipe.shiftOverlayRecipe=Require holding shift to move items when overlaying recipe
nei.options.inventory.guirecipe.shiftOverlayRecipe.true=Yes
nei.options.inventory.guirecipe.shiftOverlayRecipe.false=No
nei.options.inventory.guirecipe.freezeCycleOnHover=Stop cycling the recipe while hovering over an ingredient or a button
nei.options.inventory.guirecipe.freezeCycleOnHover.true=Yes
nei.options.inventory.guirecipe.freezeCycleOnHover.false=No
nei.options.inventory.widgetsenabled.true=NEI Enabled
nei.options.inventory.widgetsenabled.false=NEI Disabled
nei.options.inventory.cheatmode.0=Recipe Mode
@@ -516,6 +520,13 @@ nei.options.inventory.itemzoom.neiOnly.tip=Zoom items only from the JEI ingredie
nei.options.inventory.itemzoom.onlySolid=Show Only Solid Items
nei.options.inventory.itemzoom.onlySolid.true=Enabled
nei.options.inventory.itemzoom.onlySolid.false=Disabled
nei.options.inventory.itemzoom.preferredSide=Preferred Side
nei.options.inventory.itemzoom.preferredSide.0=Auto
nei.options.inventory.itemzoom.preferredSide.1=Left
nei.options.inventory.itemzoom.preferredSide.2=Right
nei.options.inventory.itemzoom.preferredSide.0.tip=Prefer whichever side currently has fewer items in its panel.
nei.options.inventory.itemzoom.preferredSide.1.tip=Always prefer the left side, unless the cursor is there.
nei.options.inventory.itemzoom.preferredSide.2.tip=Always prefer the right side, unless the cursor is there.
nei.options.inventory.itemzoom.helpText=Display Help Text
nei.options.inventory.itemzoom.helpText.true=Enabled
nei.options.inventory.itemzoom.helpText.false=Disabled
@@ -685,8 +696,8 @@ nei.recipe.concurrent.usage=Concurrent Usage - Total
nei.recipe.concurrent.crafting=Concurrent Crafting - Total
nei.recipe.accepts=Accepts following
nei.recipe.accepts.scroll=Change Item
nei.recipe.group=Variants
nei.recipe.group.scroll=Change Variant (%s/%s)
nei.recipe.pinned=Click to resume cycling
nei.recipe.overlay=Recipe Overlay
nei.recipe.overlay.missing=Missing following
@@ -265,6 +265,9 @@ nei.options.inventory.optimize_gui_overlap_computation.false=Нет
nei.options.inventory.guirecipe.shiftOverlayRecipe=Требовать удержание Shift для перемещения предметов при отображении рецепта
nei.options.inventory.guirecipe.shiftOverlayRecipe.true=Да
nei.options.inventory.guirecipe.shiftOverlayRecipe.false=Нет
nei.options.inventory.guirecipe.freezeCycleOnHover=Останавливать перелистывание рецепта при наведении на предмет или кнопку
nei.options.inventory.guirecipe.freezeCycleOnHover.true=Да
nei.options.inventory.guirecipe.freezeCycleOnHover.false=Нет
nei.options.inventory.widgetsenabled.true=NEI включен
nei.options.inventory.widgetsenabled.false=NEI выключен
nei.options.inventory.cheatmode.0=Режим рецептов
@@ -332,6 +335,13 @@ nei.options.inventory.itemzoom.neiOnly.tip=Увеличивать предмет
nei.options.inventory.itemzoom.onlySolid=Показывать только твердые предметы
nei.options.inventory.itemzoom.onlySolid.true=Включено
nei.options.inventory.itemzoom.onlySolid.false=Отключено
nei.options.inventory.itemzoom.preferredSide=Предпочитаемая сторона
nei.options.inventory.itemzoom.preferredSide.0=Авто
nei.options.inventory.itemzoom.preferredSide.1=Слева
nei.options.inventory.itemzoom.preferredSide.2=Справа
nei.options.inventory.itemzoom.preferredSide.0.tip=Выбирать сторону, где сейчас меньше предметов в панели.
nei.options.inventory.itemzoom.preferredSide.1.tip=Всегда предпочитать левую сторону, если там нет курсора.
nei.options.inventory.itemzoom.preferredSide.2.tip=Всегда предпочитать правую сторону, если там нет курсора.
nei.options.inventory.itemzoom.helpText=Показывать текст помощи
nei.options.inventory.itemzoom.helpText.true=Включено
nei.options.inventory.itemzoom.helpText.false=Отключено
@@ -422,6 +432,7 @@ nei.recipe.profiler.usage=Профилирование использовани
nei.recipe.concurrent.usage=Одновременное использование - всего
nei.recipe.concurrent.crafting=Одновременный крафт - всего
nei.recipe.accepts=Принимает следующее
nei.recipe.pinned=Нажмите, чтобы продолжить перебор
nei.recipe.overlay=отображение рецепта
nei.recipe.overlay.missing=Отсутствует следующее
Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

@@ -64,6 +64,7 @@ public class SearchTokenParserTest {
new ModeValue(1, "Extended mode"), new ModeValue(2, "Regex mode"), new ModeValue(3, "Extended+ mode") };
private static final ModeValue[] extendedPlusPatternMode = { patternModes[3] };
private static final ModeValue[] extendedPatternModes = { patternModes[1], patternModes[3] };
private static final ModeValue[] nonGrammarPatternModes = { patternModes[0], patternModes[1], patternModes[2] };
private static final SearchParserProvider defaultParserProvider = parserProvider(
'\0',
@@ -119,6 +120,10 @@ public class SearchTokenParserTest {
private static final List<Arguments> allModesTestProvider = combinationsProvider(spaceModes, patternModes);
private static final List<Arguments> nonGrammarAllSpaceModesTestProvider = combinationsProvider(
spaceModes,
nonGrammarPatternModes);
private static final List<Arguments> extendedPlusAllSpaceModesTestProvider = combinationsProvider(
spaceModes,
extendedPlusPatternMode);
@@ -236,6 +241,36 @@ public class SearchTokenParserTest {
assertTrue(matchedItems.contains(itemA));
}
@DisplayName("Negated prefix (dash)")
@ParameterizedTest(name = "{argumentsWithNames}")
@FieldSource("allModesTestProvider")
public void testNegatedPrefixDash(int spaceMode, int patternMode) {
SearchTokenParser searchParser = new SearchTokenParser();
searchParser.addProvider(defaultParserProvider);
searchParser
.addProvider(parserProvider('?', "custom", SearchTokenParser.SearchMode.PREFIX, customCreateFilter));
Set<ItemStack> matchedItems = testFilterAgainstAllItems(spaceMode, patternMode, searchParser, "-?A");
assertEquals(5, matchedItems.size());
assertFalse(matchedItems.contains(itemA));
}
@DisplayName("Negated prefix (bang)")
@ParameterizedTest(name = "{argumentsWithNames}")
@FieldSource("nonGrammarAllSpaceModesTestProvider")
public void testNegatedPrefixBang(int spaceMode, int patternMode) {
SearchTokenParser searchParser = new SearchTokenParser();
searchParser.addProvider(defaultParserProvider);
searchParser
.addProvider(parserProvider('?', "custom", SearchTokenParser.SearchMode.PREFIX, customCreateFilter));
Set<ItemStack> matchedItems = testFilterAgainstAllItems(spaceMode, patternMode, searchParser, "!?A");
assertEquals(5, matchedItems.size());
assertFalse(matchedItems.contains(itemA));
}
@DisplayName("Space mode")
@ParameterizedTest(name = "{argumentsWithNames}")
@FieldSource("spaceIsSpaceAllModesTestProvider")