"Tagging" Projectiles

Discussion in 'Plugin Development' started by rogerin0, Jan 9, 2013.

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


    I'm working on a plugin that allows different types of items to fire projectiles with different properties. For example, right-clicking with a stick will launch a snowball that deals 2 damage. Right-clicking with a diamond will launch a snowball that deals 10 damage.

    But how can you differentiate between snowballs that are launched by diamonds and the snowballs that are launched by sticks? Checking the item in the player's hand upon the EntityDamage event is not an option, as the player can easily switch items during the projectile's flight-time. Checking whether or not the player has a stick or diamond in his inventory will not work if the player has both.

    It appears the only possible solution is to "tag" projectiles with a special value. Allowing the launched projectile to be tagged with, for example, a 'launchedByStick' variable. Upon a EntityDamage event, check if the snowball has the 'launchedByStick' tag on it, and if so, deal 2 damage.

    Is this possible? And if not, what would you suggest?
  2. Offline


    Add MetaData to the projectile entity.
  3. Offline


    Snowball snow = (Snowball) player.launchProjectile(Snowball.class);
    snow.setMetadata("Label", new FixedMetadataValue(this, "YourLabel"));
        //Meanwhile in other events.
    if(entity instanceof Snowball && entity.hasMetadata("Label")){
            //Do something
            //Do other things.
Thread Status:
Not open for further replies.

Share This Page