How can I fill a chest of this type? Code (Text): FallingBlock block = map.spawnFallingBlock(objspawn, Material.CHEST, (byte) 0);
I would create an inventory and put whatever you want in there and attach it to a chest and put that as Material.CHEST
That, is technically, not a chest, it is a falling entity, that looks like a chest. So, you need to determine where the falling block lands, spawn a chest of your type with your inventory of custom items, or fill the chest normally.
And something like that Code (Text): public void ChestItem() { ItemStack item = new ItemStack(Material.CHEST, 1); ItemMeta meta = item.getItemMeta(); meta.setDisplayName("§aSupply Drop"); item.setItemMeta(meta); }
It has nothing to do with what you're doing it with... Just listen to: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityChangeBlockEvent.html and check if the entity is one of the falling sand objects from your plugin. Then get the resulting block's state and cast to chest (making sure it is actually a chest as good code would dictate), and add your items to its inventory (retrieved through #getBlockInventory()).
Code (Text): @EventHandler public void fallingChest(EntityChangeBlockEvent event){ if (event.getEntityType() == EntityType.FALLING_BLOCK) { if (event.getEntity() instanceof FallingBlock){ FallingBlock fb = (FallingBlock) event.getEntity(); if (fb.getMaterial() == Material.CHEST){ event.setCancelled(true); event.getBlock().setType(Material.CHEST); Chest chest = (Chest) event.getBlock().getState(); Inventory inv = chest.getInventory(); inv.addItem(new ItemStack(Material.WOOD,1)); } } } }
or Code (Text): public void fallingChest(EntityChangeBlockEvent event){ FallingBlock fallingBlock = (FallingBlock) event.getEntity(); if (fallingBlock.getMaterial() == Material.CHEST) { Chest chest = (Chest) event.getBlock().getState(); Inventory inv = chest.getInventory(); inv.addItem(new ItemStack(Material.WOOD,1)); } }