2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Simply an {@link ItemStack} with position.
|
|
|
|
|
* Mainly used in the recipe handlers.
|
|
|
|
|
*/
|
|
|
|
|
public class PositionedStack
|
|
|
|
|
{
|
|
|
|
|
public int relx;
|
|
|
|
|
public int rely;
|
2019-12-30 20:19:16 -08:00
|
|
|
public ItemStack[] items;
|
2014-04-29 10:54:20 +10:00
|
|
|
//compatibility dummy
|
|
|
|
|
public ItemStack item;
|
|
|
|
|
|
|
|
|
|
private boolean permutated = false;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if(genPerms)
|
|
|
|
|
generatePermutations();
|
|
|
|
|
else
|
|
|
|
|
setPermutationToRender(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PositionedStack(Object object, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
this(object, x, y, true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public void generatePermutations() {
|
2014-04-29 10:54:20 +10:00
|
|
|
if(permutated)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
ArrayList<ItemStack> stacks = new ArrayList<>();
|
2021-08-08 11:56:59 -07:00
|
|
|
for(ItemStack item : items) {
|
2014-04-29 10:54:20 +10:00
|
|
|
if(item == null || item.getItem() == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
if(item.getItemDamage() == Short.MAX_VALUE) {
|
2014-04-29 10:54:20 +10:00
|
|
|
List<ItemStack> permutations = ItemList.itemMap.get(item.getItem());
|
2021-08-08 11:56:59 -07:00
|
|
|
if(!permutations.isEmpty()) {
|
2014-04-29 10:54:20 +10:00
|
|
|
for(ItemStack stack : permutations)
|
|
|
|
|
stacks.add(stack.copy());
|
|
|
|
|
}
|
2021-08-08 11:56:59 -07: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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stacks.add(item.copy());
|
|
|
|
|
}
|
|
|
|
|
items = stacks.toArray(new ItemStack[0]);
|
|
|
|
|
|
|
|
|
|
if(items.length == 0)
|
|
|
|
|
items = new ItemStack[]{new ItemStack(Blocks.fire)};
|
|
|
|
|
|
|
|
|
|
permutated = true;
|
|
|
|
|
setPermutationToRender(0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public void setMaxSize(int i) {
|
2014-04-29 10:54:20 +10:00
|
|
|
for(ItemStack item : items)
|
|
|
|
|
if(item.stackSize > i)
|
|
|
|
|
item.stackSize = i;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
if(item.getItem() == null)
|
|
|
|
|
item = new ItemStack(Blocks.fire);
|
2019-06-12 14:11:03 -07:00
|
|
|
else if(item.getItemDamage() == OreDictionary.WILDCARD_VALUE && item.getItem() != null && item.getItem().isRepairable())
|
2014-04-29 10:54:20 +10:00
|
|
|
item.setItemDamage(0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public boolean contains(ItemStack ingredient) {
|
2014-04-29 10:54:20 +10:00
|
|
|
for(ItemStack item : items)
|
|
|
|
|
if(NEIServerUtils.areStacksSameTypeCrafting(item, ingredient))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
for(ItemStack item : items)
|
|
|
|
|
if(NEIServerUtils.areStacksSameTypeCraftingWithNBT(item, ingredient))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 11:56:59 -07:00
|
|
|
public boolean contains(Item ingred) {
|
2014-04-29 10:54:20 +10:00
|
|
|
for(ItemStack item : items)
|
|
|
|
|
if(item.getItem() == ingred)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
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
|
|
|
}
|