Search in sources :

Example 1 with FILTER_SLOTS

use of mcjty.rftools.items.storage.StorageFilterContainer.FILTER_SLOTS 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)

Aggregations

HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 InventoryHelper (mcjty.lib.container.InventoryHelper)1 ItemStackList (mcjty.lib.varia.ItemStackList)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 IBlockState (net.minecraft.block.state.IBlockState)1 ITooltipFlag (net.minecraft.client.util.ITooltipFlag)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1 net.minecraft.util (net.minecraft.util)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextFormatting (net.minecraft.util.text.TextFormatting)1