NMS More Range

Discussion in 'Plugin Development' started by Plugers11, Jul 28, 2014.

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

    Plugers11

    How could I make a hostile mob able to acquire and track targets that are further than the default limit of 16 blocks?
     
  2. Offline

    GameplayJDK

  3. Offline

    Plugers11

  4. Offline

    GameplayJDK

    Plugers11 Hmm... It's 1.6 code, possibly some classes and fields got renamed.. But it should do the thing
    I don't know if this code is still working, it's from 2012 too :/
    Code:java
    1. private boolean livingEntityMoveTo(LivingEntity livingEntity, double x, double y, double z, float speed) {
    2. return ((org.bukkit.craftbukkit.entity.CraftLivingEntity)livingEntity).getHandle().getNavigation().a(x, y, z, speed);
    3. }
     
  5. Offline

    Plugers11

    I know how to navigate mob ..
    But if blocks range is < 16 then path is null
     
  6. Offline

    GameplayJDK

    Plugers11
    Possibly you can try to navigate the mob step by step.. calculate the next position within 16 blocks, then the next and than the next again..
     
  7. Offline

    Plugers11

  8. Offline

    GameplayJDK

    Plugers11 I have ever been someone who trys to avoid working with nms too much because the resulting solutions are not very version persistent and cause a lot of updating work, so I'm not that familiar with the possibilities.. :/
     
  9. Offline

    Deleted user

    Plugers11
    Let me get back to you on this.
     
  10. Offline

    Plugers11

    zombiekiller753
    How to set to go on location ?
    I have this:

    But how do this for my creeper?

    Code:
    import java.lang.reflect.Field;
     
    import net.minecraft.server.v1_7_R3.EntityInsentient;
    import net.minecraft.server.v1_7_R3.PathEntity;
    import net.minecraft.server.v1_7_R3.PathfinderGoal;
    import net.minecraft.server.v1_7_R3.PathfinderGoalFloat;
    import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
     
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftLivingEntity;
    import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    import org.bukkit.entity.LivingEntity;
     
    public class WalkToLocation {
     
        private static Field gsa;
        private static Field goalSelector;
        private static Field targetSelector;
     
        static {
            try {
                gsa = PathfinderGoalSelector.class.getDeclaredField("b");
                gsa.setAccessible(true);
     
                goalSelector = EntityInsentient.class.getDeclaredField("goalSelector");
                goalSelector.setAccessible(true);
     
                targetSelector = EntityInsentient.class.getDeclaredField("targetSelector");
                targetSelector.setAccessible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
        @SuppressWarnings("deprecation")
        public static void gotoLoc(LivingEntity e) {
            try {
                Object nms_entity = ((CraftLivingEntity) e).getHandle();
                if (nms_entity instanceof EntityInsentient) {
     
                    PathfinderGoalSelector goal = (PathfinderGoalSelector) goalSelector.get(nms_entity);
                    PathfinderGoalSelector target = (PathfinderGoalSelector) targetSelector.get(nms_entity);
     
                    gsa.set(goal, new UnsafeList<Object>());
                    gsa.set(target, new UnsafeList<Object>());
     
                    goal.a(0, new PathfinderGoalFloat((EntityInsentient) nms_entity));
                    goal.a(1, new PathfinderGoalWalktoTile((EntityInsentient) nms_entity));
     
                } else {
                    throw new IllegalArgumentException(e.getType().getName() + " is not an instance of an EntityInsentient.");
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
       
        public static void gotoLocCreep(CustomCreeper e) {
            try {
                Object nms_entity = e.getBukkitEntity();
                if (nms_entity instanceof EntityInsentient) {
     
                    PathfinderGoalSelector goal = (PathfinderGoalSelector) goalSelector.get(nms_entity);
                    PathfinderGoalSelector target = (PathfinderGoalSelector) targetSelector.get(nms_entity);
     
                    gsa.set(goal, new UnsafeList<Object>());
                    gsa.set(target, new UnsafeList<Object>());
     
                    goal.a(0, new PathfinderGoalFloat((EntityInsentient) nms_entity));
                    goal.a(1, new PathfinderGoalWalktoTile((EntityInsentient) nms_entity));
     
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
     
        public static class PathfinderGoalWalktoTile extends PathfinderGoal {
     
            public EntityInsentient entity;
            public PathEntity path;
     
            public PathfinderGoalWalktoTile(EntityInsentient entitycreature) {
                this.entity = entitycreature;
            }
     
            @Override
            public boolean a() {
           
                        boolean flag = this.entity.getNavigation().c();
                        this.entity.getNavigation().b(false);
                        this.path = this.entity.getNavigation().a(425 , 83, 402);
                        System.out.println(path);
                        this.entity.getNavigation().b(flag);
           
                        if (this.path != null) {
                            this.c();
                        }
               
                return this.path != null;
            }
     
            @Override
            public void c() {
                this.entity.getNavigation().a(this.path, 0.8D);
            }
        }
    }
    
    This can be for walk to location of mob ?

    Code:
    import net.minecraft.server.v1_7_R3.EntityInsentient;
    import net.minecraft.server.v1_7_R3.Navigation;
    import net.minecraft.server.v1_7_R3.PathEntity;
    import net.minecraft.server.v1_7_R3.PathfinderGoal;
     
    import org.bukkit.Location;
     
    public class PathfinderGoalWalkToLoc extends PathfinderGoal
    {
      private double speed;
     
      private EntityInsentient entity;
     
      private Location loc;
     
      private Navigation navigation;
     
      public PathfinderGoalWalkToLoc(EntityInsentient entity, Location loc, double speed)
      {
        this.entity = entity;
        this.loc = loc;
        this.navigation = this.entity.getNavigation();
        this.speed = speed;
      }
     
      public boolean a()
      {
        return true;
      }
     
      public void c()
      {
          PathEntity pathEntity = this.navigation.a(loc.getX(), loc.getY(), loc.getZ());
     
          this.navigation.a(pathEntity, speed);
      }
    }
     
    
    Code:
    public CustomCreeper(net.minecraft.server.v1_7_R3.World world) {
            super(world);
            this.getAttributeInstance(GenericAttributes.a).setValue(48.0D);
            this.goalSelector.a(1, new PathfinderGoalWalkToLoc(this, getToLocation(), 2D));
        }
    Ok i solved go to location but now i'm waiting for this range @zombiekiller753 :(

    I think it's done :3
    I must do attribute :D

    protected void aC() {
    super.aC();
    this.getAttributeInstance(GenericAttributes.b).setValue(100.0D);
    }

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

Share This Page