Solved Changing DisplayName of dropped item

Discussion in 'Spigot Plugin Development' started by benyji, Jun 30, 2020.

  1. Hey all,

    I've successfully created a code snippet in which checks if a certain block is broken and then changes the dropped item to a custom one, in this case CLAY_BRICK. My problem lies in the naming of said dropped item.
    Code (Java):
        @EventHandler
        public void onBreak(BlockBreakEvent event) {
             Player player = event.getPlayer();
             Block block = (Block) event.getBlock();
             if (block.getTypeId() == 247) {
                    ItemStack droppedBlock;
                droppedBlock = new ItemStack(Material.CLAY_BRICK, 1);
                event.getBlock().setType(Material.AIR);
                event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), new ItemStack(droppedBlock));
                 ItemMeta m = droppedBlock.getItemMeta();
                m.setDisplayName("Copper Ingot");
                 droppedBlock.setItemMeta(m);


             }
           
        }
    I know don't scream at me for using item ID's but thats besides the point, I have no idea why it doesn't want to change the name of the item, you help is much appreciated.
     
  2. Maybe you need to set that before drop it.
     
    • Agree Agree x 1
  3. loool quickest debug of my life, thanks so much aha!