Entity Collision Event?

Discussion in 'Plugin Development' started by spoony_loony, Aug 24, 2013.

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

    spoony_loony

    Hi guys!
    I have recently been working on a plugin that will fire exploding pigs from a special wand :p. SO, I need to figure out how to detect when the pigs actually collide with a block. I currently use the EntityDamageEvent to detect fall damage, but fall damage isn't always caused resulting in "Pigs of doom" just walking around!

    My code:

    Code:
    @Override
    public boolean use(Player p) {
    p.sendMessage("Wand fired!");
    final Vector dir = p.getEyeLocation().getDirection().multiply(2);
    Pig proj = (Pig) p.getWorld().spawn(p.getEyeLocation().add(dir.getX(), dir.getY(), dir.getZ()), Pig.class);
    proj.setCustomName(""+ChatColor.RESET+ChatColor.RED+"Pig of Doom");
    proj.setCustomNameVisible(true);
    proj.setVelocity(dir);
    listofpigs.add(proj.getEntityId());
    return true;
    }
     
    @EventHandler
    public void onEntityDamageEvent(EntityDamageEvent e) {
    if (listofpigs.contains(e.getEntity().getEntityId())) {
    Pig pig = (Pig) e.getEntity();
    listofpigs.remove(new Integer(pig.getEntityId()));
    pig.setHealth(0);
    e.getEntity().getWorld().createExplosion(e.getEntity().getLocation().getX(), e.getEntity().getLocation().getY(), e.getEntity().getLocation().getZ(), 4, false, false);
    }
    }
    
    Btw, the "use(Player p)" method is called with the PlayerInteractEvent.

    Thanks in advanced!
     
  2. Offline

    tommycake50

    What about tag the pigs and make a task that runs every tick(2 ticks if you want).
    And checks the location the pig is in and check if its location is touching any other blocks.
     
  3. Offline

    spoony_loony

    I considered this, but I was worried that it will lag too much... Any other ideas? (If not I may be forced to use that)
     
  4. Offline

    tommycake50

    afaik the lag wouldn't be bad as long as your check was quick.
     
  5. Offline

    LucasEmanuel

    tommycake50
    If you launch the pigs at great velocity, they will receive damage whenever they hit something solid. :)
     
  6. Offline

    tommycake50

    Uuuunless its a wall.
     
  7. Offline

    LucasEmanuel

    tommycake50
    If you launch them at a great velocity, they will receive damage since they hit it so darn hard. ;)

    EDIT:
    Haha, oh sorry. I'm gonna blame it on being tired. I temporarily forgot that minecraft doesn't deal damage that way. :)

    tommycake50
    Yea I realized this directly after I posted my response, check the edit ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Offline

    spoony_loony

    It seems I would create even greater lag if I don't use the scheduler, so that is what I am going to be stuck with. Thanks!
     
  9. you can spawn an arrow, and set the pig as passengier, if the location of the combination stays the same, it must have hit something solid
     
Thread Status:
Not open for further replies.

Share This Page