implemented list item, close #1999

This commit is contained in:
SpaceToad 2014-08-29 00:03:05 +02:00
parent fb83ca8e99
commit 72758ba9a9
25 changed files with 714 additions and 36 deletions

View file

@ -173,6 +173,7 @@ item.redstone_comp_chipset.name=Redstone Comp Chipset
item.redstone_board.name=Redstone Board
item.robot.name=Robot
item.blueprintItem.name=Blueprint
item.list.name=List
item.blueprint.unnamed=<unnamed>
item.blueprint.author=by
item.blueprint.blank=Blank

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

View file

@ -76,6 +76,7 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.GuiHandler;
import buildcraft.core.InterModComms;
import buildcraft.core.ItemGear;
import buildcraft.core.ItemList;
import buildcraft.core.ItemMapLocation;
import buildcraft.core.ItemScienceBook;
import buildcraft.core.ItemSpring;
@ -157,6 +158,7 @@ public class BuildCraftCore extends BuildCraftMod {
public static Item diamondGearItem;
public static Item wrenchItem;
public static Item mapLocationItem;
public static Item listItem;
@SideOnly(Side.CLIENT)
public static IIcon redLaserTexture;
@SideOnly(Side.CLIENT)
@ -303,6 +305,9 @@ public class BuildCraftCore extends BuildCraftMod {
mapLocationItem = (new ItemMapLocation()).setUnlocalizedName("mapLocation");
CoreProxy.proxy.registerItem(mapLocationItem);
listItem = (new ItemList()).setUnlocalizedName("list");
CoreProxy.proxy.registerItem(listItem);
Property modifyWorldProp = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "modifyWorld", true);
modifyWorldProp.comment = "set to false if BuildCraft should not generate custom blocks (e.g. oil)";
modifyWorld = modifyWorldProp.getBoolean(true);
@ -608,6 +613,8 @@ public class BuildCraftCore extends BuildCraftMod {
CoreProxy.proxy.addCraftingRecipe(Tier.DiamondGear.getTechnology(),
new ItemStack(diamondGearItem), " I ", "IGI", " I ", 'I', Items.diamond, 'G', goldGearItem);
CoreProxy.proxy.addCraftingRecipe(new ItemStack(mapLocationItem), "ppp", "pYp", "ppp", 'p', Items.paper, 'Y', new ItemStack(Items.dye, 1, 11));
CoreProxy.proxy.addCraftingRecipe(new ItemStack(listItem), "ppp", "pYp", "ppp", 'p', Items.paper, 'Y',
new ItemStack(Items.dye, 1, 2));
}
@Mod.EventHandler

View file

@ -109,7 +109,7 @@ public class TileRequester extends TileBuildCraft implements IInventory, IReques
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
if (requests.getStackInSlot(i) == null) {
return false;
} else if (!StackHelper.isMatchingItem(requests.getStackInSlot(i), itemStack)) {
} else if (!StackHelper.isMatchingItemOrList(requests.getStackInSlot(i), itemStack)) {
return false;
} else {
return inv.isItemValidForSlot(i, itemStack);
@ -143,7 +143,7 @@ public class TileRequester extends TileBuildCraft implements IInventory, IReques
} else if (inv.getStackInSlot(i) == null) {
return false;
} else {
return StackHelper.isMatchingItem(requests.getStackInSlot(i), inv.getStackInSlot(i))
return StackHelper.isMatchingItemOrList(requests.getStackInSlot(i), inv.getStackInSlot(i))
&& inv.getStackInSlot(i).stackSize >= requests.getStackInSlot(i).stackSize;
}
}
@ -205,9 +205,9 @@ public class TileRequester extends TileBuildCraft implements IInventory, IReques
return stack;
}
} else if (!StackHelper.isMatchingItem(stack, existingStack)) {
} else if (!StackHelper.isMatchingItemOrList(stack, existingStack)) {
return stack;
} else if (existingStack == null || StackHelper.isMatchingItem(stack, requests.getStackInSlot(i))) {
} else if (existingStack == null || StackHelper.isMatchingItemOrList(stack, requests.getStackInSlot(i))) {
int maxQty = requests.getStackInSlot(i).stackSize;
if (existingStack.stackSize + stack.stackSize <= maxQty) {

View file

@ -13,7 +13,9 @@ import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
import buildcraft.core.gui.ContainerList;
import buildcraft.core.gui.ContainerScienceBook;
import buildcraft.core.gui.GuiList;
import buildcraft.core.science.GuiScienceBook;
public class GuiHandler implements IGuiHandler {
@ -22,6 +24,8 @@ public class GuiHandler implements IGuiHandler {
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
if (id == GuiIds.SCIENCE_BOOK) {
return new GuiScienceBook(player);
} else if (id == GuiIds.LIST) {
return new GuiList(player);
}
return null;
@ -31,6 +35,8 @@ public class GuiHandler implements IGuiHandler {
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
if (id == GuiIds.SCIENCE_BOOK) {
return new ContainerScienceBook(player);
} else if (id == GuiIds.LIST) {
return new ContainerList(player);
}
return null;

View file

@ -17,6 +17,7 @@ public final class GuiIds {
public static final int URBANIST = 14;
public static final int MAP = 15;
public static final int REQUESTER = 16;
public static final int LIST = 17;
public static final int ENGINE_IRON = 20;
public static final int ENGINE_STONE = 21;

View file

@ -0,0 +1,298 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.BuildCraftCore;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.NBTUtils;
public class ItemList extends ItemBuildCraft {
private IIcon baseIcon;
private IIcon writtenIcon;
public static class StackLine {
public boolean oreWildcard = false;
public boolean subitemsWildcard = false;
public boolean isOre;
private ItemStack[] stacks = new ItemStack[7];
private ArrayList<ItemStack> ores = new ArrayList<ItemStack>();
private ArrayList<ItemStack> relatedItems = new ArrayList<ItemStack>();
public ItemStack getStack(int index) {
if (index == 0 || (!oreWildcard && !subitemsWildcard)) {
if (index < 7) {
return stacks[index];
} else {
return null;
}
} else if (oreWildcard) {
if (ores.size() >= index) {
return ores.get(index - 1);
} else {
return null;
}
} else {
if (relatedItems.size() >= index) {
return relatedItems.get(index - 1);
} else {
return null;
}
}
}
public void setStack(int slot, ItemStack stack) {
stacks[slot] = stack;
if (stack != null) {
stacks[slot] = stacks[slot].copy();
stacks[slot].stackSize = 1;
}
if (slot == 0) {
relatedItems.clear();
ores.clear();
if (stack == null) {
isOre = false;
} else {
setLists();
}
}
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setBoolean("ore", oreWildcard);
nbt.setBoolean("sub", subitemsWildcard);
for (int i = 0; i < 7; ++i) {
if (stacks[i] != null) {
NBTTagCompound stackNBT = new NBTTagCompound();
stacks[i].writeToNBT(stackNBT);
nbt.setTag("stacks[" + i + "]", stackNBT);
}
}
}
public void readFromNBT(NBTTagCompound nbt) {
oreWildcard = nbt.getBoolean("ore");
subitemsWildcard = nbt.getBoolean("sub");
for (int i = 0; i < 7; ++i) {
if (nbt.hasKey("stacks[" + i + "]")) {
setStack(i, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stacks[" + i + "]")));
}
}
}
private boolean classMatch(Item base, Item matched) {
if (base.getClass() == Item.class) {
return base == matched;
} else if (base.getClass() == matched.getClass()) {
if (base instanceof ItemBlock) {
Block baseBlock = ((ItemBlock) base).field_150939_a;
Block matchedBlock = ((ItemBlock) matched).field_150939_a;
if (baseBlock.getClass() == Block.class) {
return baseBlock == matchedBlock;
} else {
return baseBlock.equals(matchedBlock);
}
} else {
return true;
}
} else {
return false;
}
}
private boolean oreMatch(ItemStack base, ItemStack matched) {
int[] oreIds = OreDictionary.getOreIDs(base);
int[] matchesIds = OreDictionary.getOreIDs(matched);
for (int stackId : oreIds) {
for (int matchId : matchesIds) {
if (stackId == matchId) {
return true;
}
}
}
return false;
}
private void setLists() {
Item baseItem = stacks [0].getItem();
int[] oreIds = OreDictionary.getOreIDs(stacks[0]);
isOre = oreIds.length > 0;
for (Object o : Item.itemRegistry) {
Item item = (Item) o;
boolean classMatch = classMatch(baseItem, item);
List list = new LinkedList();
for (CreativeTabs tab : item.getCreativeTabs()) {
item.getSubItems(item, tab, list);
}
if (list.size() > 0) {
for (Object ol : list) {
ItemStack stack = (ItemStack) ol;
if (classMatch && relatedItems.size() <= 7 && !StackHelper.isMatchingItemOrList(stacks[0], stack)) {
relatedItems.add(stack);
}
if (isOre && ores.size() <= 7 && !StackHelper.isMatchingItemOrList(stacks[0], stack)
&& oreMatch(stacks[0], stack)) {
ores.add(stack);
}
}
}
}
}
public boolean matches(ItemStack item) {
if (subitemsWildcard) {
if (stacks[0] == null) {
return false;
}
return classMatch(stacks[0].getItem(), item.getItem());
} else if (oreWildcard) {
if (stacks[0] == null) {
return false;
}
return oreMatch(stacks[0], item);
} else {
for (ItemStack stack : stacks) {
if (stack != null && StackHelper.isMatchingItemOrList(stacks[0], item)) {
return true;
}
}
return false;
}
}
}
@Override
public IIcon getIconIndex(ItemStack stack) {
if (NBTUtils.getItemData(stack).hasKey("written")) {
itemIcon = writtenIcon;
} else {
itemIcon = baseIcon;
}
return itemIcon;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister) {
baseIcon = par1IconRegister.registerIcon("buildcraft:list");
writtenIcon = par1IconRegister.registerIcon("buildcraft:list_used");
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (!world.isRemote) {
player.openGui(BuildCraftCore.instance, GuiIds.LIST, world, 0, 0, 0);
}
return stack;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
NBTTagCompound nbt = NBTUtils.getItemData(stack);
if (nbt.hasKey("label")) {
list.add(nbt.getString("label"));
}
}
public static void saveLine(ItemStack stack, StackLine line, int index) {
NBTTagCompound nbt = NBTUtils.getItemData(stack);
nbt.setBoolean("written", true);
NBTTagCompound lineNBT = new NBTTagCompound();
line.writeToNBT(lineNBT);
nbt.setTag("line[" + index + "]", lineNBT);
}
public static void saveLabel(ItemStack stack, String text) {
NBTTagCompound nbt = NBTUtils.getItemData(stack);
nbt.setString("label", text);
}
public static StackLine[] getLines(ItemStack stack) {
StackLine[] result = new StackLine[6];
for (int i = 0; i < 6; ++i) {
result[i] = new StackLine();
}
NBTTagCompound nbt = NBTUtils.getItemData(stack);
if (nbt.hasKey("written")) {
for (int i = 0; i < 6; ++i) {
result[i].readFromNBT(nbt.getCompoundTag("line[" + i + "]"));
}
}
return result;
}
public static String getLabel(ItemStack stack) {
return NBTUtils.getItemData(stack).getString("label");
}
public static boolean matches(ItemStack stackList, ItemStack item) {
StackLine[] lines = getLines(stackList);
for (StackLine line : lines) {
if (line != null) {
if (line.matches(item)) {
return true;
}
}
}
return false;
}
}

View file

@ -0,0 +1,83 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import buildcraft.core.ItemList;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCSide;
public class ContainerList extends BuildCraftContainer {
private EntityPlayer player;
public ItemList.StackLine lines[];
public ContainerList(EntityPlayer iPlayer) {
super(iPlayer.inventory.getSizeInventory());
player = iPlayer;
lines = ItemList.getLines(player.getCurrentEquippedItem());
for (int sy = 0; sy < 3; sy++) {
for (int sx = 0; sx < 9; sx++) {
addSlotToContainer(new Slot(player.inventory, sx + sy * 9 + 9, 8 + sx * 18, 153 + sy * 18));
}
}
for (int sx = 0; sx < 9; sx++) {
addSlotToContainer(new Slot(player.inventory, sx, 8 + sx * 18, 211));
}
}
@Override
public boolean canInteractWith(EntityPlayer p_75145_1_) {
return true;
}
@RPC(RPCSide.SERVER)
public void setStack(int lineIndex, int slotIndex, ItemStack stack) {
lines[lineIndex].setStack(slotIndex, stack);
ItemList.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex);
if (player.worldObj.isRemote) {
RPCHandler.rpcServer(this, "setStack", lineIndex, slotIndex, stack);
}
}
@RPC(RPCSide.SERVER)
public void switchButton(int lineIndex, int button) {
if (button == 0) {
lines[lineIndex].oreWildcard = false;
lines[lineIndex].subitemsWildcard = !lines[lineIndex].subitemsWildcard;
} else if (button == 1 && lines[lineIndex].isOre) {
lines[lineIndex].subitemsWildcard = false;
lines[lineIndex].oreWildcard = !lines[lineIndex].oreWildcard;
}
ItemList.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex);
if (player.worldObj.isRemote) {
RPCHandler.rpcServer(this, "switchButton", lineIndex, button);
}
}
@RPC(RPCSide.SERVER)
public void setLabel(String text) {
ItemList.saveLabel(player.getCurrentEquippedItem(), text);
if (player.worldObj.isRemote) {
RPCHandler.rpcServer(this, "setLabel", text);
}
}
}

View file

@ -0,0 +1,205 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import buildcraft.core.DefaultProps;
import buildcraft.core.ItemList;
public class GuiList extends GuiAdvancedInterface {
private GuiTextField textField;
private EntityPlayer player;
private static final ResourceLocation TEXTURE_BASE = new ResourceLocation(
"buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/list.png");
private static class MainSlot extends AdvancedSlot {
public int lineIndex;
public MainSlot(GuiAdvancedInterface gui, int x, int y, int iLineIndex) {
super(gui, x, y);
lineIndex = iLineIndex;
}
@Override
public ItemStack getItemStack() {
ContainerList container = (ContainerList) gui.getContainer();
if (container.lines[lineIndex].getStack(0) != null) {
return container.lines[lineIndex].getStack(0);
} else {
return null;
}
}
}
private static class SecondarySlot extends AdvancedSlot {
public int lineIndex;
public int slotIndex;
public SecondarySlot(GuiAdvancedInterface gui, int x, int y, int iLineIndex, int iSlotIndex) {
super(gui, x, y);
lineIndex = iLineIndex;
slotIndex = iSlotIndex;
}
@Override
public ItemStack getItemStack() {
ContainerList container = (ContainerList) gui.getContainer();
if (slotIndex == 6 && container.lines[lineIndex].getStack(7) != null) {
return null;
}
if (container.lines[lineIndex].getStack(slotIndex) != null) {
return container.lines[lineIndex].getStack(slotIndex);
} else {
return null;
}
}
}
private static class Button extends AdvancedSlot {
public int line;
public int kind;
public Button(GuiAdvancedInterface gui, int x, int y, int iLine, int iKind) {
super(gui, x, y);
line = iLine;
kind = iKind;
}
}
public GuiList(EntityPlayer iPlayer) {
super(new ContainerList(iPlayer), iPlayer.inventory, TEXTURE_BASE);
xSize = 176;
ySize = 241;
for (int sy = 0; sy < 6; ++sy) {
slots.add(new MainSlot(this, 44, 31 + sy * 18, sy));
for (int sx = 1; sx < 7; ++sx) {
slots.add(new SecondarySlot(this, 44 + sx * 18, 31 + sy * 18, sy, sx));
}
slots.add(new Button(this, 8, 31 + sy * 18, sy, 0));
slots.add(new Button(this, 26, 31 + sy * 18, sy, 1));
}
player = iPlayer;
}
@Override
public void initGui() {
super.initGui();
textField = new GuiTextField(this.fontRendererObj, 10, 10, 156, 12);
textField.setMaxStringLength(32);
textField.setText(ItemList.getLabel(player.getCurrentEquippedItem()));
textField.setFocused(false);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
super.drawGuiContainerBackgroundLayer(f, x, y);
ContainerList container = (ContainerList) getContainer();
bindTexture(TEXTURE_BASE);
for (int i = 0; i < 6; ++i) {
if (container.lines[i].subitemsWildcard) {
drawTexturedModalRect(guiLeft + 7, guiTop + 30 + 18 * i, 194, 18, 18, 18);
} else {
drawTexturedModalRect(guiLeft + 7, guiTop + 30 + 18 * i, 194, 0, 18, 18);
}
if (container.lines[i].isOre) {
if (container.lines[i].oreWildcard) {
drawTexturedModalRect(guiLeft + 25, guiTop + 30 + 18 * i, 176, 18, 18, 18);
} else {
drawTexturedModalRect(guiLeft + 25, guiTop + 30 + 18 * i, 176, 0, 18, 18);
}
}
if (container.lines[i].subitemsWildcard || container.lines[i].oreWildcard) {
for (int j = 0; j < 6; ++j) {
drawTexturedModalRect(guiLeft + 62 + 18 * j, guiTop + 31 + 18 * i, 195, 37, 16, 16);
}
}
}
drawBackgroundSlots();
bindTexture(TEXTURE_BASE);
for (int i = 0; i < 6; ++i) {
if (container.lines[i].getStack(7) != null) {
drawTexturedModalRect(guiLeft + 152, guiTop + 31 + 18 * i, 177, 37, 16, 16);
}
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
super.drawGuiContainerForegroundLayer(par1, par2);
textField.drawTextBox();
drawTooltipForSlotAt(par1, par2);
}
@Override
protected void mouseClicked(int x, int y, int b) {
super.mouseClicked(x, y, b);
AdvancedSlot slot = getSlotAtLocation(x, y);
ContainerList container = (ContainerList) getContainer();
if (slot instanceof MainSlot) {
container.setStack(((MainSlot) slot).lineIndex, 0, mc.thePlayer.inventory.getItemStack());
} else if (slot instanceof SecondarySlot) {
container.setStack(((SecondarySlot) slot).lineIndex, ((SecondarySlot) slot).slotIndex,
mc.thePlayer.inventory.getItemStack());
} else if (slot instanceof Button) {
Button button = (Button) slot;
container.switchButton(button.line, button.kind);
}
textField.mouseClicked(x - guiLeft, y - guiTop, b);
}
@Override
protected void keyTyped(char c, int i) {
if (textField.isFocused()) {
if (c == 13 || c == 27) {
textField.setFocused(false);
} else {
textField.textboxKeyTyped(c, i);
((ContainerList) container).setLabel(textField.getText());
// RPCHandler.rpcServer(architect, "handleClientSetName",
// textField.getText());
}
} else {
super.keyTyped(c, i);
}
}
}

View file

@ -22,7 +22,6 @@ import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
public final class InvUtils {
@ -33,10 +32,6 @@ public final class InvUtils {
private InvUtils() {
}
public static int countItems(IInventory inv, ForgeDirection side, ItemStack... filter) {
return countItems(inv, side, new ArrayStackFilter(filter));
}
public static int countItems(IInventory inv, ForgeDirection side, IStackFilter filter) {
int count = 0;
for (IInvSlot slot : InventoryIterator.getIterable(inv, side)) {
@ -48,10 +43,6 @@ public final class InvUtils {
return count;
}
public static boolean containsItem(IInventory inv, ForgeDirection side, ItemStack... filter) {
return containsItem(inv, side, new ArrayStackFilter(filter));
}
public static boolean containsItem(IInventory inv, ForgeDirection side, IStackFilter filter) {
for (IInvSlot slot : InventoryIterator.getIterable(inv, side)) {
ItemStack stack = slot.getStackInSlot();
@ -100,10 +91,6 @@ public final class InvUtils {
return null;
}
public static ItemStack moveOneItem(IInventory source, ForgeDirection output, IInventory dest, ForgeDirection intput, ItemStack... filter) {
return moveOneItem(source, output, dest, intput, new ArrayStackFilter(filter));
}
/* STACK DROPS */
public static void dropItems(World world, ItemStack stack, int i, int j, int k) {
if (stack == null || stack.stackSize <= 0) {

View file

@ -9,8 +9,11 @@
package buildcraft.core.inventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.core.ItemList;
public class StackHelper {
protected StackHelper() {
@ -38,6 +41,27 @@ public class StackHelper {
}
public static boolean canStacksOrListsMerge(ItemStack stack1, ItemStack stack2) {
if (stack1 == null || stack2 == null) {
return false;
}
if (stack1.getItem() instanceof ItemList) {
return ItemList.matches(stack1, stack2);
} else if (stack2.getItem() instanceof ItemList) {
return ItemList.matches(stack2, stack1);
}
if (!stack1.isItemEqual(stack2)) {
return false;
}
if (!ItemStack.areItemStackTagsEqual(stack1, stack2)) {
return false;
}
return true;
}
/**
* Merges mergeSource into mergeTarget
*
@ -108,6 +132,20 @@ public class StackHelper {
return false;
}
public static boolean isMatchingItemOrList(ItemStack a, ItemStack b) {
if (a == null || b == null) {
return false;
}
if (a.getItem() instanceof ItemList) {
return ItemList.matches(a, b);
} else if (b.getItem() instanceof ItemList) {
return ItemList.matches(b, a);
}
return isMatchingItem(a, b, true, false);
}
/**
* Compares item id, damage and NBT. Accepts wildcard damage. Ignores damage
* entirely if the item doesn't have subtypes.
@ -130,10 +168,12 @@ public class StackHelper {
* @param matchNBT
* @return true if matches
*/
public static boolean isMatchingItem(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
public static boolean isMatchingItem(final ItemStack a, final ItemStack b, final boolean matchDamage,
final boolean matchNBT) {
if (a == null || b == null) {
return false;
}
if (a.getItem() != b.getItem()) {
return false;
}

View file

@ -0,0 +1,39 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.inventory.filters;
import net.minecraft.item.ItemStack;
import buildcraft.core.inventory.StackHelper;
/**
* Returns true if the stack matches any one one of the filter stacks. Takes
* into account item lists.
*/
public class ArrayStackOrListFilter extends ArrayStackFilter {
public ArrayStackOrListFilter(ItemStack... stacks) {
super(stacks);
}
@Override
public boolean matches(ItemStack stack) {
if (stacks.length == 0 || !hasFilter()) {
return true;
}
for (ItemStack s : stacks) {
if (StackHelper.isMatchingItemOrList(s, stack)) {
return true;
}
}
return false;
}
}

View file

@ -19,7 +19,7 @@ import buildcraft.api.gates.TriggerParameterItemStack;
/**
* Returns true if the stack matches any one one of the filter stacks.
*/
public class StatementParameterStackFilter extends ArrayStackFilter {
public class StatementParameterStackFilter extends ArrayStackOrListFilter {
public StatementParameterStackFilter(IStatementParameter... parameters) {
ArrayList<ItemStack> tmp = new ArrayList<ItemStack>();

View file

@ -33,6 +33,7 @@ import buildcraft.core.inventory.InventoryCopy;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.silicon.statements.ActionRobotFilter;
import buildcraft.silicon.statements.ActionStationAllowCraft;
@ -224,7 +225,7 @@ public class AIRobotCraftWorkbench extends AIRobotCraftGeneric {
@Override
public boolean matches(DockingStation station) {
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackFilter(recipe.getRecipeOutput()),
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackOrListFilter(recipe.getRecipeOutput()),
ActionStationAllowCraft.class)) {
return false;
}

View file

@ -17,7 +17,7 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IRequestProvider;
import buildcraft.api.robots.StackRequest;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
import buildcraft.silicon.statements.ActionStationRequestItemsMachine;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.ActionIterator;
@ -51,7 +51,7 @@ public class AIRobotDeliverRequested extends AIRobot {
return;
}
IInvSlot slot = InvUtils.getItem(robot, new ArrayStackFilter(requested.stack));
IInvSlot slot = InvUtils.getItem(robot, new ArrayStackOrListFilter(requested.stack));
if (slot == null) {
terminate();

View file

@ -93,7 +93,7 @@ public class BoardRobotDelivery extends RedstoneBoardRobot {
if (currentRequest == null) {
return false;
} else {
return StackHelper.isMatchingItem(stack, currentRequest.stack);
return StackHelper.isMatchingItemOrList(stack, currentRequest.stack);
}
}
}

View file

@ -27,6 +27,7 @@ import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.TickHandlerCore;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
import buildcraft.core.inventory.filters.CompositeFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.inventory.filters.OreStackFilter;
@ -70,7 +71,7 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
}
if (filteredFilter.size() > 0) {
ArrayStackFilter arrayFilter = new ArrayStackFilter(
ArrayStackFilter arrayFilter = new ArrayStackOrListFilter(
filteredFilter.toArray(new ItemStack[filteredFilter.size()]));
startDelegateAI(new AIRobotFetchAndEquipItemStack(robot, arrayFilter));

View file

@ -18,6 +18,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.ItemList;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.StringUtils;
@ -63,9 +64,18 @@ public class TriggerInventory extends BCTrigger {
hasSlots = true;
ItemStack stack = slot.getStackInSlot();
foundItems |= stack != null && (searchedStack == null || StackHelper.canStacksMerge(stack, searchedStack));
foundSpace |= (stack == null || (StackHelper.canStacksMerge(stack, searchedStack) && stack.stackSize < stack.getMaxStackSize()))
&& (searchedStack == null || slot.canPutStackInSlot(searchedStack));
foundItems |= stack != null
&& (searchedStack == null || StackHelper.canStacksOrListsMerge(stack, searchedStack));
foundSpace |= (stack == null
|| (StackHelper.canStacksOrListsMerge(stack, searchedStack) && stack.stackSize < stack
.getMaxStackSize()))
&& (searchedStack == null || searchedStack.getItem() instanceof ItemList || slot
.canPutStackInSlot(searchedStack));
// On the test above, we deactivate item list as inventories
// typically don't check for lists possibility. This is a
// heuristic which is more desirable than expensive computation
// of list components or possibility of extension
}
if (!hasSlots) {

View file

@ -76,7 +76,7 @@ public class TriggerInventoryLevel extends BCTrigger {
for (IInvSlot slot : InventoryIterator.getIterable((IInventory) tile, side.getOpposite())) {
if (slot.canPutStackInSlot(searchStack)) {
ItemStack stackInSlot = slot.getStackInSlot();
if (stackInSlot == null || StackHelper.canStacksMerge(stackInSlot, searchStack)) {
if (stackInSlot == null || StackHelper.canStacksOrListsMerge(stackInSlot, searchStack)) {
stackSpace++;
foundItems += stackInSlot == null ? 0 : stackInSlot.stackSize;
}

View file

@ -21,7 +21,7 @@ import buildcraft.api.gates.ActionParameterItemStack;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.robots.IDockingStation;
import buildcraft.core.inventory.filters.ArrayFluidFilter;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
import buildcraft.core.inventory.filters.IFluidFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.inventory.filters.PassThroughFluidFilter;
@ -92,7 +92,7 @@ public class ActionRobotFilter extends BCActionPassive {
if (stacks.size() == 0) {
return new PassThroughStackFilter();
} else {
return new ArrayStackFilter(stacks.toArray(new ItemStack[stacks.size()]));
return new ArrayStackOrListFilter(stacks.toArray(new ItemStack[stacks.size()]));
}
}

View file

@ -115,7 +115,7 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IClien
foundFilter = true;
}
if (StackHelper.isMatchingItem(filter, event.item.getItemStack(), true, false)) {
if (StackHelper.isMatchingItemOrList(filter, event.item.getItemStack())) {
filteredOrientations.add(dir);
}
}

View file

@ -154,7 +154,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu
return null;
}
if (!StackHelper.isMatchingItem(filter, stack, true, false)) {
if (!StackHelper.isMatchingItemOrList(filter, stack)) {
continue;
}
@ -183,7 +183,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu
return false;
}
if (StackHelper.isMatchingItem(filter, stack, true, false)) {
if (StackHelper.isMatchingItemOrList(filter, stack)) {
return true;
}
}

View file

@ -22,6 +22,7 @@ import net.minecraftforge.fluids.FluidTankInfo;
import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
@ -77,9 +78,7 @@ public class TriggerPipeContents extends BCTrigger {
} else if (kind == PipeContents.containsItems) {
if (parameter != null && parameter.getItemStackToDraw() != null) {
for (TravelingItem item : transportItems.items) {
if (item.getItemStack().getItem() == parameter.getItemStackToDraw().getItem()
&& item.getItemStack().getItemDamage() == parameter.getItemStackToDraw()
.getItemDamage()) {
if (StackHelper.isMatchingItemOrList(parameter.getItemStackToDraw(), item.getItemStack())) {
return true;
}
}