Is Creature.setTarget() borked?

Discussion in 'Plugin Development' started by TheButlah, Jun 28, 2013.

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

    TheButlah

    hi guys, i was working on a plugin that would allow the player to tame hostile mobs. I successfully was able to keep track of which mobs went with which player, but was unable to get the mobs to stop attacking their owner. I tried hooking into the EntityTargetEvent and cancel/set its target to null if it was targetting its owner but that didnt work. One of my friends mentioned to me that the setTarget() method was broken in bukkit 1.5.2 and i was wondering if this was true.
     
  2. Offline

    CubieX

    Most mobs cannot be controlled with "setTarget()" properly anymore.
    The AI works now with "goals" instead of the old target-system since a couple of versions.
    Making a mob not attack someone can be done by cancel the "EntityTargetLivingEntityEvent", before the mob has targeted the player.
    If he already has, you would have to delete this mob and spawn a new one in the same location (for example),
    so you can suppress it's targeting of a player from the beginning.
    At least this is the way I do it.

    I never used the "goal"-system yet.
    Someone other has to explain it, if you want or do need to use it.
     
  3. Offline

    travja

    If you want to remove their target, assuming it was a snowgolem, I would suggest doing something like this:
    Code:java
    1. @EventHandler
    2. public void damage(EntityDamageByEntityEvent event){
    3. Entity e = event.getEntity();
    4. Entity ed = event.getDamager();
    5. if(e.getType()== EntityType.SNOWMAN){
    6. CraftSnowman snow = (CraftSnowman) e;
    7. snow.getHandle().setGoalTarget(null);
    8. }
    9. }
     
Thread Status:
Not open for further replies.

Share This Page