1.14.4 Custom skulls break drop

Discussion in 'Spigot Plugin Development' started by LinkOfArrow, Mar 24, 2020.

  1. So I am trying to make it when a custom skull is destroyed by a player that the skull then will drop with a custom name. And I got the part from when a mob is killed that it would drop that custom skull with the custom name but not how to make it so it will also drop like the same if it is placed and then broken.
    This is my code:
    Code (Text):
            if(en instanceof Spider) {
                if (plugin.getConfig().getBoolean("Drops.MobHeads.Enabled")) {
                    chance = plugin.getConfig().getInt("Drops.MobHeads.Chance");
                    rand = new Random();
                    fact = rand.nextInt(100);
                    if (fact <= chance) {
                        ItemStack Spskull = new ItemStack(Material.PLAYER_HEAD);
                        SkullMeta skullmeta = (SkullMeta) Spskull.getItemMeta();
                        skullmeta.setOwner("MHF_Spider");
                        skullmeta.setDisplayName(Utils.chat("&eSpider's Skull"));
                        Spskull.setItemMeta(skullmeta);
                        e.getDrops().add(Spskull);
                    }
                }
            }
        }
     
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
            ItemStack Spskull = new ItemStack(Material.PLAYER_HEAD);
            SkullMeta skullmeta = (SkullMeta) Spskull.getItemMeta();
            skullmeta.setOwner("MHF_Spider");
            Spskull.setItemMeta(skullmeta);
            if (e.getBlock() == Spskull) {
                ItemStack SpSkull = new ItemStack(Material.PLAYER_HEAD);
                SkullMeta skullMeta = (SkullMeta) SpSkull.getItemMeta();
                skullMeta.setOwner("MHF_Spider");
                skullMeta.setDisplayName(Utils.chat("&eSpider's Skull"));
                SpSkull.setItemMeta(skullMeta);
                e.getBlock().getDrops().clear();
                e.getBlock().getDrops().add(SpSkull);
            }
    And this is the skull when broken from the ground:
    http://imgur.com/a/nOUqwsx
    [​IMG]
    And this is the skull when dropped from a spider:
    [​IMG]
    http://imgur.com/a/6evN0VD
     
  2. Please write a little bit useful so i can realise what's the problem. What it is?
     
  3. You can store the name you want in the block using the PersistentDataContainer when the player places down your spider head. You then listen to the BlockBreakEvent, check if the block that got broken has your value in its data container, if so read it and disable the normal drops (#setDropItems) and then drop the modified item using World#dropItemNaturally.
     
    • Like Like x 1