Search in sources :

Example 21 with ItemStackList

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

the class StorageFilterItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    if (playerIn.isSneaking()) {
        if (!worldIn.isRemote) {
            TileEntity te = worldIn.getTileEntity(pos);
            if (InventoryHelper.isInventory(te)) {
                ItemStackList stacks = ItemStackList.create();
                Set<ResourceLocation> registeredItems = new HashSet<>();
                InventoryHelper.getItems(te, s -> true).forEach(s -> addItem(te, stacks, registeredItems, s));
                if (!stack.hasTagCompound()) {
                    stack.setTagCompound(new NBTTagCompound());
                }
                StorageFilterInventory.convertItemsToNBT(stack.getTagCompound(), stacks);
                playerIn.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Stored inventory contents in filter"), false);
            } else {
                IBlockState state = worldIn.getBlockState(pos);
                ItemStack blockStack = state.getBlock().getItem(worldIn, pos, state);
                if (!blockStack.isEmpty()) {
                    if (!stack.hasTagCompound()) {
                        stack.setTagCompound(new NBTTagCompound());
                    }
                    Set<ResourceLocation> registeredItems = new HashSet<>();
                    ItemStackList stacks = ItemStackList.create(FILTER_SLOTS);
                    NBTTagList bufferTagList = stack.getTagCompound().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));
                    }
                    for (int i = 0; i < FILTER_SLOTS; i++) {
                        if (stacks.get(i).isEmpty()) {
                            stacks.set(i, blockStack);
                            playerIn.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Added " + blockStack.getDisplayName() + " to the filter!"), false);
                            StorageFilterInventory.convertItemsToNBT(stack.getTagCompound(), stacks);
                            break;
                        }
                    }
                }
            }
        }
        return EnumActionResult.SUCCESS;
    }
    return super.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
Also used : ModularStorageTileEntity(mcjty.rftools.blocks.storage.ModularStorageTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) net.minecraft.util(net.minecraft.util) Constants(net.minecraftforge.common.util.Constants) InventoryHelper(mcjty.lib.container.InventoryHelper) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) Keyboard(org.lwjgl.input.Keyboard) HashSet(java.util.HashSet) ItemStackList(mcjty.lib.varia.ItemStackList) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) ModularStorageTileEntity(mcjty.rftools.blocks.storage.ModularStorageTileEntity) Side(net.minecraftforge.fml.relauncher.Side) FILTER_SLOTS(mcjty.rftools.items.storage.StorageFilterContainer.FILTER_SLOTS) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) RFTools(mcjty.rftools.RFTools) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) GenericRFToolsItem(mcjty.rftools.items.GenericRFToolsItem) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) IBlockState(net.minecraft.block.state.IBlockState) ItemStackList(mcjty.lib.varia.ItemStackList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 22 with ItemStackList

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

the class ModifierItem method getItemStacks.

public static ItemStackList getItemStacks(NBTTagCompound tagCompound) {
    NBTTagList bufferTagList = tagCompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    ItemStackList stacks = ItemStackList.create(ModifierContainer.COUNT_SLOTS);
    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 23 with ItemStackList

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

the class ModifierItem method addOp.

private static void addOp(ItemStack stack, ModifierFilterType type, ModifierFilterOperation op) {
    List<ModifierEntry> modifiers = getModifiers(stack);
    NBTTagCompound tagCompound = stack.getTagCompound();
    ItemStackList stacks = getItemStacks(tagCompound);
    ItemStack stackIn = stacks.get(ModifierContainer.SLOT_FILTER);
    ItemStack stackOut = stacks.get(ModifierContainer.SLOT_REPLACEMENT);
    modifiers.add(new ModifierEntry(stackIn, stackOut, type, op));
    stacks.set(ModifierContainer.SLOT_FILTER, ItemStack.EMPTY);
    stacks.set(ModifierContainer.SLOT_REPLACEMENT, ItemStack.EMPTY);
    ModifierInventory.convertItemsToNBT(tagCompound, stacks);
    updateModifiers(stack, modifiers);
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 24 with ItemStackList

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

the class ModifierItem method delOp.

private static void delOp(ItemStack stack, int index) {
    List<ModifierEntry> modifiers = getModifiers(stack);
    ModifierEntry entry = modifiers.get(index);
    ItemStack in = entry.getIn();
    ItemStack out = entry.getOut();
    NBTTagCompound tagCompound = stack.getTagCompound();
    ItemStackList stacks = getItemStacks(tagCompound);
    if (!in.isEmpty() && !stacks.get(ModifierContainer.SLOT_FILTER).isEmpty()) {
        // Something is in the way
        return;
    }
    if (!out.isEmpty() && !stacks.get(ModifierContainer.SLOT_REPLACEMENT).isEmpty()) {
        // Something is in the way
        return;
    }
    if (!in.isEmpty()) {
        stacks.set(ModifierContainer.SLOT_FILTER, in.copy());
    }
    if (!out.isEmpty()) {
        stacks.set(ModifierContainer.SLOT_REPLACEMENT, out.copy());
    }
    ModifierInventory.convertItemsToNBT(tagCompound, stacks);
    modifiers.remove(index);
    updateModifiers(stack, modifiers);
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 25 with ItemStackList

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

the class RFToolsJeiPlugin method transferRecipe.

public static void transferRecipe(Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients, BlockPos pos) {
    ItemStackList items = ItemStackList.create(10);
    for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : guiIngredients.entrySet()) {
        int recipeSlot = entry.getKey();
        List<ItemStack> allIngredients = entry.getValue().getAllIngredients();
        if (!allIngredients.isEmpty()) {
            items.set(recipeSlot, allIngredients.get(0));
        }
    }
    RFToolsMessages.INSTANCE.sendToServer(new PacketSendRecipe(items, pos));
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map)

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