2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import java.util.ArrayList;
|
2025-01-25 21:16:28 +02:00
|
|
|
import java.util.Arrays;
|
2025-04-24 18:48:40 +03:00
|
|
|
import java.util.Comparator;
|
2023-09-25 00:35:24 +02:00
|
|
|
import java.util.List;
|
2025-01-25 21:16:28 +02:00
|
|
|
import java.util.stream.Collectors;
|
2023-09-25 00:35:24 +02:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2026-09-08 13:41:16 +03:00
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2014-04-29 10:54:20 +10:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
2025-01-25 21:16:28 +02:00
|
|
|
import codechicken.nei.api.ItemFilter;
|
|
|
|
|
import codechicken.nei.api.ItemInfo;
|
2026-08-13 21:49:05 +03:00
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
2026-09-26 01:06:38 +03:00
|
|
|
import codechicken.nei.item.FluidDrawer;
|
|
|
|
|
import codechicken.nei.item.FluidDrawer.FillDirection;
|
2026-04-06 20:39:41 +03:00
|
|
|
import codechicken.nei.recipe.Badge;
|
2025-01-25 21:16:28 +02:00
|
|
|
import codechicken.nei.recipe.GuiRecipe;
|
2025-07-11 17:25:15 +03:00
|
|
|
import codechicken.nei.recipe.StackInfo;
|
2025-01-25 21:16:28 +02:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
/**
|
|
|
|
|
* Simply an {@link ItemStack} with position. Mainly used in the recipe handlers.
|
|
|
|
|
*/
|
2026-08-13 21:49:05 +03:00
|
|
|
public class PositionedStack implements Cloneable {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2026-03-30 20:36:55 +03:00
|
|
|
/** Maximum chance value representing 100% probability (1 unit = 0.01%). */
|
|
|
|
|
public static final int CHANCE_FULL = 10_000;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public int relx;
|
|
|
|
|
public int rely;
|
2026-08-13 21:49:05 +03:00
|
|
|
public int width = 16;
|
|
|
|
|
public int height = 16;
|
2019-12-30 20:19:16 -08:00
|
|
|
public ItemStack[] items;
|
2022-06-24 12:32:13 +01:00
|
|
|
// compatibility dummy
|
2014-04-29 10:54:20 +10:00
|
|
|
public ItemStack item;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2026-03-30 20:36:55 +03:00
|
|
|
protected int chance = CHANCE_FULL;
|
2026-08-13 21:49:05 +03:00
|
|
|
protected boolean permutated = false;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2026-08-14 22:41:15 +03:00
|
|
|
protected String acceptsLabel;
|
|
|
|
|
protected List<String> tooltip;
|
|
|
|
|
protected List<Badge> badges;
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public PositionedStack(Object object, int x, int y, boolean genPerms) {
|
2014-04-29 10:54:20 +10:00
|
|
|
items = NEIServerUtils.extractRecipeItems(object);
|
|
|
|
|
relx = x;
|
|
|
|
|
rely = y;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
if (genPerms) {
|
|
|
|
|
generatePermutations();
|
|
|
|
|
} else {
|
|
|
|
|
setPermutationToRender(0);
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
public PositionedStack(Object object, int x, int y) {
|
2014-04-29 10:54:20 +10:00
|
|
|
this(object, x, y, true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public void generatePermutations() {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (permutated) return;
|
|
|
|
|
|
2025-01-25 21:16:28 +02:00
|
|
|
List<ItemStack> stacks = new ArrayList<>();
|
2022-06-24 12:32:13 +01:00
|
|
|
for (ItemStack item : items) {
|
|
|
|
|
if (item == null || item.getItem() == null) continue;
|
|
|
|
|
|
|
|
|
|
if (item.getItemDamage() == Short.MAX_VALUE) {
|
2014-04-29 10:54:20 +10:00
|
|
|
List<ItemStack> permutations = ItemList.itemMap.get(item.getItem());
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!permutations.isEmpty()) {
|
2022-12-27 03:14:45 +09:00
|
|
|
for (ItemStack stack : permutations) {
|
|
|
|
|
ItemStack toAdd = stack.copy();
|
|
|
|
|
toAdd.stackSize = item.stackSize;
|
|
|
|
|
stacks.add(toAdd);
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
} else {
|
2014-04-29 10:54:20 +10:00
|
|
|
ItemStack base = new ItemStack(item.getItem(), item.stackSize);
|
|
|
|
|
base.stackTagCompound = item.stackTagCompound;
|
|
|
|
|
stacks.add(base);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
stacks.add(item.copy());
|
|
|
|
|
}
|
|
|
|
|
items = stacks.toArray(new ItemStack[0]);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (items.length == 0) items = new ItemStack[] { new ItemStack(Blocks.fire) };
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
permutated = true;
|
|
|
|
|
setPermutationToRender(0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public void setMaxSize(int i) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (ItemStack item : items) if (item.stackSize > i) item.stackSize = i;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2026-08-14 22:41:15 +03:00
|
|
|
public void setAcceptsLabel(String acceptsLabel) {
|
|
|
|
|
this.acceptsLabel = acceptsLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAcceptsLabel() {
|
|
|
|
|
return this.acceptsLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setBadges(List<Badge> badges) {
|
|
|
|
|
this.badges = badges;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 20:39:41 +03:00
|
|
|
public List<Badge> getBadges() {
|
2026-08-14 22:41:15 +03:00
|
|
|
return this.badges;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTooltip(List<String> tooltip) {
|
|
|
|
|
this.tooltip = tooltip;
|
2026-04-06 20:39:41 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-13 21:49:05 +03:00
|
|
|
public List<String> getTooltip() {
|
2026-08-14 22:41:15 +03:00
|
|
|
return this.tooltip;
|
2026-08-13 21:49:05 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:36:55 +03:00
|
|
|
public int getChance() {
|
|
|
|
|
return this.chance;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 20:39:41 +03:00
|
|
|
public void setChance(int chance) {
|
|
|
|
|
this.chance = chance;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public PositionedStack copy() {
|
2026-08-13 21:49:05 +03:00
|
|
|
try {
|
|
|
|
|
PositionedStack pStack = (PositionedStack) super.clone();
|
|
|
|
|
pStack.items = Arrays.stream(this.items).map(ItemStack::copy).toArray(ItemStack[]::new);
|
|
|
|
|
pStack.item = this.item == null ? null : this.item.copy();
|
2026-08-14 22:41:15 +03:00
|
|
|
pStack.tooltip = this.tooltip == null ? null : new ArrayList<>(this.tooltip);
|
|
|
|
|
pStack.badges = this.badges == null ? null : new ArrayList<>(this.badges);
|
2026-08-13 21:49:05 +03:00
|
|
|
return pStack;
|
|
|
|
|
} catch (CloneNotSupportedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void draw(int mousex, int mousey) {
|
|
|
|
|
final int x = this.relx + (this.width - 16) / 2;
|
|
|
|
|
final int y = this.rely + (this.height - 16) / 2;
|
|
|
|
|
GuiContainerManager.drawItem(x, y, this.item);
|
2025-01-25 21:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ItemStack> getFilteredPermutations() {
|
|
|
|
|
return getFilteredPermutations(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ItemStack> getFilteredPermutations(ItemFilter additionalFilter) {
|
2025-04-24 18:48:40 +03:00
|
|
|
List<ItemStack> items = Arrays.asList(this.items);
|
2025-01-25 21:16:28 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
items = filteringPermutations(items, item -> !ItemInfo.isHidden(item));
|
|
|
|
|
items = filteringPermutations(items, PresetsList.getItemFilter());
|
|
|
|
|
items = filteringPermutations(items, GuiRecipe.getSearchItemFilter());
|
|
|
|
|
items = filteringPermutations(items, additionalFilter);
|
2025-01-25 21:16:28 +02:00
|
|
|
|
2026-02-23 09:32:15 +02:00
|
|
|
items.sort(Comparator.comparing(FavoriteRecipes::containsManual).reversed());
|
2025-01-25 21:16:28 +02:00
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
private List<ItemStack> filteringPermutations(List<ItemStack> items, ItemFilter filter) {
|
|
|
|
|
if (filter == null) return items;
|
|
|
|
|
final List<ItemStack> filteredItems = items.stream().filter(filter::matches).collect(Collectors.toList());
|
|
|
|
|
return filteredItems.isEmpty() ? items : filteredItems;
|
2025-01-25 21:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public int getPermutationIndex(ItemStack stack) {
|
2025-01-25 21:16:28 +02:00
|
|
|
|
|
|
|
|
for (int index = 0; index < this.items.length; index++) {
|
2025-11-08 09:32:47 +02:00
|
|
|
if (NEIServerUtils.areStacksSameType(items[index], stack)) {
|
2025-10-12 19:39:21 +03:00
|
|
|
return index;
|
2025-01-25 21:16:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean setPermutationToRender(ItemStack ingredient) {
|
|
|
|
|
final int stackIndex = getPermutationIndex(ingredient);
|
|
|
|
|
|
|
|
|
|
if (stackIndex >= 0) {
|
|
|
|
|
setPermutationToRender(stackIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stackIndex >= 0;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public void setPermutationToRender(int index) {
|
2025-01-25 21:16:28 +02:00
|
|
|
this.item = this.items[index].copy();
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-01-25 21:16:28 +02:00
|
|
|
if (this.item.getItem() == null) {
|
|
|
|
|
this.item = new ItemStack(Blocks.fire);
|
|
|
|
|
} else if (this.item.getItemDamage() == OreDictionary.WILDCARD_VALUE && this.item.getItem().isRepairable()) {
|
|
|
|
|
this.item.setItemDamage(0);
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
public boolean contains(int mx, int my) {
|
2026-08-13 21:49:05 +03:00
|
|
|
return mx >= this.relx - 1 && mx < this.relx + this.width + 1
|
|
|
|
|
&& my >= this.rely - 1
|
|
|
|
|
&& my < this.rely + this.height + 1;
|
2025-10-12 19:39:21 +03:00
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public boolean contains(ItemStack ingredient) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (ItemStack item : items) if (NEIServerUtils.areStacksSameTypeCrafting(item, ingredient)) return true;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 16:29:51 +09:00
|
|
|
/**
|
|
|
|
|
* NBT-friendly version of {@link #contains(ItemStack)}
|
|
|
|
|
*/
|
2022-02-08 05:12:26 +09:00
|
|
|
public boolean containsWithNBT(ItemStack ingredient) {
|
2025-07-11 17:25:15 +03:00
|
|
|
for (ItemStack item : items) if (StackInfo.equalItemAndNBT(item, ingredient, true)) return true;
|
2022-02-08 05:12:26 +09:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public boolean contains(Item ingred) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (ItemStack item : items) if (item.getItem() == ingred) return true;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
return "PositionedStack(output='" + item.toString() + "')";
|
|
|
|
|
}
|
2026-08-13 21:49:05 +03:00
|
|
|
|
|
|
|
|
public static class Placeholder extends PositionedStack {
|
|
|
|
|
|
|
|
|
|
public Placeholder(Object object, int x, int y, boolean genPerms) {
|
|
|
|
|
super(object, x, y, genPerms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Placeholder(Object object, int x, int y) {
|
|
|
|
|
this(object, x, y, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void draw(int mousex, int mousey) {}
|
|
|
|
|
}
|
2026-09-08 13:41:16 +03:00
|
|
|
|
|
|
|
|
public static class Fluid extends PositionedStack {
|
|
|
|
|
|
|
|
|
|
/** The tank size the fill level is measured against, in mB. 0 means "always render full". */
|
2026-09-26 01:06:38 +03:00
|
|
|
protected int capacity = 0;
|
|
|
|
|
protected boolean flowingTexture = false;
|
|
|
|
|
protected FillDirection fillDirection = FillDirection.AUTO;
|
2026-09-08 13:41:16 +03:00
|
|
|
|
|
|
|
|
private ItemStack cachedFluidItem;
|
|
|
|
|
private FluidStack cachedFluidStack;
|
|
|
|
|
|
|
|
|
|
public Fluid(Object object, int x, int y, boolean genPerms) {
|
|
|
|
|
super(object, x, y, genPerms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Fluid(Object object, int x, int y) {
|
|
|
|
|
this(object, x, y, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Fluid(Object object, int x, int y, int width, int height, int capacity) {
|
|
|
|
|
super(object, x, y, false);
|
|
|
|
|
this.width = width;
|
|
|
|
|
this.height = height;
|
2026-09-26 01:06:38 +03:00
|
|
|
setCapacity(capacity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCapacity() {
|
|
|
|
|
return this.capacity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Fluid setCapacity(int capacity) {
|
|
|
|
|
this.capacity = Math.max(capacity, 0);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasFlowingTexture() {
|
|
|
|
|
return this.flowingTexture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Fluid setFlowingTexture(boolean flowingTexture) {
|
|
|
|
|
this.flowingTexture = flowingTexture;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FillDirection getFillDirection() {
|
|
|
|
|
return this.fillDirection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Fluid setFillDirection(FillDirection fillDirection) {
|
|
|
|
|
this.fillDirection = fillDirection == null ? FillDirection.AUTO : fillDirection;
|
|
|
|
|
return this;
|
2026-09-08 13:41:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected FluidStack getFluidStack() {
|
|
|
|
|
|
|
|
|
|
if (this.item != this.cachedFluidItem) {
|
|
|
|
|
this.cachedFluidItem = this.item;
|
|
|
|
|
this.cachedFluidStack = StackInfo.isFluidDisplayItem(this.item) ? StackInfo.getFluid(this.item) : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.cachedFluidStack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getTooltip() {
|
|
|
|
|
final List<String> tooltip = new ArrayList<>();
|
|
|
|
|
final List<String> customTooltip = super.getTooltip();
|
|
|
|
|
final FluidStack fluidStack = getFluidStack();
|
|
|
|
|
|
|
|
|
|
if (fluidStack != null) {
|
|
|
|
|
tooltip.add(
|
|
|
|
|
EnumChatFormatting.GRAY + NEIClientUtils
|
|
|
|
|
.translate("recipe.fluid.tank.amount", NEIClientUtils.formatFluid(fluidStack.amount)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (customTooltip != null) {
|
|
|
|
|
tooltip.addAll(customTooltip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void draw(int mousex, int mousey) {
|
|
|
|
|
final FluidStack fluidStack = getFluidStack();
|
|
|
|
|
|
|
|
|
|
if (fluidStack == null) {
|
|
|
|
|
super.draw(mousex, mousey);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-26 01:06:38 +03:00
|
|
|
FluidDrawer.drawFluid(
|
|
|
|
|
this.relx,
|
|
|
|
|
this.rely,
|
|
|
|
|
this.width,
|
|
|
|
|
this.height,
|
|
|
|
|
this.capacity,
|
|
|
|
|
fluidStack,
|
|
|
|
|
this.flowingTexture,
|
|
|
|
|
this.fillDirection);
|
2026-09-08 13:41:16 +03:00
|
|
|
}
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|