Solved Getting the inventory of a shulker box itemstack

Discussion in 'Spigot Plugin Development' started by Yadeses, Jan 25, 2017.

  1. So I have a plugin, which worked fine until shulker boxes were implemented with 1.11. This plugin modifies all the food in inventories to make it decay over time. But with the introduction of shulker boxes there is a problem. When they are just placed down it is fine, but when you break one and pick it up, my plugin can no longer access the inventory of the shulker box and change its contents.

    Does anyone know how to access this? All I read about accessing the block entity tag, where the inventory is stored according to the minecraft wiki, was that it is impossible to get to.

    Thank you for your response,
    Yadeses
     
  2. sample of how to get the inventory:


    Code (Java):

      ItemStack item = shulkerBoxItemStack;
            if(item.getItemMeta() instanceof BlockStateMeta){
                BlockStateMeta im = (BlockStateMeta)item.getItemMeta();
                if(im.getBlockState() instanceof ShulkerBox){
                    ShulkerBox shulker = (ShulkerBox) im.getBlockState();
                    Inventory inv = Bukkit.createInventory(null, 27, "Shulker Box");
                    inv.setContents(shulker.getInventory().getContents());
                    player.openInventory(inv);
                }
            }
     
    • Useful Useful x 2
  3. Thank you a lot.