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);
}
Aggregations