Making non-pickupable floating Item/Block entities

Discussion in 'Plugin Development' started by AndrewAnderVille, Sep 17, 2012.

Thread Status:
Not open for further replies.
  1. Hey guys just a quick question. For a plugin I'm currently working on I need to make floating Item/Block entities that you can't pickup. Do you know of anyways of doing this ?
     
  2. Offline

    chasechocolate

  3. Offline

    kyle1320

    AndrewAnderVille
    If you don't want to root through source, this works:
    Code:
    @EventHandler
    public void onDrop(PlayerDropItemEvent event) {
        event.getItemDrop().setMetadata("nopickup", null);
    }
     
    @EventHandler
    public void onPickup(PlayerPickupItemEvent event) {
        if (event.getItem().hasMetadata("nopickup")) {
            event.setCancelled(true);
        }
    }
    Basically just tag the item with metadata, then when someone tries to pick it up check if it has that metadata
     
  4. Offline

    Tzeentchful

    I would create a listener for an item pickup and simply cancel the event if it's the correct item.
    PHP:
     @EventHandler(priority EventPriority.HIGH)
    publicvoidpickup(PlayerPickupItemEventevent){
    if(
    event.getItem().equals(myitem)){
    event.setCancelled(true);
    }
    }
     
  5. Thanks :D
     
Thread Status:
Not open for further replies.

Share This Page