Dropping an item that can't be picked up?

Discussion in 'Plugin Development' started by ron975, Aug 14, 2012.

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

    ron975

    Is there any way that I can drop an ItemStack, but without anyone being able to pick it up?
    Essentially, I need to drop the sprite of an item, but without it being able to be picked up as an item.
     
  2. Offline

    Malikk

    I would suggest assigning it metadata, then checking for that metadata on the pickup event and cancelling accordingly.
     
  3. Offline

    ron975

    I'm pretty noob at Bukkit Plugin Development, and Java, in general. The metadata section here isn't very helpful.. Can you give me some tips?
     
  4. Offline

    Malikk

    Basically, all your doing is assigning a key, which is used to check your metadata, and a value, which in this case, you don't really need. I set my value to a simple boolean, since it doesnt matter.

    Code:
    item.setMetadata("myKey", new FixedMetadataValue(plugin, true));
    
    Now, to check if an item has our metadata we use
    Code:
    boolean hasMetadata = item.hasMetadata("myKey");
    
    The key doesnt matter, as long as its the same in both places.

    Now you can cancel the ItemPickupEvent based on that boolean.
     
    ron975 likes this.
  5. Offline

    ron975

    I tried this today, I can't setMetadata to an ItemStack.
     
  6. Offline

    Malikk

    Not to the ItemStack, sorry, to the item entity, I didn't specify.
     
  7. Offline

    ron975

    How do I define an item then? Can I cast an ItemStack into an Item?
     
  8. Offline

    Malikk

    Well, you're dropping the item yourself, right?
    Code:
    world.dropItem(location, ItemStack);
    
    You can just set that equal to an entity,
    Code:
    Entity item = world.dropItem(location, ItemStack);
    
     
  9. Offline

    ron975


    So I can do
    Code:
    Entity item = world.dropItem(location, ItemStack);
    item.setMetadata("key", new FixedMetadataValue(plugin, true);
    
     
  10. Offline

    Malikk

    Yup, should be good to go
     
Thread Status:
Not open for further replies.

Share This Page