Im trying to make a player event to where when you break a stained glass block, it drops that block. But, everytime I run the plugin, it drops the default stained glass (white) instead of the color I'm breaking. Code (Text): if (e.getBlock().getType() == Material.STAINED_GLASS){ e.setCancelled(true); e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(e.getBlock().getType())); e.getBlock().setType(Material.AIR); } What am I doing wrong? Im new to plugins, so... xD
Use: ItemStack glass =new ItemStack(Material.STAINED_GLASS, 1, (short)14); Or remove the (short) 14 part (this is for the actual color of the glass itself)
Maybe the OP is trying to making glass drop naturally on his server? Fortunate for you you're actually not that far off what you actually aim to achieve. You can call the Block#getData() method (note that it's deprecated) and assign it to your dropped itemstack Code (Text): if (e.getBlock().getType() == Material.STAINED_GLASS){ e.setCancelled(true); // Retrieving the data (color) of glass here byte data = e.getBlock().getData(); // Assigning the byte object to your itemstack e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(e.getBlock().getType(), data)); e.getBlock().setType(Material.AIR); }
Do you see my avatar? A famous quote from him was, "A person who never made a mistake, never tried anything new."
Now its not only dropping the same white stained glass, its dropping stacks of 15. LOL Code (Text): if (e.getBlock().getType() == Material.STAINED_GLASS){ e.setCancelled(true); // Retrieving the data (color) of glass here byte color = e.getBlock().getData(); // Assigning the byte object to your itemstack e.getBlock().getWorld().dropItem(e.getBlock().getLocation(), new ItemStack(e.getBlock().getType(), color)); e.getBlock().setType(Material.AIR); }