How would I get all the contents in a chest and then calling them to Item. I want to be able to shoot the items out of a chest into the sky.
Code: /* * import org.bukkit.block.Block; * import org.bukkit.block.Chest; * import org.bukkit.entity.Item; * import org.bukkit.inventory.ItemStack; * import org.bukkit.util.Vector; */ public void explodeChest(Block b) { // check if block is a chest if(b.getState() instanceof Chest) { // get the content of the chest and clone it ItemStack[] items = ((Chest) b.getState()).getInventory().getContents().clone(); // clear the content of the chest (prevent duplication) ((Chest) b.getState()).getInventory().clear(); // iterate through all items for(ItemStack item : items) { // prevent nullpointer exception from empty slots if(item != null) { // drop item one block above the chest Item i = b.getWorld().dropItem(b.getLocation().add(0, 1, 0), item); // add upwards velocity to the item i.setVelocity(new Vector(0,.5,0)); } } } }
He just wanted to help... @undeaD_D I suggest you comment your code to explain what it does. That way it's not 100% spoonfeeding. Thank you for helping
@Signatured But he could still just copy and paste and not read the comments. The best thing to do is just give him 'pseudocode' instructions.
@FisheyLP Thanks, I tried basically that but I forgot the BlockInventory part. @undeaD_D How would I go about shooting the items slower, like instead of shooting them all at once?
Inside the repeating task Loop through the items -> if it is not air -> shoot it -> remove the item from inventory -> break;