Search in sources :

Example 11 with ItemStackList

use of mcjty.lib.varia.ItemStackList in project RFToolsControl by McJty.

the class CraftingStationTileEntity method findItem.

private int findItem(String itemName, int meta, String nbtString) {
    int index = 0;
    for (BlockPos p : processorList) {
        TileEntity te = getWorld().getTileEntity(p);
        if (te instanceof ProcessorTileEntity) {
            ProcessorTileEntity processor = (ProcessorTileEntity) te;
            ItemStackList items = ItemStackList.create();
            processor.getCraftableItems(items);
            for (ItemStack item : items) {
                if (item.getItemDamage() == meta && itemName.equals(item.getItem().getRegistryName().toString())) {
                    if (item.hasTagCompound()) {
                        if (nbtString.equalsIgnoreCase(item.serializeNBT().toString())) {
                            return index;
                        }
                    } else {
                        return index;
                    }
                }
                index++;
            }
        }
    }
    return -1;
}
Also used : ProcessorTileEntity(mcjty.rftoolscontrol.blocks.processor.ProcessorTileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ProcessorTileEntity(mcjty.rftoolscontrol.blocks.processor.ProcessorTileEntity) ItemStackList(mcjty.lib.varia.ItemStackList) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 12 with ItemStackList

use of mcjty.lib.varia.ItemStackList in project RFToolsControl by McJty.

the class CraftingStationTileEntity method findCraftableItem.

private Pair<ProcessorTileEntity, ItemStack> findCraftableItem(int index) {
    for (BlockPos p : processorList) {
        TileEntity te = getWorld().getTileEntity(p);
        if (te instanceof ProcessorTileEntity) {
            ProcessorTileEntity processor = (ProcessorTileEntity) te;
            ItemStackList items = ItemStackList.create();
            processor.getCraftableItems(items);
            for (ItemStack item : items) {
                if (index == 0) {
                    // found!
                    return Pair.of(processor, item);
                }
                index--;
            }
        }
    }
    return null;
}
Also used : ProcessorTileEntity(mcjty.rftoolscontrol.blocks.processor.ProcessorTileEntity) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ProcessorTileEntity(mcjty.rftoolscontrol.blocks.processor.ProcessorTileEntity) ItemStackList(mcjty.lib.varia.ItemStackList) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 13 with ItemStackList

use of mcjty.lib.varia.ItemStackList in project RFToolsControl by McJty.

the class CraftingCardItem method getStacksFromItem.

public static ItemStackList getStacksFromItem(ItemStack craftingCard) {
    NBTTagCompound tagCompound = craftingCard.getTagCompound();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
        craftingCard.setTagCompound(tagCompound);
    }
    ItemStackList stacks = ItemStackList.create(CraftingCardContainer.INPUT_SLOTS + 1);
    NBTTagList bufferTagList = tagCompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < bufferTagList.tagCount(); i++) {
        NBTTagCompound nbtTagCompound = bufferTagList.getCompoundTagAt(i);
        stacks.set(i, new ItemStack(nbtTagCompound));
    }
    return stacks;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ItemStackList(mcjty.lib.varia.ItemStackList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 14 with ItemStackList

use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.

the class RemoteStorageItemInventory method isItemValidForSlot.

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
    ItemStackList s = getStacks();
    if (index >= s.size()) {
        return false;
    }
    if (isServer()) {
        RemoteStorageTileEntity storage = getRemoteStorage();
        if (storage == null) {
            return false;
        }
        int si = storage.findRemoteIndex(getStorageID());
        if (si == -1) {
            return false;
        }
        if (index >= storage.getMaxStacks(si)) {
            return false;
        }
    }
    return true;
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList)

Example 15 with ItemStackList

use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.

the class RemoteStorageTileEntity method decrStackSizeRemote.

public ItemStack decrStackSizeRemote(int si, int index, int amount) {
    if (index >= slots[si].size()) {
        return ItemStack.EMPTY;
    }
    ItemStackList stacks = slots[si];
    boolean hasOld = !stacks.get(index).isEmpty();
    ItemStack its = ItemStack.EMPTY;
    if (!stacks.get(index).isEmpty()) {
        if (stacks.get(index).getCount() <= amount) {
            ItemStack old = stacks.get(index);
            stacks.set(index, ItemStack.EMPTY);
            its = old;
        } else {
            its = stacks.get(index).splitStack(amount);
            if (stacks.get(index).isEmpty()) {
                stacks.set(index, ItemStack.EMPTY);
            }
        }
    }
    boolean hasNew = !stacks.get(index).isEmpty();
    if (hasOld && !hasNew) {
        numStacks[si]--;
    } else if (hasNew && !hasOld) {
        numStacks[si]++;
    }
    StorageModuleItem.updateStackSize(getStackInSlot(si), numStacks[si]);
    markDirty();
    return its;
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStackList (mcjty.lib.varia.ItemStackList)30 ItemStack (net.minecraft.item.ItemStack)21 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 TileEntity (net.minecraft.tileentity.TileEntity)5 BlockPos (net.minecraft.util.math.BlockPos)5 GenericTileEntity (mcjty.lib.entity.GenericTileEntity)4 ProcessorTileEntity (mcjty.rftoolscontrol.blocks.processor.ProcessorTileEntity)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 InventoryHelper (mcjty.lib.container.InventoryHelper)1 BlockRenderEvent (mcjty.lib.gui.events.BlockRenderEvent)1 RFTools (mcjty.rftools.RFTools)1 ModularStorageTileEntity (mcjty.rftools.blocks.storage.ModularStorageTileEntity)1 GenericRFToolsItem (mcjty.rftools.items.GenericRFToolsItem)1 FILTER_SLOTS (mcjty.rftools.items.storage.StorageFilterContainer.FILTER_SLOTS)1