EnderDragon does not go where I want. :(

Discussion in 'Plugin Development' started by Gamesareme, Jul 30, 2014.

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

    Gamesareme

    I am having trouble getting a dragon to fly where I want.
    This is my dragon class.
    Code:java
    1. public class CustomEntityEnderDragon extends EntityEnderDragon {
    2.  
    3. public CustomEntityEnderDragon(World world) {
    4. super(world);
    5. this.getAttributeInstance(GenericAttributes.a).setValue(100);
    6. this.setHealth(16);
    7. }
    8.  
    9. @Override
    10. public void dropDeathLoot(boolean flag, int i) {
    11. this.world.getWorld().dropItem(this.getBukkitEntity().getLocation(),
    12. new ItemStack(Material.DIAMOND));
    13. }
    14.  
    15. @Override
    16. public void e(float sideMot, float forMot) {
    17. if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
    18. super.e(sideMot, forMot);
    19. return;
    20. }
    21.  
    22. this.lastYaw = this.yaw = this.passenger.yaw;
    23. this.pitch = this.passenger.pitch * 0.5F;
    24.  
    25. this.b(this.yaw, this.pitch);
    26. this.aO = this.aM = this.yaw;
    27.  
    28. this.W = 0.5F;
    29. this.Y = this.passenger.Y - 1;
    30.  
    31. sideMot = ((EntityLiving) this.passenger).bd * 0.5F;
    32. forMot = ((EntityLiving) this.passenger).be;
    33.  
    34. if (forMot <= 0.0F) {
    35. forMot *= 0.25F;
    36. }
    37. sideMot *= 0.75F;
    38.  
    39. final float speed = 0.35F;
    40. this.i(speed);
    41. super.e(sideMot, forMot);
    42.  
    43. }
    44.  
    45. }

    Then I spawn and get on the dragon using this.
    Code:java
    1. CustomEntityEnderDragon dragon = new CustomEntityEnderDragon(((CraftWorld)player.getWorld()).getHandle());
    2. dragon.setLocation(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getLocation().getPitch(), player.getLocation().getYaw());
    3. ((CraftWorld)player.getWorld()).getHandle().addEntity(dragon, SpawnReason.CUSTOM);
    4. dragon.getBukkitEntity().setPassenger(player);

    I have registered this in the enable with this.
    Code:java
    1. CustomEntityTypeDragon.registerEntities();

    But when I try and make the dragon turn and go where I want it just continues to go where it wants.
    What do I need to change?

    Bump :p

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

    xTDKx

    The EnderDragon has a different AI than regular mobs, so that probably won't work.
     
  3. Offline

    ResultStatic

    Gamesareme you need to remove all the pathfinders yourself and add custom ones. it can be complicated finding certain blocks. the way i did it in my plugin is i extended PathFinderGoal then used the worldedit api to determine if that certain block was in range. if it did i would return true on a(). when you return true on boolean a() public void e() runs, so you can make it run to the block that you found on a()
     
  4. Offline

    Ka-Boomba

  5. Offline

    ResultStatic

    Ka-Boomba well i created this method that returns the list for goalselector and targetselector.

    Code:
    private List b = new UnsafeList();
    cast the object it returns to UnsafeList and clear it. then you can add what ever pathfinders you want. remember pathfinders use priority. most ground mobs start with pathfinderfloat as priority 1 so they dont drown. then ones that flee from the sun, or find targets then lesser priorities like wander or play. also i had trouble modifying health i had to override aC() and change stuff for my custom mob, it was a wolf tho.

    Code:
      public static Object getGoalSelectorListB(PathfinderGoalSelector p){
          try {
            Field f = p.getClass().getDeclaredField("b");
            f.setAccessible(true);
            return f.get(p);
        } catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
      }
    }
    Code:
    public UnsafeList<PathfinderGoal> getGoalsSelectorList(){
    return (UnsafeList<PathfinderGoal>) Nms.getGoalSelectorListB(this.goalSelector);
    }
     
    public UnsafeList<PathfinderGoal> getTargetSelectorList(){
    return (UnsafeList<PathfinderGoal>) Nms.getGoalSelectorListB(this.targetSelector);
    }
     
  6. Offline

    Gamesareme

    ResultStatic Would I put this in the dragon class or enum. I believe that it would be the class, but I would want to be sure.
     
  7. Offline

    ResultStatic

    Gamesareme put it in the dragon class, clear the list and add ur pathfinders in ur constructor. im looking in the EntityEnderDragon class and i dont see any pathfinders registered in the constructor which is weird. it might still work though
     
  8. Offline

    Gamesareme

    ResultStatic I am sorry, but I do not know how to do that. Could someone please explain what I need to do? :(
     
  9. Offline

    ResultStatic

    Gamesareme your going to need to look at source code and problem solve yourself. there wont be people who know exactly what you want to do with nms.
     
Thread Status:
Not open for further replies.

Share This Page