Development Assistance Modded PathfinderNormal - how to add to custom unit?

Discussion in 'Plugin Help/Development/Requests' started by Azuna1, Dec 14, 2014.

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

    Azuna1

    Ok so i created a
    PathfinderNormalModded (open)

    Code:
    import net.minecraft.server.Block;
    import net.minecraft.server.BlockCobbleWall;
    import net.minecraft.server.BlockDoor;
    import net.minecraft.server.BlockFence;
    import net.minecraft.server.BlockFenceGate;
    import net.minecraft.server.BlockMinecartTrackAbstract;
    import net.minecraft.server.BlockPosition;
    import net.minecraft.server.Blocks;
    import net.minecraft.server.Entity;
    import net.minecraft.server.IBlockAccess;
    import net.minecraft.server.Material;
    import net.minecraft.server.MathHelper;
    import net.minecraft.server.PathPoint;
    import net.minecraft.server.PathfinderAbstract;
    
    public class PathfinderNormalModded extends PathfinderNormal {
    
        private boolean f;
        private boolean g;
        private boolean h;
        private boolean i;
        private boolean j;
    
        public PathfinderNormalModded() {}
    
        public void a(IBlockAccess iblockaccess, Entity entity) {
            super.a(iblockaccess, entity);
            this.j = this.h;
        }
    
        public void a() {
            super.a();
            this.h = this.j;
        }
    
        public PathPoint a(Entity entity) {
            int i;
    
            if (this.i && entity.V()) {
                i = (int) entity.getBoundingBox().b;
    
                for (Block block = this.a.getType(new BlockPosition(MathHelper.floor(entity.locX), i, MathHelper.floor(entity.locZ))).getBlock(); block == Blocks.FLOWING_WATER || block == Blocks.WATER; block = this.a.getType(new BlockPosition(MathHelper.floor(entity.locX), i, MathHelper.floor(entity.locZ))).getBlock()) {
                    ++i;
                }
    
                this.h = false;
            } else {
                i = MathHelper.floor(entity.getBoundingBox().b + 0.5D);
            }
    
            return this.a(MathHelper.floor(entity.getBoundingBox().a), i, MathHelper.floor(entity.getBoundingBox().c));
        }
    
        public PathPoint a(Entity entity, double d0, double d1, double d2) {
            return this.a(MathHelper.floor(d0 - (double) (entity.width / 2.0F)), MathHelper.floor(d1), MathHelper.floor(d2 - (double) (entity.width / 2.0F)));
        }
    
        public int a(PathPoint[] apathpoint, Entity entity, PathPoint pathpoint, PathPoint pathpoint1, float f) { // f = max distance
                int i = 0;
        byte b0 = 0;
    
        if (this.a(entity, pathpoint.a, pathpoint.b + 1, pathpoint.c) == 1) {
            b0 = 1;
        }
    
        PathPoint pathpoint2 = this.a(entity, pathpoint.a, pathpoint.b, pathpoint.c + 1, b0);
        PathPoint pathpoint3 = this.a(entity, pathpoint.a - 1, pathpoint.b, pathpoint.c, b0);
        PathPoint pathpoint4 = this.a(entity, pathpoint.a + 1, pathpoint.b, pathpoint.c, b0);
        PathPoint pathpoint5 = this.a(entity, pathpoint.a, pathpoint.b, pathpoint.c - 1, b0);
    
        if (pathpoint2 != null && !pathpoint2.i && pathpoint2.a(pathpoint1) < f) {
            apathpoint[i++] = pathpoint2;
        }
    
        if (pathpoint3 != null && !pathpoint3.i && pathpoint3.a(pathpoint1) < f) {
            apathpoint[i++] = pathpoint3;
        }
    
        if (pathpoint4 != null && !pathpoint4.i && pathpoint4.a(pathpoint1) < f) {
            apathpoint[i++] = pathpoint4;
        }
    
        if (pathpoint5 != null && !pathpoint5.i && pathpoint5.a(pathpoint1) < f) {
            apathpoint[i++] = pathpoint5;
        }
    
        return i;
        }
    
        private PathPoint a(Entity entity, int i, int j, int k, int l) {//checks for best block to move to
            PathPoint pathpoint = null;
            int i1 = this.a(entity, i, j, k);  // returns flag of processAdjacentTile
    
            if (i1 == 2) { // normal solid block + all good
                return this.a(i, j, k); // add block to hashmap
            } else {
                if (i1 == 1) {
                    pathpoint = this.a(i, j, k); // normal solid block &  add block to hashmap
                }
    
                if (pathpoint == null && l > 0 && i1 != -3 && i1 != -4 && this.a(entity, i, j + l, k) == 1) {
                    pathpoint = this.a(i, j + l, k);
                    j += l;
                }
    
                if (pathpoint != null) {
                    int j1 = 0;
    
                    int k1;
    
                    for (k1 = 0; j > 0; pathpoint = this.a(i, j, k)) {
                        k1 = this.a(entity, i, j - 1, k);
                        if (this.h && k1 == -1) { //if all y blocks are water
                            return null;
                        }
    
                        if (k1 != 1) { // if normal block
                            break;
                        }
    
                        if (j1++ >= 2) { // if cliff higher than X blocks exit check changed form 4 to 2
                            return null;
                        }
    
                        --j;
                        if (j <= 0) {
                            return null; // if out of map
                        }
                    }
    
                    if (k1 == -2) {
                        return null; // something with lava
                    }
                }
    
                return pathpoint;
            }
        }
    
        private int a(Entity entity, int i, int j, int k) {
            return a(this.a, entity, i, j, k, this.c, this.d, this.e, this.h, this.g, this.f);
        }
    
        public static int a(IBlockAccess iblockaccess, Entity entity, int i, int j, int k, int l, int i1, int j1, boolean flag, boolean flag1, boolean flag2) { //processAdjacentTiles
            boolean flag3 = false;
            BlockPosition blockposition = new BlockPosition(entity);
    
            for (int k1 = i; k1 < i + l; ++k1) {
                for (int l1 = j; l1 < j + i1; ++l1) {
                    for (int i2 = k; i2 < k + j1; ++i2) {
                        BlockPosition blockposition1 = new BlockPosition(k1, l1, i2);
                        Block block = iblockaccess.getType(blockposition1).getBlock();
    
                        if (block.getMaterial() != Material.AIR) {
                            if (block != Blocks.TRAPDOOR && block != Blocks.IRON_TRAPDOOR) {
                                if (block != Blocks.FLOWING_WATER && block != Blocks.WATER) {
                                    if (!flag2 && block instanceof BlockDoor && block.getMaterial() == Material.WOOD) {
                                        return 0; //can break door, isDoor, is Wood
                                    }
                                } else {
                                    if (flag) {
                                        return -1; //if all Y blocks are water (RECHECK!) todo
                                    }
    
                                    flag3 = true;
                                }
                            } else {
                                flag3 = true;
                            }
    
                            if (entity.world.getType(blockposition1).getBlock() instanceof BlockMinecartTrackAbstract) {
                                if (!(entity.world.getType(blockposition).getBlock() instanceof BlockMinecartTrackAbstract) && !(entity.world.getType(blockposition.down()).getBlock() instanceof BlockMinecartTrackAbstract)) {
                                    return -3;
                                }
                            } else if (!block.b(iblockaccess, blockposition1) && (!flag1 || !(block instanceof BlockDoor) || block.getMaterial() != Material.WOOD)) { // solid && (cantBreak || no door || not wood)
                                if (block instanceof BlockFence || block instanceof BlockFenceGate || block instanceof BlockCobbleWall) {
                                    return -3; // we cant walk on fence/wall/gates
                                }
    
                                if (block == Blocks.TRAPDOOR || block == Blocks.IRON_TRAPDOOR) {
                                    return -4;
                                }
    
                                Material material = block.getMaterial();
    
                                if (material != Material.LAVA) {
                                    return 0;
                                }
    
                                if (!entity.ab()) { //not standing in lava
                                    return -2;
                                }
                            }
                        }
                    }
                }
            }
    
            return flag3 ? 2 : 1; // true = 1, false = 2
        }
    
        public void a(boolean flag) {
            this.f = flag;
        }
    
        public void b(boolean flag) {
            this.g = flag;
        }
    
        public void c(boolean flag) {
            this.h = flag;
        }
    
        public void d(boolean flag) {
            this.i = flag;
        }
    
        public boolean b() {
            return this.f;
        }
    
        public boolean d() {
            return this.i;
        }
    
        public boolean e() {
            return this.h;
        }
    }
    

    and
    NavigationCustom (open)

    Code:
    
    
    import net.minecraft.server.EntityInsentient;
    import net.minecraft.server.Navigation;
    import net.minecraft.server.Pathfinder;
    import net.minecraft.server.World;
    
    public class NavigationCustom extends Navigation  {
    
       
        public NavigationCustom(EntityInsentient entityinsentient, World world) {
            super(entityinsentient, world);
        }
    
        @Override
        protected Pathfinder a() {
            this.a = new PathfinderNormalModded();
            this.a.a(true);
            return new Pathfinder(this.a);
        }
    
    }
    
    

    and put
    Code:
    @Override
        protected NavigationAbstract b(World world) {
            return new NavigationCustom(this, world);
        }
    
    into my public class EntityZombieTest extends EntityZombie
    to apply the modded Pathfinder class (in this case the only difference would be that it no longer considers cliffs to jump down)


    solved

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

Share This Page