2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Simply an {@link ItemStack} with position. Mainly used in the recipe handlers.
|
|
|
|
|
*/
|
2022-06-24 12:32:13 +01:00
|
|
|
public class PositionedStack {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public int relx;
|
|
|
|
|
public int rely;
|
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
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
private boolean permutated = false;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
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;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
ArrayList<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
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public PositionedStack copy() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return new PositionedStack(items, relx, rely);
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public void setPermutationToRender(int index) {
|
2014-04-29 10:54:20 +10:00
|
|
|
item = items[index].copy();
|
2024-02-04 14:09:24 +02:00
|
|
|
|
|
|
|
|
if (item.getItem() == null) {
|
|
|
|
|
item = new ItemStack(Blocks.fire);
|
|
|
|
|
} else if (item.getItemDamage() == OreDictionary.WILDCARD_VALUE && item.getItem() != null
|
|
|
|
|
&& item.getItem().isRepairable()) {
|
|
|
|
|
item.setItemDamage(0);
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10: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) {
|
2022-06-24 12:32:13 +01:00
|
|
|
for (ItemStack item : items) if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(item, ingredient)) 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() + "')";
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|