Solved [UNSOLVED] Entity walk to tile not working

Discussion in 'Plugin Development' started by leimekiller, May 8, 2014.

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

    leimekiller

    Hey guys,

    I am trying to let an entity move to a specific location, but it doesn't work.

    Here's my code:

    CustomEntityPig:
    Code:java
    1. package com.me.test;
    2.  
    3. import net.minecraft.server.v1_7_R2.*;
    4. import org.bukkit.Location;
    5. import org.bukkit.craftbukkit.v1_7_R2.util.UnsafeList;
    6.  
    7. import java.lang.reflect.Field;
    8.  
    9. public class CustomEntityPig extends EntityPig {
    10. public CustomEntityPig(World world, Location target) {
    11. super(world);
    12.  
    13. try {
    14. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    15. bField.setAccessible(true);
    16. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    17. cField.setAccessible(true);
    18. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    19. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    20. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    21. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    22. } catch (Exception exc) {
    23. exc.printStackTrace();
    24. }
    25.  
    26. this.goalSelector.a(0, new PathFinderGoalWalkToTile(this, target));
    27. this.goalSelector.a(1, new PathfinderGoalFloat(this));
    28. this.goalSelector.a(2, new PathfinderGoalPassengerCarrotStick(this, 0.3F));
    29. this.goalSelector.a(3, new PathfinderGoalBreed(this, 1.0D));
    30. this.goalSelector.a(4, new PathfinderGoalTempt(this, 1.2D, Items.CARROT_STICK, false));
    31. this.goalSelector.a(5, new PathfinderGoalTempt(this, 1.2D, Items.CARROT, false));
    32. this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 6.0F));
    33. this.goalSelector.a(7, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 6.0F, true));
    34. }
    35. }
    36.  


    PathfinderWalkToTile:
    Code:java
    1. package com.me.test;
    2.  
    3. import net.minecraft.server.v1_7_R2.EntityCreature;
    4. import net.minecraft.server.v1_7_R2.PathfinderGoal;
    5. import org.bukkit.Location;
    6.  
    7. public class PathFinderGoalWalkToTile extends PathfinderGoal
    8. {
    9. private EntityCreature entitycreature;
    10.  
    11. private double x = 0;
    12. private double y = 100;
    13. private double z = 100;
    14.  
    15. public PathFinderGoalWalkToTile(EntityCreature entitycreature, Location target)
    16. {
    17. this.entitycreature = entitycreature;
    18. this.x = target.getX();
    19. this.y = target.getY();
    20. this.z = target.getZ();
    21. }
    22.  
    23.  
    24. public boolean a()
    25. {
    26. return true;
    27. }
    28.  
    29. public void c()
    30. {
    31. this.entitycreature.getNavigation().a(x, y, z, 1);
    32. }
    33. }


    Spawn command:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. Player player = (Player) sender;
    4.  
    5. if(cmd.getName().equalsIgnoreCase("test"))
    6. {
    7. Location loc = player.getLocation();
    8.  
    9. CustomEntityPig pig = new CustomEntityPig(((CraftWorld)player.getWorld()).getHandle(), new Location(player.getWorld(), 100, 100, 100));
    10. pig.setLocation(loc.getX(), loc.getY(), loc.getZ(), 1, 1);
    11. ((CraftWorld)player.getWorld()).getHandle().addEntity(pig);
    12. }
    13.  
    14. return true;
    15. }


    So it spawns the entity just fine, it just does everything right except the PathFinderWalkToTile.

    Anyone?

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

    Mathias Eklund

    nms can be a bitch. Make sure you got the correct methods. Have you double checked with the nms code, and not just copied of a tutorial? Got a stacktrace we can see aswell?
     
  3. Offline

    leimekiller

    Mathias Eklund There is no error. And yes I have double checked the code.

    I tried doing this:

    Code:java
    1. System.out.println(this.entitycreature.getNavigation().a(loc.getX(), loc.getY(), loc.getZ()));


    So now I know the problem, it's always null for some reason. I tried using reflections to make the l() method which returns a boolean true, but that didn't work either.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page