Create item?

Discussion in 'Plugin Development' started by Snowl, Jan 16, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Snowl

    Is it possible to have a block, when damaged to throw out an item? I can't figure out how to make it work, i'm such a noob :(
     
  2. Offline

    DjDCH

  3. Offline

    MadMichi

    Hi David, i'm a n00b too [​IMG]
    Did you find out how to put an item into the minecraft world?
    If yes, would you explain it? I searched in the javadocs and tryed some things but nothing worked for me...
    Thanks in advance
     
  4. Offline

    Snowl

    Nope, i'm just going to wait for a later version and hope that it will be implemented :p
     
  5. Offline

    MadMichi

  6. Offline

    MarkusNemesis

    So basically, you want to (for example) when you break sandstone, it drops a sandstone block?
     
  7. Offline

    MadMichi

    Basically yes, but a sandstone block is already dropped if you break sandstone? So if i wanted two sandstone blocks to be dropped, that would be it.
    What i really want is i.e. a dropped snowball if i break snow or something like that.
     
  8. Offline

    MarkusNemesis

    okay. well, Sandstone is nonreclaimable when placed, so hence why i used it as an example :) also, shovelling snow drops snowballs but i can see why you want it to be done with your hands etc, so give me a moment and ill see if i can get it working for you.
     
  9. Like MadMichi said, dropItemNaturally() is probably the way to go, something like this:
    Code:
    event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(Material.SNOW_BALL, 1));
    to use it you should only need to import

    Code:
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    Along with whatever imports you need for the event you are using.
     
  10. Offline

    MarkusNemesis

    I'll admit that i have no idea how to check if a block is being damaged. this:

    Code:
    public void onBlockDamaged(BlockDamageEvent event)
        {
            System.out.println("A block is being damaged!");
            System.out.println(event.getBlock().toString());
            if (event.getBlock().toString().equalsIgnoreCase("snow"))
            {
                event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(Material.SNOW_BALL));
            }
        }
    does not output anything in the console,

    Code:
    pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
    is the code registered.
     
  11. Its onBlockDamage() now, i dont think they've updated the hook names though so BLOCK_DAMAGED should still work.

    EDIT:
    I'm not sure that
    Code:
    event.getBlock().toString().equalsIgnoreCase("snow")
    will work, might be better to use
    Code:
    event.getBlock().getType() == Material.SNOW
     
  12. Offline

    MarkusNemesis

    Welp, i've got it.

    break a snow sheet and it gives you 2 snowballs. Doesn't check "in hand" for any tools or anything. oh, and it also randomly spawns a big tree...

    Code:
        public void onBlockDamage(BlockDamageEvent event)
        {
            if (event.getBlock().getType() == Material.SNOW )
            {
                if (event.getDamageLevel() == BlockDamageLevel.BROKEN)
                {
                    event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(Material.SNOW_BALL, 2));
                }
            }
        }
     
  13. Offline

    MadMichi

    Wohoo... it works!!one!

    A bukkit of win for both of you kind gentlemen! [​IMG]
     
  14. Offline

    MarkusNemesis

    My version also, if you break a snow sheet at your feet, it grows a tree :p but i didnt give you that bit.
     
  15. Offline

    Snowl

    Wow, works great!
    I have one problem though,
    fails epically :p What's wrong with it?

    Tried doing
    compiled fine, but insta-errored me AND corrupted my player.dat file in the world file, making me unable to log in 0.0
     
  16. Offline

    Archelaus

    Code:
    Material blockzor = event.getBlock().getType();
    Player player = event.getPlayer();
    dropItemNaturally(event.getPlayer().getLocation(), new ItemStack(blockzor, 1));

    I think works.
     
  17. Offline

    Snowl

    Worked. Some reason I recompiled and it stopped giving me errors and corruption o.o
     
  18. Offline

    MadMichi

  19. Offline

    Archelaus

Thread Status:
Not open for further replies.

Share This Page