[Unsolved] Entity Navigation

Discussion in 'Plugin Development' started by DSH105, May 9, 2013.

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

    DSH105

    I am trying to achieve controlled entity movement using the code below.

    Code:java
    1.  
    2. Object entityLiving = pet.getClass().getMethod("getHandle").invoke(pet);
    3. Object navigation = entityLiving.getClass().getMethod("getNavigation").invoke(entityLiving);
    4. Method nav_a = navigation.getClass().getMethod("a");
    5. nav_a.invoke(navigation, new Object[] {l.getX(), l.getY(), l.getZ(), 0.4f});
    6.  
    7.  
    8. /*net.minecraft.server.v1_5_R3.Navigation nav = ((net.minecraft.server.v1_5_R3.EntityLiving) ((org.bukkit.craftbukkit.v1_5_R3.entity.CraftEntity) pet).getHandle()).getNavigation();
    9. nav.a(l.getX(), l.getY(), l.getZ(), 0.4f);*/
    10.  



    If it helps, this is the error it produces:
    Show Spoiler

    Code:
     
    20:46:15 [SEVERE] java.lang.IllegalArgumentException
    20:46:15 [SEVERE]at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
    20:46:15 [SEVERE]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    20:46:15 [SEVERE]at java.lang.reflect.Method.invoke(Method.java:597)
    20:46:15 [SEVERE]at me.dsh105.echopet.data.Navigation$1.run(Navigation.java:93)
    20:46:15 [SEVERE]at org.bukkit.craftbukkit.v1_5_R3.scheduler.CraftTask.run(CraftTask.java:53)
    20:46:15 [SEVERE]at org.bukkit.craftbukkit.v1_5_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    20:46:15 [SEVERE]at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:513)
    20:46:15 [SEVERE]at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
    20:46:15 [SEVERE]at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
    20:46:15 [SEVERE]at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
    20:46:15 [SEVERE]at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    
    Line 93 is the "nav_a.invoke" bit.



    The NMS version-dependent method works well. Can someone help me see where I can improve? :)
     
  2. Offline

    caseif

    I've never done this before, but my guess would be that either a) the array you're passing to the method is of an improper size, or b) there's something wrong with "l".
     
  3. Offline

    DSH105

    AngryNerd
    Yeah, it's just that the method commented uses exactly the same arguments and it works fine.

    Bump. No-one else know this?

    EDIT: I think there's a problem getting the actual 'EntityLiving' through reflection, but I'm not entirely sure how to fix it.

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

    MP5K

    Hello _DSH105_,
    try change
    PHP:
    nav_a.invoke(navigation, new Object[] {l.getX(), l.getY(), l.getZ(), 0.4f});
    to:
    PHP:
    nav_a.invoke(navigation,l.getX(), l.getY(), l.getZ(), 0.4f);
     
  5. Offline

    DSH105

    Produces the same error. I think I need to cast entityLiving to EntityLiving before calling getNavigation()...But I'm not sure how to do that.

    Final bump...

    I guess this is going to have to remain unsolved then :\

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

    Deathmarine

    You seem to be looking in the wrong place for controlling movement up to actually modifing the ai, I would recommend looking into the pathfinding of the entity. Adding different targeting to entities or swapping around how the target and goal selector is stacked may help however I would tread lightly in this realm.

    https://github.com/Bukkit/CraftBukk...va/net/minecraft/server/EntityPig.java#L16-25

    Also with this in mind entity living is a super class to basically any entity that moves, and from what I can tell that method in Navigation.class doesn't do what you think it does.
     
Thread Status:
Not open for further replies.

Share This Page