Chest Animation.

Discussion in 'Spigot Plugin Development' started by RealAstro, Sep 15, 2018.

  1. I'm making a crate plugin but i need help adding a chest animation with the reward coming out of it when clicking the chest with a key

    Code
    Code (Java):
            if (e.getClickedBlock().getType() == Material.CHEST && is.getItemMeta().getDisplayName().equals(Utils.chat("&8[&d!&8] &eRank Crate &8[&d!&8]"))) {
                if (e.getPlayer().getItemInHand().getType() == Material.NETHER_STAR && is.getItemMeta().getDisplayName().equals(Utils.chat("&8[&a!&8] &aRank&7 Crate Key &8[&a!&8]"))) {
                    int  n = random.nextInt(100) + 1;
                    if (n<=1) {
                        for (ItemStack Demon : player.getInventory().getContents()) {
                            if (is.getType() == Material.PAPER && is.hasItemMeta() && is.getItemMeta().hasDisplayName() && is.getItemMeta().getDisplayName().equalsIgnoreCase("&8&l[&4!&8] &r&4&lDemon&r&7 Rank &8&l[&4!&8]&r")) {
                                ItemStack item = Demon;
                                player.getInventory().addItem(Demon);
                            }
                        }
                    }  
                    for (ItemStack key : player.getInventory().getContents()) {
                        if (is.getType() == Material.NETHER_STAR && is.hasItemMeta() && is.getItemMeta().hasDisplayName() && is.getItemMeta().getDisplayName().equalsIgnoreCase("&8[&a!&8] &aRank&7 Crate Key &8[&a!&8]")) {
                            player.getInventory().remove(key);

                        }
                    }
                } else {
                    player.sendMessage(Utils.chat("&8[&d!&8]&e You need a Rank Key to open this Crate"));
                }
            }
     
  2. What is exactly not working, pass some more information to us.
    Also, I see you use color codes with & instead of the paragraph character in equal statements which is absoluty wrong.
     
  3. i'm using an event that allows me to use color codes in code
     
  4. i want to implement a chest opening animation and the reward coming out of it
     
  5. Interested in finding out how this can be done. Bump.
     
  6. The way I do this is: spawn an item at the chest, then just give it a small upward and outward velocity.

    Spawning an item In the world creates an Item object, you can set the pickup delay to a long time so the item can’t be picked up by players.

    You’ll also need to track the items so you can despawn them after a second or two. And by track them I mean add them to a set/map/list/object



    Sent from my iPhone using Tapatalk
     
  7. Would it be possible to make the chest appear as open?
     
  8. Yeah, look into the blockstate of the chest or if that won’t work in your particular version you may have to send a packet to the client to show the chest as open.


    Sent from my iPhone using Tapatalk
     
    • Informative Informative x 1
  9. correct me if i'm wrong
    Code (Java):
            Location location = chest.getLocation();
            WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
            BlockPosition position = new BlockPosition(location.getX(), location.getY(), location.getZ());
            TileEntityChest tileChest = (TileEntityChest) world.getTileEntity(position);
            world.playBlockAction(position, tileChest.w(), 1, open ? 1 : 0);
     

Share This Page