@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
TileEntityPedestal tile = getTileEntity(world, pos);
IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
if (!player.isSneaking()) {
if (heldItem.isEmpty()) {
player.setHeldItem(hand, itemHandler.extractItem(0, 64, false));
} else {
player.setHeldItem(hand, itemHandler.insertItem(0, heldItem, false));
}
tile.markDirty();
} else {
ItemStack stack = itemHandler.getStackInSlot(0);
if (!stack.isEmpty()) {
String localized = TutorialMod.proxy.localize(stack.getUnlocalizedName() + ".name");
player.addChatMessage(new TextComponentString(stack.getCount() + "x " + localized));
} else {
player.addChatMessage(new TextComponentString("Empty"));
}
}
}
return true;
}
From https://shadowfacts.net/tutorials/forge-modding-112/tile-entities-inventory/