Solved StainedGlass Event

Discussion in 'Spigot Plugin Development' started by Minersof49ers, May 17, 2016.

  1. 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
     
    #1 Minersof49ers, May 17, 2016
    Last edited: May 17, 2016
  2. 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)
     
  3. And the stain glass will never drop naturally... So why are you doing this?
     
  4. 14 makes it red
    use ItemStack#setData(StainedGlassItem#getData());
    Maybe he wants it to drop
     
  5. I never thought of that... But then that is playerDropItemEvent
     
  6. no, maybe he wants to make the server drop stained glass naturally.
     
  7. 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);
            }
     
    • Agree Agree x 1
  8. ...Hmmmmmm I have no idea how that would be done then, any ideas?
     
  9. Yeah, this is what he should do, I didn't fully explain it in my post, thanks for expanding :)
     
  10. it's already answered in this thread
     
  11. I know, I didn't reload the page before it was posted...
     
    • Friendly Friendly x 1
  12. ah okay, no worries, wasn't bashing just explaining
     
    • Friendly Friendly x 1
  13. Thanks for all the help guys, but this is what I was looking for. XD
     
  14. [EDIT] Wait a second, I broke the block and nothing dropped. .-.
     
    • Agree Agree x 1
  15. LOL, "I think I can, I think I can, I think I can...."
     
  16. Lol, I'll just keep playing with it. Idk why it isn't working, everything's set up. xD
     
  17. Do you see my avatar? A famous quote from him was, "A person who never made a mistake, never tried anything new."
     
  18. Ah, yes I do. I keep making lots of mistakes on here, so it must be new... Lol that logic xD
     
  19. 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);
            }
     
  20. initialize an itemstack and set it's item amount.
     
    • Funny Funny x 1