Solved Set wolves (or any passive mob) to angry

Discussion in 'Plugin Development' started by WhosDaMan, Jan 9, 2014.

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

    WhosDaMan

    After I spawn a few wolves using
    Code:java
    1. target.getWorld().spawnEntity(wolfSpawnLoc.add(0, 1, 0), EntityType.WOLF);

    in a for-loop, I want them to attack the player they spawn around. I'm having some difficulties doing this. The way I have been trying to do it is by using an Event Handler like so:
    Code:java
    1. @EventHandler
    2. public void onEntitySpawn(CreatureSpawnEvent event) {
    3. if (event.getSpawnReason().equals("CUSTOM")) {
    4. Wolf w = (Wolf) event.getEntity();
    5. w.setAngry(true);
    6. }
    7. }

    To be honest, I'm not even sure if that onEntitySpawn is doing anything in the first place.

    Is there a more efficient way to set a passive mob to angry that works, and how can I implement it?

    Here's the rest of my code: https://github.com/SlightThought/Sl...Angry Wolves/src/com/gmail/nabaymiller/wolves
     
  2. Offline

    Seadragon91

    The method spawnEntity returns a entity.
    Code:java
    1. Wolf w = (Wolf) target.getWorld().spawnEntity(wolfSpawnLoc.add(0, 1, 0), EntityType.WOLF);
    2. w.setAngry(true);
     
  3. Offline

    WhosDaMan

    It worked, but I am crushed that the one method to solve all my problems only sets their eyes to red, as if they are angry. The wolves don't attack. After that I wrote "w.setTarget(player)" but that didn't make a difference - the wolves are still passive on creation.

    Code:java
    1. if (wolfSpawnLoc.getBlock().getType() != Material.AIR) {
    2. Wolf w = (Wolf) target.getWorld().spawnEntity(wolfSpawnLoc.add(0, 1, 0), EntityType.WOLF);
    3. w.setAngry(true);
    4. w.setTarget(player);
    5. break;
    6. }


    Seadragon91

    Up to the top we go!

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

    DrJava

    Code:
    EntityWolf nmsWolf = ((CraftWolf) wolf).getHandle();
    nmsWolf.setTarget(((CraftPlayer) player).getHandle());
    nmsWolf.setGoalTarget(((CraftPlayer) player).getHandle());
    
     
Thread Status:
Not open for further replies.

Share This Page