@EventHandler public void onPlace(BlockPlaceEvent event){ BlockState state = event.getBlockPlaced().getState(); if(state instanceof ShulkerBox){ event.setCancelled(true); } }
public void setBoxInventory(Inventory inventory){ if(item.getItemMeta() instanceof BlockStateMeta){ BlockStateMeta im = (BlockStateMeta)item.getItemMeta(); if(im.getBlockState() instanceof ShulkerBox){ ShulkerBox shulker = (ShulkerBox) im.getBlockState(); shulker.getInventory().setContents(inventory.getContents()); im.setBlockState(shulker); item.setItemMeta(im); return; } } return; }
public Inventory getBoxInventory(){ Inventory inv = Bukkit.createInventory(null, 27, "Bank"); if(item.getItemMeta() instanceof BlockStateMeta){ BlockStateMeta im = (BlockStateMeta)item.getItemMeta(); if(im.getBlockState() instanceof ShulkerBox){ ShulkerBox shulker = (ShulkerBox) im.getBlockState(); inv.setContents(shulker.getInventory().getContents()); return inv; } } return inv; }
@Override public SerialItemData initialize(ItemStack stack) { TNE.debug("ShulkerData.initialize."); if(SerialItem.isShulker(stack.getType())) { TNE.debug("Passed shulker check"); ItemMeta meta = stack.getItemMeta(); if(meta instanceof BlockStateMeta) { TNE.debug("Is BlockStateMeta"); BlockStateMeta state = (BlockStateMeta)meta; if(state.getBlockState() instanceof ShulkerBox) { TNE.debug("Is ShulkerBox BlockState"); valid = true; ShulkerBox shulker = (ShulkerBox)state.getBlockState(); Inventory inventory = shulker.getInventory(); TNE.debug("Initializing shulker box.."); for(int i = 0; i < inventory.getSize(); i++) { if(inventory.getItem(i) == null || inventory.getItem(i).getType().equals(Material.AIR)) { if(items.containsKey(i)) { items.remove(i); TNE.debug("Removing item from slot " + i); } } else { TNE.debug("Adding Item: " + inventory.getItem(i).getType().name()); TNE.debug("Item Slot: " + i); items.put(i, new SerialItem(inventory.getItem(i))); } } } } } return this; }
@Override public ItemStack build(ItemStack stack) { if(valid) { BlockStateMeta meta = (BlockStateMeta)stack.getItemMeta(); ShulkerBox shulkerBox = (ShulkerBox)meta; items.forEach((slot, item)->shulkerBox.getInventory().setItem(slot, item.getStack())); meta.setBlockState(shulkerBox); stack.setItemMeta(meta); } return stack; }