Set target of tamed wolf

Discussion in 'Plugin Development' started by MisterErwin, Jul 7, 2013.

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

    MisterErwin

    Hello together,

    how can I let a tamed wolf/dog attack an entity?
    The wolf growls, but he won't attack...

    I've tried to to
    Code:
    Wolf dog;
    dog.setAngry(true);
    AND:
    Entity target;
    dog.setTarget(target);
    Is there any way?
    Or do I have to modify the behavior?

    Thanks,
    MisterErwin
     
  2. Offline

    xTrollxDudex

    MisterErwin
    Are you new to this? You need to assign values to fields to make them work.
    I remembered a post that allowed you to set a target without setTarget() ill find it

    MisterErwin
    Thx DarkBladee12
    Code:java
    1.  
    2. Location loc = p.getLocation();
    3. EntityLiving el = ((CraftLivingEntity) sheep).getHandle();
    4. Navigation n = el.getNavigation();
    5. n.a(loc.getX(), loc.getY(), loc.getZ(), VELOCITY);
    6.  
    7. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  3. Offline

    macguy8

    Code:java
    1.  
    2.  
    3. Wha.... The reason it's not working now is just that you have to call .setAngry(true) and .setTarget(LivingEntity) and .setSitting(false).
     
  4. Offline

    MisterErwin

    Thanks, but that would be only the "walking-toward-player" method.

    And: Since 1.6 you have to get your Navigation otherwise:
    Code:java
    1. Navigation n = ((EntityInsentient)((CraftLivingEntity) e).getHandle()).getNavigation();


    ;)
     
  5. Offline

    xTrollxDudex

    macguy8
    Fine.
    Code:java
    1. //listener, entitydamagebyentity event
    2. Entity damager = e.getDamager();
    3. Entity damaged = e.getEntity();
    4.  
    5. if(damaged instanceof Wolf && damager instanceof Player){
    6. e.setCancelled(true);
    7. Wolf wolf = (Wolf) damaged;
    8. wolf.setOwner(damager);
    9. }
    10.  
    11. public void makeAngry(Player p){
    12. LivingEntity ply = (LivingEntity) p;
    13.  
    14. wolf.setSitting(false);
    15. wolf.setAngry(true);
    16. wolf.setTarget(ply);
    17. }
    18.  
    19. //in another class
    20. Dog.makeAngry(/*whatever*\);
     
  6. Offline

    MisterErwin

  7. Offline

    xTrollxDudex

    MisterErwin
    Did you copy and paste my code? I noticed you've developed some plugins before, shouldn't you try to implement this a s best as you can? Anyway I really don't have time, tag me again so I can answer this as soon a s possible
     
Thread Status:
Not open for further replies.

Share This Page