From 041abb71bc087c693e1c183be4a3bcecb686a336 Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Sat, 5 Nov 2022 00:47:36 -0400 Subject: [PATCH 1/6] Kam Is God --- .../net/minecraft/util/math/BlockPos.java | 232 +++++++++++--- .../npcs/ai/pathfinder/FlyPathFinder.java | 295 +++++++++++++----- 2 files changed, 411 insertions(+), 116 deletions(-) diff --git a/src/main/java/net/minecraft/util/math/BlockPos.java b/src/main/java/net/minecraft/util/math/BlockPos.java index b9aa29c1b..04472fb26 100644 --- a/src/main/java/net/minecraft/util/math/BlockPos.java +++ b/src/main/java/net/minecraft/util/math/BlockPos.java @@ -1,18 +1,32 @@ package net.minecraft.util.math; -import com.google.common.collect.AbstractIterator; import java.util.Iterator; +import java.util.List; + +import javax.annotation.concurrent.Immutable; + +import net.minecraft.util.Vec3i; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.google.common.collect.AbstractIterator; +import com.google.common.collect.Lists; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.Entity; import net.minecraft.util.EnumFacing; -import net.minecraft.util.Vec3; -import net.minecraft.util.Vec3i; +import net.minecraft.util.MathHelper; -/** This code is owned by Minecraft */ - -public class BlockPos extends Vec3i{ +/** + */ +@Immutable +public class BlockPos extends Vec3i +{ + private static final Logger LOGGER = LogManager.getLogger(); /** The BlockPos with all coordinates 0 */ public static final BlockPos ORIGIN = new BlockPos(0, 0, 0); - private static final int NUM_X_BITS = 1 + 25;//MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); + private static final int NUM_X_BITS = 26; //1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); //Manually calculated because of crash private static final int NUM_Z_BITS = NUM_X_BITS; private static final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS; private static final int Y_SHIFT = 0 + NUM_Z_BITS; @@ -36,11 +50,6 @@ public class BlockPos extends Vec3i{ this(source.posX, source.posY, source.posZ); } - public BlockPos(Vec3 source) - { - this(source.xCoord, source.yCoord, source.zCoord); - } - public BlockPos(Vec3i source) { this(source.getX(), source.getY(), source.getZ()); @@ -217,6 +226,9 @@ public class BlockPos extends Vec3i{ return new BlockPos(i, j, k); } + /** + * Create an Iterable that returns all positions in the box specified by the given corners + */ public static Iterable getAllInBox(BlockPos from, BlockPos to) { final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ())); @@ -270,6 +282,21 @@ public class BlockPos extends Vec3i{ }; } + /** + * Returns a version of this BlockPos that is guaranteed to be immutable. + * + *

When storing a BlockPos given to you for an extended period of time, make sure you + * use this in case the value is changed internally.

+ */ + public BlockPos toImmutable() + { + return this; + } + + /** + * Like getAllInBox but reuses a single MutableBlockPos instead. If this method is used, the resulting BlockPos + * instances can only be used inside the iteration loop. + */ public static Iterable getAllInBoxMutable(BlockPos from, BlockPos to) { final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ())); @@ -325,35 +352,25 @@ public class BlockPos extends Vec3i{ }; } - /** - * Returns a version of this BlockPos that is guaranteed to be Immutable. - * In most cases this will return 'this', but if 'this' is an instance of - * MutableBlockPos it will return a new instance of BlockPos with the same values. - * - * When storing a parameter given to you for an extended period of time, make sure you - * use this in case the value is changed internally. - * - * @return An immutable BlockPos. - */ - public BlockPos getImmutable() - { - return this; - } - - public static final class MutableBlockPos extends BlockPos + public static class MutableBlockPos extends BlockPos { /** Mutable X Coordinate */ - private int x; + protected int x; /** Mutable Y Coordinate */ - private int y; + protected int y; /** Mutable Z Coordinate */ - private int z; + protected int z; public MutableBlockPos() { this(0, 0, 0); } + public MutableBlockPos(BlockPos pos) + { + this(pos.getX(), pos.getY(), pos.getZ()); + } + public MutableBlockPos(int x_, int y_, int z_) { super(0, 0, 0); @@ -363,7 +380,7 @@ public class BlockPos extends Vec3i{ } /** - * Get the X coordinate + * Gets the X coordinate. */ public int getX() { @@ -371,7 +388,7 @@ public class BlockPos extends Vec3i{ } /** - * Get the Y coordinate + * Gets the Y coordinate. */ public int getY() { @@ -379,7 +396,7 @@ public class BlockPos extends Vec3i{ } /** - * Get the Z coordinate + * Gets the Z coordinate. */ public int getZ() { @@ -387,13 +404,9 @@ public class BlockPos extends Vec3i{ } /** - * Set the values - * - * @param xIn The X value - * @param yIn The Y value - * @param zIn The Z value + * Sets the position, MUST not be name 'set' as that causes obfusication conflicts with func_185343_d */ - public BlockPos.MutableBlockPos set(int xIn, int yIn, int zIn) + public BlockPos.MutableBlockPos setPos(int xIn, int yIn, int zIn) { this.x = xIn; this.y = yIn; @@ -401,6 +414,143 @@ public class BlockPos extends Vec3i{ return this; } - @Override public BlockPos getImmutable() { return new BlockPos(this); } + public BlockPos.MutableBlockPos setPos(double p_189532_1_, double p_189532_3_, double p_189532_5_) + { + return this.setPos(MathHelper.floor_double(p_189532_1_), MathHelper.floor_double(p_189532_3_), MathHelper.floor_double(p_189532_5_)); + } + + @SideOnly(Side.CLIENT) + public BlockPos.MutableBlockPos setPos(Entity p_189535_1_) + { + return this.setPos(p_189535_1_.posX, p_189535_1_.posY, p_189535_1_.posZ); + } + + public BlockPos.MutableBlockPos setPos(Vec3i p_189533_1_) + { + return this.setPos(p_189533_1_.getX(), p_189533_1_.getY(), p_189533_1_.getZ()); + } + + public BlockPos.MutableBlockPos move(EnumFacing p_189536_1_) + { + return this.move(p_189536_1_, 1); + } + + public BlockPos.MutableBlockPos move(EnumFacing p_189534_1_, int p_189534_2_) + { + return this.setPos(this.x + p_189534_1_.getFrontOffsetX() * p_189534_2_, this.y + p_189534_1_.getFrontOffsetY() * p_189534_2_, this.z + p_189534_1_.getFrontOffsetZ() * p_189534_2_); + } + + public void setY(int yIn) + { + this.y = yIn; + } + + /** + * Returns a version of this BlockPos that is guaranteed to be immutable. + * + *

When storing a BlockPos given to you for an extended period of time, make sure you + * use this in case the value is changed internally.

+ */ + public BlockPos toImmutable() + { + return new BlockPos(this); + } + } + + public static final class PooledMutableBlockPos extends BlockPos.MutableBlockPos + { + private boolean released; + private static final List POOL = Lists.newArrayList(); + + private PooledMutableBlockPos(int xIn, int yIn, int zIn) + { + super(xIn, yIn, zIn); + } + + public static BlockPos.PooledMutableBlockPos retain() + { + return retain(0, 0, 0); + } + + public static BlockPos.PooledMutableBlockPos retain(double xIn, double yIn, double zIn) + { + return retain(MathHelper.floor_double(xIn), MathHelper.floor_double(yIn), MathHelper.floor_double(zIn)); + } + + @SideOnly(Side.CLIENT) + public static BlockPos.PooledMutableBlockPos retain(Vec3i vec) + { + return retain(vec.getX(), vec.getY(), vec.getZ()); + } + + public static BlockPos.PooledMutableBlockPos retain(int xIn, int yIn, int zIn) + { + synchronized (POOL) + { + if (!POOL.isEmpty()) + { + BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = (BlockPos.PooledMutableBlockPos)POOL.remove(POOL.size() - 1); + + if (blockpos$pooledmutableblockpos != null && blockpos$pooledmutableblockpos.released) + { + blockpos$pooledmutableblockpos.released = false; + blockpos$pooledmutableblockpos.set(xIn, yIn, zIn); + return blockpos$pooledmutableblockpos; + } + } + } + + return new BlockPos.PooledMutableBlockPos(xIn, yIn, zIn); + } + + public void release() + { + synchronized (POOL) + { + if (POOL.size() < 100) + { + POOL.add(this); + } + + this.released = true; + } + } + + public BlockPos.PooledMutableBlockPos set(int xIn, int yIn, int zIn) + { + if (this.released) + { + BlockPos.LOGGER.error("PooledMutableBlockPosition modified after it was released.", new Throwable()); + this.released = false; + } + + return (BlockPos.PooledMutableBlockPos)super.setPos(xIn, yIn, zIn); + } + + @SideOnly(Side.CLIENT) + public BlockPos.PooledMutableBlockPos set(Entity p_189537_1_) + { + return (BlockPos.PooledMutableBlockPos)super.setPos(p_189537_1_); + } + + public BlockPos.PooledMutableBlockPos set(double xIn, double yIn, double zIn) + { + return (BlockPos.PooledMutableBlockPos)super.setPos(xIn, yIn, zIn); + } + + public BlockPos.PooledMutableBlockPos set(Vec3i vec) + { + return (BlockPos.PooledMutableBlockPos)super.setPos(vec); + } + + public BlockPos.PooledMutableBlockPos offsetMutable(EnumFacing facing) + { + return (BlockPos.PooledMutableBlockPos)super.move(facing); + } + + public BlockPos.PooledMutableBlockPos movePos(EnumFacing p_189538_1_, int p_189538_2_) + { + return (BlockPos.PooledMutableBlockPos)super.move(p_189538_1_, p_189538_2_); + } } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java index 9bb05603f..bc80d92a8 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java @@ -7,7 +7,9 @@ import net.minecraft.init.Blocks; import net.minecraft.pathfinding.PathFinder; import net.minecraft.util.IntHashMap; import net.minecraft.util.MathHelper; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; +import noppes.npcs.entity.EntityNPCInterface; public class FlyPathFinder extends PathFinder { @@ -57,62 +59,105 @@ public class FlyPathFinder extends PathFinder /** * Internal implementation of creating a path from an entity to a point */ - private FlyPathEntity createEntityPathTo(Entity p_75857_1_, double p_75857_2_, double p_75857_4_, double p_75857_6_, float p_75857_8_) +// private FlyPathEntity createEntityPathTo(Entity p_75857_1_, double p_75857_2_, double p_75857_4_, double p_75857_6_, float p_75857_8_) +// { +// this.path.clearPath(); +// this.pointMap.clearMap(); +// boolean flag = this.isPathingInWater; +// int i = MathHelper.floor_double(p_75857_1_.boundingBox.minY + 0.5D); +// +// if (this.canEntityDrown && p_75857_1_.isInWater()) +// { +// i = (int)p_75857_1_.boundingBox.minY; +// +// for (Block block = this.worldMap.getBlock(MathHelper.floor_double(p_75857_1_.posX), i, MathHelper.floor_double(p_75857_1_.posZ)); block == Blocks.flowing_water || block == Blocks.water; block = this.worldMap.getBlock(MathHelper.floor_double(p_75857_1_.posX), i, MathHelper.floor_double(p_75857_1_.posZ))) +// { +// ++i; +// } +// +// flag = this.isPathingInWater; +// this.isPathingInWater = false; +// } +// +// FlyPathPoint pathpoint2 = this.openPoint(MathHelper.floor_double(p_75857_1_.boundingBox.minX), i, MathHelper.floor_double(p_75857_1_.boundingBox.minZ)); +// FlyPathPoint pathpoint = this.openPoint(MathHelper.floor_double(p_75857_2_ - (double)(p_75857_1_.width / 2.0F)), MathHelper.floor_double(p_75857_4_), MathHelper.floor_double(p_75857_6_ - (double)(p_75857_1_.width / 2.0F))); +// FlyPathPoint pathpoint1 = new FlyPathPoint(MathHelper.floor_float(p_75857_1_.width + 1.0F), MathHelper.floor_float(p_75857_1_.height + 1.0F), MathHelper.floor_float(p_75857_1_.width + 1.0F)); +// FlyPathEntity pathentity = this.addToPath(p_75857_1_, pathpoint2, pathpoint, pathpoint1, p_75857_8_); +// this.isPathingInWater = flag; +// return pathentity; +// } + + private FlyPathEntity createEntityPathTo(Entity entityIn, double x, double y, double z, float distance) { this.path.clearPath(); this.pointMap.clearMap(); - boolean flag = this.isPathingInWater; - int i = MathHelper.floor_double(p_75857_1_.boundingBox.minY + 0.5D); - - if (this.canEntityDrown && p_75857_1_.isInWater()) - { - i = (int)p_75857_1_.boundingBox.minY; - - for (Block block = this.worldMap.getBlock(MathHelper.floor_double(p_75857_1_.posX), i, MathHelper.floor_double(p_75857_1_.posZ)); block == Blocks.flowing_water || block == Blocks.water; block = this.worldMap.getBlock(MathHelper.floor_double(p_75857_1_.posX), i, MathHelper.floor_double(p_75857_1_.posZ))) - { - ++i; - } - - flag = this.isPathingInWater; - this.isPathingInWater = false; - } - - FlyPathPoint pathpoint2 = this.openPoint(MathHelper.floor_double(p_75857_1_.boundingBox.minX), i, MathHelper.floor_double(p_75857_1_.boundingBox.minZ)); - FlyPathPoint pathpoint = this.openPoint(MathHelper.floor_double(p_75857_2_ - (double)(p_75857_1_.width / 2.0F)), MathHelper.floor_double(p_75857_4_), MathHelper.floor_double(p_75857_6_ - (double)(p_75857_1_.width / 2.0F))); - FlyPathPoint pathpoint1 = new FlyPathPoint(MathHelper.floor_float(p_75857_1_.width + 1.0F), MathHelper.floor_float(p_75857_1_.height + 1.0F), MathHelper.floor_float(p_75857_1_.width + 1.0F)); - FlyPathEntity pathentity = this.addToPath(p_75857_1_, pathpoint2, pathpoint, pathpoint1, p_75857_8_); - this.isPathingInWater = flag; + FlyPathPoint pathpoint = this.getPathPointTo(entityIn); + FlyPathPoint pathpoint1 = this.getPathPointToCoords(entityIn, x, y, z); + FlyPathEntity pathentity = addToPath(entityIn, pathpoint, pathpoint1, distance); return pathentity; } + public FlyPathPoint getPathPointTo(Entity entity) + { + int i; + + if (((EntityNPCInterface) entity).ai.canSwim && entity.isInWater()) + { + i = (int)entity.boundingBox.minY; + BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor_double(entity.posX), i, MathHelper.floor_double(entity.posZ)); + + for (Block block = this.worldMap.getBlock(blockpos$mutableblockpos.getX(), blockpos$mutableblockpos.getY(), blockpos$mutableblockpos.getZ()); + block == Blocks.flowing_water || block == Blocks.water; + block = this.worldMap.getBlock(blockpos$mutableblockpos.getX(), blockpos$mutableblockpos.getY(), blockpos$mutableblockpos.getZ())) + { + ++i; + blockpos$mutableblockpos.setPos(MathHelper.floor_double(entity.posX), i, MathHelper.floor_double(entity.posZ)); + } + } + else + { + i = MathHelper.floor_double(entity.boundingBox.minY + 0.5D); + } + + BlockPos blockpos1 = new BlockPos(entity); + + return this.openPoint(blockpos1.getX(), i, blockpos1.getZ()); + } + + public FlyPathPoint getPathPointToCoords(Entity entityIn, double x, double y, double z) + { + return openPoint(MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); + } + + /** * Adds a path from start to end and returns the whole path (args: unused, start, end, unused, maxDistance) */ - private FlyPathEntity addToPath(Entity p_75861_1_, FlyPathPoint p_75861_2_, FlyPathPoint p_75861_3_, FlyPathPoint p_75861_4_, float p_75861_5_) + private FlyPathEntity addToPath(Entity entityIn, FlyPathPoint pathpointStart, FlyPathPoint pathpointEnd, float maxDistance) { - p_75861_2_.totalPathDistance = 0.0F; - p_75861_2_.distanceToNext = p_75861_2_.distanceToSquared(p_75861_3_); - p_75861_2_.distanceToTarget = p_75861_2_.distanceToNext; + pathpointStart.totalPathDistance = 0.0F; + pathpointStart.distanceToNext = pathpointStart.distanceToSquared(pathpointEnd); + pathpointStart.distanceToTarget = pathpointStart.distanceToNext; this.path.clearPath(); - this.path.addPoint(p_75861_2_); - FlyPathPoint pathpoint3 = p_75861_2_; + this.path.addPoint(pathpointStart); + FlyPathPoint pathpoint3 = pathpointStart; while (!this.path.isPathEmpty()) { FlyPathPoint pathpoint4 = this.path.dequeue(); - if (pathpoint4.equals(p_75861_3_)) + if (pathpoint4.equals(pathpointEnd)) { - return this.createEntityPath(p_75861_2_, p_75861_3_); + return this.createEntityPath(pathpointStart, pathpointEnd); } - if (pathpoint4.distanceToSquared(p_75861_3_) < pathpoint3.distanceToSquared(p_75861_3_)) + if (pathpoint4.distanceToSquared(pathpointEnd) < pathpoint3.distanceToSquared(pathpointEnd)) { pathpoint3 = pathpoint4; } pathpoint4.isFirst = true; - int i = this.findPathOptions(p_75861_1_, pathpoint4, p_75861_4_, p_75861_3_, p_75861_5_); + int i = this.findPathOptions(this.pathOptions, entityIn, pathpoint4, pathpointEnd, maxDistance); for (int j = 0; j < i; ++j) { @@ -123,7 +168,7 @@ public class FlyPathFinder extends PathFinder { pathpoint5.previous = pathpoint4; pathpoint5.totalPathDistance = f1; - pathpoint5.distanceToNext = pathpoint5.distanceToSquared(p_75861_3_); + pathpoint5.distanceToNext = pathpoint5.distanceToSquared(pathpointEnd); if (pathpoint5.isAssigned()) { @@ -138,13 +183,13 @@ public class FlyPathFinder extends PathFinder } } - if (pathpoint3 == p_75861_2_) + if (pathpoint3 == pathpointStart) { return null; } else { - return this.createEntityPath(p_75861_2_, pathpoint3); + return this.createEntityPath(pathpointStart, pathpoint3); } } @@ -152,77 +197,177 @@ public class FlyPathFinder extends PathFinder * populates pathOptions with available points and returns the number of options found (args: unused1, currentPoint, * unused2, targetPoint, maxDistance) */ - private int findPathOptions(Entity p_75860_1_, FlyPathPoint p_75860_2_, FlyPathPoint p_75860_3_, FlyPathPoint p_75860_4_, float p_75860_5_) + public int findPathOptions(FlyPathPoint[] pathOptions, Entity entityIn, FlyPathPoint currentPoint, FlyPathPoint targetPoint, float maxDistance) { int i = 0; - byte b0 = 0; + FlyPathPoint pathpoint = this.openPoint(currentPoint.xCoord, currentPoint.yCoord, currentPoint.zCoord + 1); + FlyPathPoint pathpoint1 = this.openPoint(currentPoint.xCoord - 1, currentPoint.yCoord, currentPoint.zCoord); + FlyPathPoint pathpoint2 = this.openPoint(currentPoint.xCoord + 1, currentPoint.yCoord, currentPoint.zCoord); + FlyPathPoint pathpoint3 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord, currentPoint.zCoord - 1); + FlyPathPoint pathpoint4 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord + 1, currentPoint.zCoord); + FlyPathPoint pathpoint5 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord - 1, currentPoint.zCoord); - if (this.getVerticalOffset(p_75860_1_, p_75860_2_.xCoord, p_75860_2_.yCoord + 1, p_75860_2_.zCoord, p_75860_3_) == 1) + if (pathpoint != null && !pathpoint.isFirst && pathpoint.distanceTo(targetPoint) < maxDistance) { - b0 = 1; + pathOptions[i++] = pathpoint; } - for(int y = -1; y <= 1; y ++) { - FlyPathPoint pathpoint3 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord, p_75860_2_.yCoord + y, p_75860_2_.zCoord + 1, p_75860_3_, b0); //A - FlyPathPoint pathpoint4 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord - 1, p_75860_2_.yCoord + y, p_75860_2_.zCoord, p_75860_3_, b0); //D - FlyPathPoint pathpoint5 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord + 1, p_75860_2_.yCoord + y, p_75860_2_.zCoord, p_75860_3_, b0); //B - FlyPathPoint pathpoint6 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord, p_75860_2_.yCoord + y, p_75860_2_.zCoord - 1, p_75860_3_, b0); //C + if (pathpoint1 != null && !pathpoint1.isFirst && pathpoint1.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint1; + } - FlyPathPoint pathpoint7 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord, p_75860_2_.yCoord + y, p_75860_2_.zCoord, p_75860_3_, b0); + if (pathpoint2 != null && !pathpoint2.isFirst && pathpoint2.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint2; + } - FlyPathPoint pathpoint8 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord + 1, p_75860_2_.yCoord + y, p_75860_2_.zCoord + 1, p_75860_3_, b0); //2 - FlyPathPoint pathpoint9 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord - 1, p_75860_2_.yCoord + y, p_75860_2_.zCoord - 1, p_75860_3_, b0); //4 - FlyPathPoint pathpoint10 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord + 1, p_75860_2_.yCoord + y, p_75860_2_.zCoord - 1, p_75860_3_, b0); //3 - FlyPathPoint pathpoint11 = this.getSafePoint(p_75860_1_, p_75860_2_.xCoord - 1, p_75860_2_.yCoord + y, p_75860_2_.zCoord + 1, p_75860_3_, b0); //1 + if (pathpoint3 != null && !pathpoint3.isFirst && pathpoint3.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint3; + } - if (pathpoint3 != null && !pathpoint3.isFirst && pathpoint3.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint3; + if (pathpoint4 != null && !pathpoint4.isFirst && pathpoint4.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint4; + } + + if (pathpoint5 != null && !pathpoint5.isFirst && pathpoint5.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint5; + } + + boolean flag = pathpoint3 == null; + boolean flag1 = pathpoint == null; + boolean flag2 = pathpoint2 == null; + boolean flag3 = pathpoint1 == null; + boolean flag4 = pathpoint4 == null; + boolean flag5 = pathpoint5 == null; + + if (flag && flag3) + { + FlyPathPoint pathpoint6 = this.openPoint(currentPoint.xCoord - 1, currentPoint.yCoord, currentPoint.zCoord - 1); + + if (pathpoint6 != null && !pathpoint6.isFirst && pathpoint6.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint6; } + } - if (pathpoint4 != null && !pathpoint4.isFirst && pathpoint4.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint4; + if (flag && flag2) + { + FlyPathPoint pathpoint7 = this.openPoint(currentPoint.xCoord + 1, currentPoint.yCoord, currentPoint.zCoord - 1); + + if (pathpoint7 != null && !pathpoint7.isFirst && pathpoint7.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint7; } + } - if (pathpoint5 != null && !pathpoint5.isFirst && pathpoint5.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint5; + if (flag1 && flag3) + { + FlyPathPoint pathpoint8 = this.openPoint(currentPoint.xCoord - 1, currentPoint.yCoord, currentPoint.zCoord + 1); + + if (pathpoint8 != null && !pathpoint8.isFirst && pathpoint8.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint8; } + } - if (pathpoint6 != null && !pathpoint6.isFirst && pathpoint6.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint6; + if (flag1 && flag2) + { + FlyPathPoint pathpoint9 = this.openPoint(currentPoint.xCoord + 1, currentPoint.yCoord, currentPoint.zCoord + 1); + + if (pathpoint9 != null && !pathpoint9.isFirst && pathpoint9.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint9; } + } - if (pathpoint7 != null && !pathpoint7.isFirst && pathpoint7.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint7; + if (flag && flag4) + { + FlyPathPoint pathpoint10 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord + 1, currentPoint.zCoord - 1); + + if (pathpoint10 != null && !pathpoint10.isFirst && pathpoint10.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint10; } + } - if (pathpoint3 != null && !pathpoint3.isFirst && pathpoint3.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint5 != null && !pathpoint5.isFirst && pathpoint5.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint8 != null && !pathpoint8.isFirst && pathpoint8.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint8; + if (flag1 && flag4) + { + FlyPathPoint pathpoint11 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord + 1, currentPoint.zCoord + 1); + + if (pathpoint11 != null && !pathpoint11.isFirst && pathpoint11.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint11; } + } - if (pathpoint6 != null && !pathpoint6.isFirst && pathpoint6.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint4 != null && !pathpoint4.isFirst && pathpoint4.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint9 != null && !pathpoint9.isFirst && pathpoint9.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint9; + if (flag2 && flag4) + { + FlyPathPoint pathpoint12 = this.openPoint(currentPoint.xCoord + 1, currentPoint.yCoord + 1, currentPoint.zCoord); + + if (pathpoint12 != null && !pathpoint12.isFirst && pathpoint12.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint12; } + } - if (pathpoint6 != null && !pathpoint6.isFirst && pathpoint6.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint5 != null && !pathpoint5.isFirst && pathpoint5.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint10 != null && !pathpoint10.isFirst && pathpoint10.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint10; + if (flag3 && flag4) + { + FlyPathPoint pathpoint13 = this.openPoint(currentPoint.xCoord - 1, currentPoint.yCoord + 1, currentPoint.zCoord); + + if (pathpoint13 != null && !pathpoint13.isFirst && pathpoint13.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint13; } + } - if (pathpoint3 != null && !pathpoint3.isFirst && pathpoint3.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint4 != null && !pathpoint4.isFirst && pathpoint4.distanceTo(p_75860_4_) < p_75860_5_ && - pathpoint11 != null && !pathpoint11.isFirst && pathpoint11.distanceTo(p_75860_4_) < p_75860_5_) { - this.pathOptions[i++] = pathpoint11; + if (flag && flag5) + { + FlyPathPoint pathpoint14 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord - 1, currentPoint.zCoord - 1); + + if (pathpoint14 != null && !pathpoint14.isFirst && pathpoint14.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint14; + } + } + + if (flag1 && flag5) + { + FlyPathPoint pathpoint15 = this.openPoint(currentPoint.xCoord, currentPoint.yCoord - 1, currentPoint.zCoord + 1); + + if (pathpoint15 != null && !pathpoint15.isFirst && pathpoint15.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint15; + } + } + + if (flag2 && flag5) + { + FlyPathPoint pathpoint16 = this.openPoint(currentPoint.xCoord + 1, currentPoint.yCoord - 1, currentPoint.zCoord); + + if (pathpoint16 != null && !pathpoint16.isFirst && pathpoint16.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint16; + } + } + + if (flag3 && flag5) + { + FlyPathPoint pathpoint17 = this.openPoint(currentPoint.xCoord - 1, currentPoint.yCoord - 1, currentPoint.zCoord); + + if (pathpoint17 != null && !pathpoint17.isFirst && pathpoint17.distanceTo(targetPoint) < maxDistance) + { + pathOptions[i++] = pathpoint17; } } return i; } + /** * Returns a point that the entity can safely move to */ From d44c33d9fbb9e85cc28dc01c1646e07f585f0d1a Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Sat, 5 Nov 2022 00:53:41 -0400 Subject: [PATCH 2/6] Update FlyPathFinder.java --- src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java index bc80d92a8..a9041c619 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java @@ -5,12 +5,15 @@ import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.pathfinding.PathFinder; +import net.minecraft.pathfinding.PathPoint; import net.minecraft.util.IntHashMap; import net.minecraft.util.MathHelper; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import noppes.npcs.entity.EntityNPCInterface; +import javax.annotation.Nullable; + public class FlyPathFinder extends PathFinder { /** Used to find obstacles */ @@ -438,6 +441,7 @@ public class FlyPathFinder extends PathFinder /** * Returns a mapped point or creates and adds one */ + @Nullable private FlyPathPoint openPoint(int p_75854_1_, int p_75854_2_, int p_75854_3_) { int l = FlyPathPoint.makeHash(p_75854_1_, p_75854_2_, p_75854_3_); From ad8cd35083770623040a52986c879d649409012f Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Sat, 5 Nov 2022 03:35:55 -0400 Subject: [PATCH 3/6] Kam is a Legend --- .../net/minecraft/util/math/BlockPos.java | 3 +- .../net/minecraft/util/math/IntHashMap.java | 255 ++++++++++++++ .../npcs/ai/pathfinder/FlyPathFinder.java | 314 +++++++++++++++--- .../npcs/ai/pathfinder/FlyPathPoint.java | 2 + .../ai/pathfinder/PathNavigateFlying.java | 4 +- .../npcs/ai/pathfinder/PathNodeType.java | 34 ++ 6 files changed, 571 insertions(+), 41 deletions(-) create mode 100644 src/main/java/net/minecraft/util/math/IntHashMap.java create mode 100644 src/main/java/noppes/npcs/ai/pathfinder/PathNodeType.java diff --git a/src/main/java/net/minecraft/util/math/BlockPos.java b/src/main/java/net/minecraft/util/math/BlockPos.java index 04472fb26..f1904b4fe 100644 --- a/src/main/java/net/minecraft/util/math/BlockPos.java +++ b/src/main/java/net/minecraft/util/math/BlockPos.java @@ -19,6 +19,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.MathHelper; /** + * Pasted in from 1.9, with the Vec3d constructor removed */ @Immutable public class BlockPos extends Vec3i @@ -553,4 +554,4 @@ public class BlockPos extends Vec3i return (BlockPos.PooledMutableBlockPos)super.move(p_189538_1_, p_189538_2_); } } -} \ No newline at end of file +} diff --git a/src/main/java/net/minecraft/util/math/IntHashMap.java b/src/main/java/net/minecraft/util/math/IntHashMap.java new file mode 100644 index 000000000..797013de5 --- /dev/null +++ b/src/main/java/net/minecraft/util/math/IntHashMap.java @@ -0,0 +1,255 @@ +package net.minecraft.util.math; + +public class IntHashMap { + private transient IntHashMap.Entry[] slots = new IntHashMap.Entry[16]; + /** + * The number of items stored in this map + */ + private transient int count; + /** + * The grow threshold + */ + private int threshold = 12; + /** + * The scale factor used to determine when to grow the table + */ + private final float growFactor = 0.75F; + + /** + * Makes the passed in integer suitable for hashing by a number of shifts + */ + private static int computeHash(int integer) { + integer = integer ^ integer >>> 20 ^ integer >>> 12; + return integer ^ integer >>> 7 ^ integer >>> 4; + } + + /** + * Computes the index of the slot for the hash and slot count passed in. + */ + private static int getSlotIndex(int hash, int slotCount) { + return hash & slotCount - 1; + } + + /** + * Returns the object associated to a key + */ + public V lookup(int p_76041_1_) { + int i = computeHash(p_76041_1_); + + for (IntHashMap.Entry entry = this.slots[getSlotIndex(i, this.slots.length)]; entry != null; entry = entry.nextEntry) { + if (entry.hashEntry == p_76041_1_) { + return entry.valueEntry; + } + } + + return (V) null; + } + + /** + * Returns true if this hash table contains the specified item. + */ + public boolean containsItem(int p_76037_1_) { + return this.lookupEntry(p_76037_1_) != null; + } + + final IntHashMap.Entry lookupEntry(int p_76045_1_) { + int i = computeHash(p_76045_1_); + + for (IntHashMap.Entry entry = this.slots[getSlotIndex(i, this.slots.length)]; entry != null; entry = entry.nextEntry) { + if (entry.hashEntry == p_76045_1_) { + return entry; + } + } + + return null; + } + + /** + * Adds a key and associated value to this map + */ + public void addKey(int p_76038_1_, V p_76038_2_) { + int i = computeHash(p_76038_1_); + int j = getSlotIndex(i, this.slots.length); + + for (IntHashMap.Entry entry = this.slots[j]; entry != null; entry = entry.nextEntry) { + if (entry.hashEntry == p_76038_1_) { + entry.valueEntry = p_76038_2_; + return; + } + } + + this.insert(i, p_76038_1_, p_76038_2_, j); + } + + /** + * Increases the number of hash slots + */ + private void grow(int p_76047_1_) { + IntHashMap.Entry[] entry = this.slots; + int i = entry.length; + + if (i == 1073741824) { + this.threshold = Integer.MAX_VALUE; + } else { + IntHashMap.Entry[] entry1 = new IntHashMap.Entry[p_76047_1_]; + this.copyTo(entry1); + this.slots = entry1; + this.threshold = (int) ((float) p_76047_1_ * this.growFactor); + } + } + + /** + * Copies the hash slots to a new array + */ + private void copyTo(IntHashMap.Entry[] p_76048_1_) { + IntHashMap.Entry[] entry = this.slots; + int i = p_76048_1_.length; + + for (int j = 0; j < entry.length; ++j) { + IntHashMap.Entry entry1 = entry[j]; + + if (entry1 != null) { + entry[j] = null; + + while (true) { + IntHashMap.Entry entry2 = entry1.nextEntry; + int k = getSlotIndex(entry1.slotHash, i); + entry1.nextEntry = p_76048_1_[k]; + p_76048_1_[k] = entry1; + entry1 = entry2; + + if (entry2 == null) { + break; + } + } + } + } + } + + /** + * Removes the specified object from the map and returns it + */ + public V removeObject(int p_76049_1_) { + IntHashMap.Entry entry = this.removeEntry(p_76049_1_); + return (V) (entry == null ? null : entry.valueEntry); + } + + final IntHashMap.Entry removeEntry(int p_76036_1_) { + int i = computeHash(p_76036_1_); + int j = getSlotIndex(i, this.slots.length); + IntHashMap.Entry entry = this.slots[j]; + IntHashMap.Entry entry1; + IntHashMap.Entry entry2; + + for (entry1 = entry; entry1 != null; entry1 = entry2) { + entry2 = entry1.nextEntry; + + if (entry1.hashEntry == p_76036_1_) { + --this.count; + + if (entry == entry1) { + this.slots[j] = entry2; + } else { + entry.nextEntry = entry2; + } + + return entry1; + } + + entry = entry1; + } + + return entry1; + } + + /** + * Removes all entries from the map + */ + public void clearMap() { + IntHashMap.Entry[] entry = this.slots; + + for (int i = 0; i < entry.length; ++i) { + entry[i] = null; + } + + this.count = 0; + } + + /** + * Adds an object to a slot + */ + private void insert(int p_76040_1_, int p_76040_2_, V p_76040_3_, int p_76040_4_) { + IntHashMap.Entry entry = this.slots[p_76040_4_]; + this.slots[p_76040_4_] = new IntHashMap.Entry(p_76040_1_, p_76040_2_, p_76040_3_, entry); + + if (this.count++ >= this.threshold) { + this.grow(2 * this.slots.length); + } + } + + static class Entry { + /** + * The hash code of this entry + */ + final int hashEntry; + /** + * The object stored in this entry + */ + V valueEntry; + IntHashMap.Entry nextEntry; + /** + * The id of the hash slot computed from the hash + */ + final int slotHash; + + Entry(int p_i1552_1_, int p_i1552_2_, V p_i1552_3_, IntHashMap.Entry p_i1552_4_) { + this.valueEntry = p_i1552_3_; + this.nextEntry = p_i1552_4_; + this.hashEntry = p_i1552_2_; + this.slotHash = p_i1552_1_; + } + + /** + * Returns the hash code for this entry + */ + public final int getHash() { + return this.hashEntry; + } + + /** + * Returns the object stored in this entry + */ + public final V getValue() { + return this.valueEntry; + } + + public final boolean equals(Object p_equals_1_) { + if (!(p_equals_1_ instanceof IntHashMap.Entry)) { + return false; + } else { + IntHashMap.Entry entry = (IntHashMap.Entry) p_equals_1_; + Object object = Integer.valueOf(this.getHash()); + Object object1 = Integer.valueOf(entry.getHash()); + + if (object == object1 || object != null && object.equals(object1)) { + Object object2 = this.getValue(); + Object object3 = entry.getValue(); + + if (object2 == object3 || object2 != null && object2.equals(object3)) { + return true; + } + } + + return false; + } + } + + public final int hashCode() { + return IntHashMap.computeHash(this.hashEntry); + } + + public final String toString() { + return this.getHash() + "=" + this.getValue(); + } + } +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java index a9041c619..00f7385cd 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java @@ -1,18 +1,23 @@ package noppes.npcs.ai.pathfinder; -import net.minecraft.block.Block; +import com.google.common.collect.Maps; +import net.minecraft.block.*; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.init.Blocks; import net.minecraft.pathfinding.PathFinder; import net.minecraft.pathfinding.PathPoint; -import net.minecraft.util.IntHashMap; import net.minecraft.util.MathHelper; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.IntHashMap; import net.minecraft.world.IBlockAccess; import noppes.npcs.entity.EntityNPCInterface; import javax.annotation.Nullable; +import java.util.EnumSet; +import java.util.Map; public class FlyPathFinder extends PathFinder { @@ -21,7 +26,7 @@ public class FlyPathFinder extends PathFinder /** The path being generated */ private FlyPath path = new FlyPath(); /** The points in the path */ - private IntHashMap pointMap = new IntHashMap(); + protected final IntHashMap pointMap = new IntHashMap(); /** Selection of path points to add to the path */ private FlyPathPoint[] pathOptions = new FlyPathPoint[32]; /** should the PathFinder go through wodden door blocks */ @@ -32,10 +37,13 @@ public class FlyPathFinder extends PathFinder /** tells the FathFinder to not stop pathing underwater */ private boolean canEntityDrown; private static final String __OBFID = "CL_00000576"; + private Entity theEntity; + private final Map mapPathPriority = Maps.newEnumMap(PathNodeType.class); - public FlyPathFinder(IBlockAccess p_i2137_1_, boolean p_i2137_2_, boolean p_i2137_3_, boolean p_i2137_4_, boolean p_i2137_5_) + public FlyPathFinder(IBlockAccess p_i2137_1_, boolean p_i2137_2_, boolean p_i2137_3_, boolean p_i2137_4_, boolean p_i2137_5_, Entity p_72865_1_) { super(p_i2137_1_,p_i2137_2_,p_i2137_3_,p_i2137_4_,p_i2137_5_); + this.theEntity = p_72865_1_; this.worldMap = p_i2137_1_; this.isWoddenDoorAllowed = p_i2137_2_; this.isMovementBlockAllowed = p_i2137_3_; @@ -62,33 +70,6 @@ public class FlyPathFinder extends PathFinder /** * Internal implementation of creating a path from an entity to a point */ -// private FlyPathEntity createEntityPathTo(Entity p_75857_1_, double p_75857_2_, double p_75857_4_, double p_75857_6_, float p_75857_8_) -// { -// this.path.clearPath(); -// this.pointMap.clearMap(); -// boolean flag = this.isPathingInWater; -// int i = MathHelper.floor_double(p_75857_1_.boundingBox.minY + 0.5D); -// -// if (this.canEntityDrown && p_75857_1_.isInWater()) -// { -// i = (int)p_75857_1_.boundingBox.minY; -// -// for (Block block = this.worldMap.getBlock(MathHelper.floor_double(p_75857_1_.posX), i, MathHelper.floor_double(p_75857_1_.posZ)); block == Blocks.flowing_water || block == Blocks.water; block = this.worldMap.getBlock(MathHelper.floor_double(p_75857_1_.posX), i, MathHelper.floor_double(p_75857_1_.posZ))) -// { -// ++i; -// } -// -// flag = this.isPathingInWater; -// this.isPathingInWater = false; -// } -// -// FlyPathPoint pathpoint2 = this.openPoint(MathHelper.floor_double(p_75857_1_.boundingBox.minX), i, MathHelper.floor_double(p_75857_1_.boundingBox.minZ)); -// FlyPathPoint pathpoint = this.openPoint(MathHelper.floor_double(p_75857_2_ - (double)(p_75857_1_.width / 2.0F)), MathHelper.floor_double(p_75857_4_), MathHelper.floor_double(p_75857_6_ - (double)(p_75857_1_.width / 2.0F))); -// FlyPathPoint pathpoint1 = new FlyPathPoint(MathHelper.floor_float(p_75857_1_.width + 1.0F), MathHelper.floor_float(p_75857_1_.height + 1.0F), MathHelper.floor_float(p_75857_1_.width + 1.0F)); -// FlyPathEntity pathentity = this.addToPath(p_75857_1_, pathpoint2, pathpoint, pathpoint1, p_75857_8_); -// this.isPathingInWater = flag; -// return pathentity; -// } private FlyPathEntity createEntityPathTo(Entity entityIn, double x, double y, double z, float distance) { @@ -441,16 +422,53 @@ public class FlyPathFinder extends PathFinder /** * Returns a mapped point or creates and adds one */ +// @Nullable +// private FlyPathPoint openPoint(int p_75854_1_, int p_75854_2_, int p_75854_3_) +// { +// int l = FlyPathPoint.makeHash(p_75854_1_, p_75854_2_, p_75854_3_); +// FlyPathPoint pathpoint = (FlyPathPoint)this.pointMap.lookup(l); +// +// if (pathpoint == null) +// { +// pathpoint = new FlyPathPoint(p_75854_1_, p_75854_2_, p_75854_3_); +// this.pointMap.addKey(l, pathpoint); +// } +// +// return pathpoint; +// } + @Nullable - private FlyPathPoint openPoint(int p_75854_1_, int p_75854_2_, int p_75854_3_) + protected FlyPathPoint openPoint(int x, int y, int z) { - int l = FlyPathPoint.makeHash(p_75854_1_, p_75854_2_, p_75854_3_); - FlyPathPoint pathpoint = (FlyPathPoint)this.pointMap.lookup(l); + FlyPathPoint pathpoint = null; + BlockPos blockPos = new BlockPos(x, y, z); + PathNodeType pathnodetype = this.getPathNodeType((EntityLiving) this.theEntity, blockPos); + float f = getPathPriority(pathnodetype); + + if (f >= 0.0F) + { + pathpoint = openPoint(x, y, z, x); + pathpoint.nodeType = pathnodetype; + pathpoint.costMalus = Math.max(pathpoint.costMalus, f); + + if (pathnodetype == PathNodeType.WALKABLE) + { + ++pathpoint.costMalus; + } + } + + return pathnodetype != PathNodeType.OPEN && pathnodetype != PathNodeType.WALKABLE ? pathpoint : pathpoint; + } + + protected FlyPathPoint openPoint(int x, int y, int z, int b) + { + int i = FlyPathPoint.makeHash(x, y, z); + FlyPathPoint pathpoint = this.pointMap.lookup(i); if (pathpoint == null) { - pathpoint = new FlyPathPoint(p_75854_1_, p_75854_2_, p_75854_3_); - this.pointMap.addKey(l, pathpoint); + pathpoint = new FlyPathPoint(x, y, z); + this.pointMap.addKey(i, pathpoint); } return pathpoint; @@ -484,8 +502,8 @@ public class FlyPathFinder extends PathFinder for (int currentY = blockY; currentY <= Math.ceil(blockY + entity.height); ++currentY) { Block b = entity.worldObj.getBlock(l, currentY, j1); if (b != Blocks.air) { - heightClear = false; - break; + heightClear = false; + break; } } if (heightClear) { @@ -583,4 +601,224 @@ public class FlyPathFinder extends PathFinder return new FlyPathEntity(apathpoint); } + + + + + public PathNodeType getPathNodeType(IBlockAccess blockaccessIn, int x, int y, int z, EntityLiving entitylivingIn, int xSize, int ySize, int zSize, boolean canBreakDoorsIn, boolean canEnterDoorsIn) + { + EnumSet enumset = EnumSet.noneOf(PathNodeType.class); + PathNodeType pathnodetype = PathNodeType.BLOCKED; + double d0 = (double)entitylivingIn.width / 2.0D; + BlockPos blockpos = new BlockPos(entitylivingIn); + pathnodetype = this.getPathNodeType(blockaccessIn, x, y, z, xSize, ySize, zSize, canBreakDoorsIn, canEnterDoorsIn, enumset, pathnodetype, blockpos); + + if (enumset.contains(PathNodeType.FENCE)) + { + return PathNodeType.FENCE; + } + else + { + PathNodeType pathnodetype1 = PathNodeType.BLOCKED; + + for (PathNodeType pathnodetype2 : enumset) + { + if (getPathPriority(pathnodetype2) < 0.0F) + { + return pathnodetype2; + } + + if (getPathPriority(pathnodetype2) >= getPathPriority(pathnodetype1)) + { + pathnodetype1 = pathnodetype2; + } + } + + if (pathnodetype == PathNodeType.OPEN && getPathPriority(pathnodetype1) == 0.0F) + { + return PathNodeType.OPEN; + } + else + { + return pathnodetype1; + } + } + } + + public PathNodeType getPathNodeType(IBlockAccess p_193577_1_, int x, int y, int z, int xSize, int ySize, int zSize, boolean canOpenDoorsIn, boolean canEnterDoorsIn, EnumSet p_193577_10_, PathNodeType p_193577_11_, BlockPos p_193577_12_) + { + for (int i = 0; i < xSize; ++i) + { + for (int j = 0; j < ySize; ++j) + { + for (int k = 0; k < zSize; ++k) + { + int l = i + x; + int i1 = j + y; + int j1 = k + z; + PathNodeType pathnodetype = this.getPathNodeType(p_193577_1_, l, i1, j1); + + if (pathnodetype == PathNodeType.DOOR_WOOD_CLOSED && canOpenDoorsIn && canEnterDoorsIn) + { + pathnodetype = PathNodeType.WALKABLE; + } + + if (pathnodetype == PathNodeType.DOOR_OPEN && !canEnterDoorsIn) + { + pathnodetype = PathNodeType.BLOCKED; + } + + if (pathnodetype == PathNodeType.RAIL && !(p_193577_1_.getBlock(p_193577_12_.getX(), p_193577_12_.getY(), p_193577_12_.getZ()) instanceof BlockRailBase) && !(p_193577_1_.getBlock(p_193577_12_.down().getX(), p_193577_12_.down().getY(), p_193577_12_.down().getZ()) instanceof BlockRailBase)) + { + pathnodetype = PathNodeType.FENCE; + } + + if (i == 0 && j == 0 && k == 0) + { + p_193577_11_ = pathnodetype; + } + + p_193577_10_.add(pathnodetype); + } + } + } + + return p_193577_11_; + } + + public PathNodeType getPathNodeType(IBlockAccess blockaccessIn, int x, int y, int z) + { + PathNodeType pathnodetype = this.getPathNodeTypeRaw(blockaccessIn, x, y, z); + + if (pathnodetype == PathNodeType.OPEN && y >= 1) + { + PathNodeType pathnodetype1 = this.getPathNodeTypeRaw(blockaccessIn, x, y - 1, z); + pathnodetype = pathnodetype1 != PathNodeType.WALKABLE && pathnodetype1 != PathNodeType.OPEN && pathnodetype1 != PathNodeType.WATER && pathnodetype1 != PathNodeType.LAVA ? PathNodeType.WALKABLE : PathNodeType.OPEN; + + if (pathnodetype1 == PathNodeType.DAMAGE_FIRE) + { + pathnodetype = PathNodeType.DAMAGE_FIRE; + } + + if (pathnodetype1 == PathNodeType.DAMAGE_CACTUS) + { + pathnodetype = PathNodeType.DAMAGE_CACTUS; + } + + if (pathnodetype1 == PathNodeType.DAMAGE_OTHER) pathnodetype = PathNodeType.DAMAGE_OTHER; + } + + pathnodetype = this.checkNeighborBlocks(blockaccessIn, x, y, z, pathnodetype); + return pathnodetype; + } + + public PathNodeType checkNeighborBlocks(IBlockAccess worldmap, int x, int y, int z, PathNodeType p_193578_5_) + { + BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain(); + + if (p_193578_5_ == PathNodeType.WALKABLE) + { + for (int i = -1; i <= 1; ++i) + { + for (int j = -1; j <= 1; ++j) + { + if (i != 0 || j != 0) + { + blockpos$pooledmutableblockpos.setPos(i + x, y, j + z); + Block block = worldmap.getBlock(blockpos$pooledmutableblockpos.getX(), blockpos$pooledmutableblockpos.getY(), blockpos$pooledmutableblockpos.getZ()); + if (block == Blocks.cactus) + { + p_193578_5_ = PathNodeType.DANGER_CACTUS; + } + else if (block == Blocks.fire) + { + p_193578_5_ = PathNodeType.DANGER_FIRE; + } + } + } + } + } + + blockpos$pooledmutableblockpos.release(); + return p_193578_5_; + } + + protected PathNodeType getPathNodeTypeRaw(IBlockAccess worldmap, int p_189553_2_, int p_189553_3_, int p_189553_4_) + { + BlockPos blockpos = new BlockPos(p_189553_2_, p_189553_3_, p_189553_4_); + Block block = worldmap.getBlock(blockpos.getX(), blockpos.getY(), blockpos.getZ()); + Material material = block.getMaterial(); + + if (material == Material.air) + { + return PathNodeType.OPEN; + } + else if (block != Blocks.trapdoor && block != Blocks.waterlily) + { + if (block == Blocks.fire) + { + return PathNodeType.DAMAGE_FIRE; + } + else if (block == Blocks.cactus) + { + return PathNodeType.DAMAGE_CACTUS; + } + else if (block instanceof BlockDoor && material == Material.wood) + { + return PathNodeType.DOOR_WOOD_CLOSED; + } + else if (block instanceof BlockDoor && material == Material.iron) + { + return PathNodeType.DOOR_IRON_CLOSED; + } + else if (block instanceof BlockRailBase) + { + return PathNodeType.RAIL; + } + else if (!(block instanceof BlockFence) && !(block instanceof BlockWall) && (!(block instanceof BlockFenceGate))) + { + if (material == Material.water) + { + return PathNodeType.WATER; + } + else if (material == Material.lava) + { + return PathNodeType.LAVA; + } + else + { + return block.getBlocksMovement(worldmap, blockpos.getX(), blockpos.getY(), blockpos.getZ()) ? PathNodeType.OPEN : PathNodeType.BLOCKED; + } + } + else + { + return PathNodeType.FENCE; + } + } + else + { + return PathNodeType.TRAPDOOR; + } + } + + private PathNodeType getPathNodeType(EntityLiving p_192559_1_, BlockPos p_192559_2_) + { + return this.getPathNodeType(p_192559_1_, p_192559_2_.getX(), p_192559_2_.getY(), p_192559_2_.getZ()); + } + + private PathNodeType getPathNodeType(EntityLiving p_192558_1_, int p_192558_2_, int p_192558_3_, int p_192558_4_) + { + int entitySizeX = MathHelper.floor_double(p_192558_1_.width + 1.0F); + int entitySizeY = MathHelper.floor_double(p_192558_1_.height + 1.0F); + int entitySizeZ = MathHelper.floor_double(p_192558_1_.width + 1.0F); + return this.getPathNodeType(this.worldMap, p_192558_2_, p_192558_3_, p_192558_4_, p_192558_1_, entitySizeX, entitySizeY, entitySizeZ, false, false); + } + + public float getPathPriority(PathNodeType nodeType) + { + Float f = this.mapPathPriority.get(nodeType); + return f == null ? nodeType.getPriority() : f.floatValue(); + } + + } diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java index 87af78ae7..8ef5b7cef 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java @@ -25,6 +25,8 @@ public class FlyPathPoint extends PathPoint public FlyPathPoint previous; /** Indicates this is the origin */ public boolean isFirst; + public float costMalus; + public PathNodeType nodeType = PathNodeType.BLOCKED; private static final String __OBFID = "CL_00000574"; public FlyPathPoint(int p_i2135_1_, int p_i2135_2_, int p_i2135_3_) diff --git a/src/main/java/noppes/npcs/ai/pathfinder/PathNavigateFlying.java b/src/main/java/noppes/npcs/ai/pathfinder/PathNavigateFlying.java index 944d87d55..9692c60a3 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/PathNavigateFlying.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/PathNavigateFlying.java @@ -488,7 +488,7 @@ public class PathNavigateFlying extends PathNavigate { int i2 = j + l; int j2 = k + l; ChunkCache chunkcache = new ChunkCache(this.theEntity.worldObj, i1, j1, k1, l1, i2, j2, 0); - FlyPathEntity pathentity = (new FlyPathFinder(chunkcache, p_72865_4_, p_72865_5_, p_72865_6_, p_72865_7_)).createEntityPathTo(p_72865_1_, p_72865_2_, p_72865_3_); + FlyPathEntity pathentity = (new FlyPathFinder(chunkcache, p_72865_4_, p_72865_5_, p_72865_6_, p_72865_7_, p_72865_1_)).createEntityPathTo(p_72865_1_, p_72865_2_, p_72865_3_); this.theEntity.worldObj.theProfiler.endSection(); return pathentity; } @@ -507,7 +507,7 @@ public class PathNavigateFlying extends PathNavigate { int l2 = i1 + k1; int i3 = j1 + k1; ChunkCache chunkcache = new ChunkCache(this.theEntity.worldObj, l1, i2, j2, k2, l2, i3, 0); - FlyPathEntity pathentity = (new FlyPathFinder(chunkcache, p_72844_6_, p_72844_7_, p_72844_8_, p_72844_9_)).createEntityPathTo(p_72844_1_, p_72844_2_, p_72844_3_, p_72844_4_, p_72844_5_); + FlyPathEntity pathentity = (new FlyPathFinder(chunkcache, p_72844_6_, p_72844_7_, p_72844_8_, p_72844_9_, p_72844_1_)).createEntityPathTo(p_72844_1_, p_72844_2_, p_72844_3_, p_72844_4_, p_72844_5_); this.theEntity.worldObj.theProfiler.endSection(); return pathentity; } diff --git a/src/main/java/noppes/npcs/ai/pathfinder/PathNodeType.java b/src/main/java/noppes/npcs/ai/pathfinder/PathNodeType.java new file mode 100644 index 000000000..f49fe3c59 --- /dev/null +++ b/src/main/java/noppes/npcs/ai/pathfinder/PathNodeType.java @@ -0,0 +1,34 @@ +package noppes.npcs.ai.pathfinder; + +public enum PathNodeType +{ + BLOCKED(-1.0F), + OPEN(0.0F), + WALKABLE(0.0F), + TRAPDOOR(0.0F), + FENCE(-1.0F), + LAVA(-1.0F), + WATER(8.0F), + RAIL(0.0F), + DANGER_FIRE(8.0F), + DAMAGE_FIRE(16.0F), + DANGER_CACTUS(8.0F), + DAMAGE_CACTUS(-1.0F), + DANGER_OTHER(8.0F), + DAMAGE_OTHER(-1.0F), + DOOR_OPEN(0.0F), + DOOR_WOOD_CLOSED(-1.0F), + DOOR_IRON_CLOSED(-1.0F); + + private final float priority; + + private PathNodeType(float priorityIn) + { + this.priority = priorityIn; + } + + public float getPriority() + { + return this.priority; + } +} \ No newline at end of file From 344e2f01444568cfd5390c35881336a749d71041 Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Sat, 5 Nov 2022 03:56:01 -0400 Subject: [PATCH 4/6] Minor Fix --- .../npcs/ai/pathfinder/FlyPathFinder.java | 188 ------------------ .../npcs/ai/pathfinder/FlyPathPoint.java | 4 +- 2 files changed, 2 insertions(+), 190 deletions(-) diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java index 00f7385cd..eec63740b 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java @@ -351,92 +351,6 @@ public class FlyPathFinder extends PathFinder return i; } - - /** - * Returns a point that the entity can safely move to - */ - private FlyPathPoint getSafePoint(Entity entity, int blockX, int blockY, int blockZ, FlyPathPoint pathPoint, int verticalOffsetFlag) - { - FlyPathPoint pathpoint1 = null; - int verticalOffset = this.getVerticalOffset(entity, blockX, blockY, blockZ, pathPoint); - - if (verticalOffset == 2) - { - return this.openPoint(blockX, blockY, blockZ); - } - else - { - if (verticalOffset == 1) - { - pathpoint1 = this.openPoint(blockX, blockY, blockZ); - } - - if (pathpoint1 == null && verticalOffsetFlag > 0 && verticalOffset != -3 && verticalOffset != -4 && this.getVerticalOffset(entity, blockX, blockY + verticalOffsetFlag, blockZ, pathPoint) == 1) - { - pathpoint1 = this.openPoint(blockX, blockY + verticalOffsetFlag, blockZ); - blockY += verticalOffsetFlag; - } - - if (pathpoint1 != null) - { - int j1 = 0; - int k1 = 0; - - while (blockY > 0) - { - k1 = this.getVerticalOffset(entity, blockX, blockY - 1, blockZ, pathPoint); - - if (this.isPathingInWater && k1 == -1) - { - return null; - } - - if (k1 != 1) - { - break; - } - - if (j1++ >= entity.getMaxSafePointTries()) - { - return null; - } - - --blockY; - - if (blockY > 0) - { - pathpoint1 = this.openPoint(blockX, blockY, blockZ); - } - } - - if (k1 == -2) - { - return null; - } - } - - return pathpoint1; - } - } - - /** - * Returns a mapped point or creates and adds one - */ -// @Nullable -// private FlyPathPoint openPoint(int p_75854_1_, int p_75854_2_, int p_75854_3_) -// { -// int l = FlyPathPoint.makeHash(p_75854_1_, p_75854_2_, p_75854_3_); -// FlyPathPoint pathpoint = (FlyPathPoint)this.pointMap.lookup(l); -// -// if (pathpoint == null) -// { -// pathpoint = new FlyPathPoint(p_75854_1_, p_75854_2_, p_75854_3_); -// this.pointMap.addKey(l, pathpoint); -// } -// -// return pathpoint; -// } - @Nullable protected FlyPathPoint openPoint(int x, int y, int z) { @@ -474,108 +388,6 @@ public class FlyPathFinder extends PathFinder return pathpoint; } - /** - * Checks if an entity collides with blocks at a position. Returns 1 if clear, 0 for colliding with any solid block, - * -1 for water(if avoiding water) but otherwise clear, -2 for lava, -3 for fence, -4 for closed trapdoor, 2 if - * otherwise clear except for open trapdoor or water(if not avoiding) - */ - public int getVerticalOffset(Entity p_75855_1_, int p_75855_2_, int p_75855_3_, int p_75855_4_, FlyPathPoint p_75855_5_) - { - return canEntityStandAt(p_75855_1_, p_75855_2_, p_75855_3_, p_75855_4_, p_75855_5_, this.isPathingInWater, this.isMovementBlockAllowed, this.isWoddenDoorAllowed); - } - - public static int canEntityStandAt(Entity entity, int blockX, int blockY, int blockZ, FlyPathPoint pathPoint, boolean isPathingInWater, boolean isMovementBlockAllowed, boolean isWoddenDoorAllowed) - { - boolean flag3 = false; - - for (int l = blockX; l < blockX + pathPoint.xCoord; ++l) - { - for (int i1 = blockY; i1 < blockY + pathPoint.yCoord; ++i1) - { - for (int j1 = blockZ; j1 < blockZ + pathPoint.zCoord; ++j1) - { - Block block = entity.worldObj.getBlock(l, i1, j1); - - if(block == Blocks.air) - { - boolean heightClear = true; - for (int currentY = blockY; currentY <= Math.ceil(blockY + entity.height); ++currentY) { - Block b = entity.worldObj.getBlock(l, currentY, j1); - if (b != Blocks.air) { - heightClear = false; - break; - } - } - if (heightClear) { - return 2; - } - } - - if (block == Blocks.trapdoor) - { - flag3 = true; - } - else if (block != Blocks.flowing_water && block != Blocks.water) - { - if (!isWoddenDoorAllowed && block == Blocks.wooden_door) - { - return 0; - } - } - else - { - if (isPathingInWater) - { - return -1; - } - - flag3 = true; - } - - int k1 = block.getRenderType(); - - if (entity.worldObj.getBlock(l, i1, j1).getRenderType() == 9) - { - int j2 = MathHelper.floor_double(entity.posX); - int l1 = MathHelper.floor_double(entity.posY); - int i2 = MathHelper.floor_double(entity.posZ); - - if (entity.worldObj.getBlock(j2, l1, i2).getRenderType() != 9 && entity.worldObj.getBlock(j2, l1 - 1, i2).getRenderType() != 9) - { - return -3; - } - } - else if (!block.getBlocksMovement(entity.worldObj, l, i1, j1) && (!isMovementBlockAllowed || block != Blocks.wooden_door)) - { - if (k1 == 11 || block == Blocks.fence_gate || k1 == 32) - { - return -3; - } - - if (block == Blocks.trapdoor) - { - return -4; - } - - Material material = block.getMaterial(); - - if (material != Material.lava) - { - return 0; - } - - if (!entity.handleLavaMovement()) - { - return -2; - } - } - } - } - } - - return flag3 ? 2 : 1; - } - /** * Returns a new FlyPathEntity for a given start and end point */ diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java index 8ef5b7cef..e08dd1bd0 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathPoint.java @@ -46,7 +46,7 @@ public class FlyPathPoint extends PathPoint /** * Returns the linear distance to another path point */ - public float distanceTo(net.minecraft.pathfinding.PathPoint p_75829_1_) + public float distanceTo(FlyPathPoint p_75829_1_) { float f = (float)(p_75829_1_.xCoord - this.xCoord); float f1 = (float)(p_75829_1_.yCoord - this.yCoord); @@ -57,7 +57,7 @@ public class FlyPathPoint extends PathPoint /** * Returns the squared distance to another path point */ - public float distanceToSquared(net.minecraft.pathfinding.PathPoint p_75832_1_) + public float distanceToSquared(FlyPathPoint p_75832_1_) { float f = (float)(p_75832_1_.xCoord - this.xCoord); float f1 = (float)(p_75832_1_.yCoord - this.yCoord); From 6e67dbd37e7627c3d18cbe2c04feb86e64c5bc2a Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Sat, 5 Nov 2022 04:20:43 -0400 Subject: [PATCH 5/6] Fix OpenPoint --- src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java index eec63740b..50e32ddc9 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java @@ -105,12 +105,12 @@ public class FlyPathFinder extends PathFinder BlockPos blockpos1 = new BlockPos(entity); - return this.openPoint(blockpos1.getX(), i, blockpos1.getZ()); + return this.openPoint(blockpos1.getX(), i, blockpos1.getZ(), i); } public FlyPathPoint getPathPointToCoords(Entity entityIn, double x, double y, double z) { - return openPoint(MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); + return openPoint(MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z), (int)z); } From 98d0161e3d793244488f058a87f09c580c197ca5 Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Sat, 5 Nov 2022 04:39:10 -0400 Subject: [PATCH 6/6] Door Potential Fix --- .../npcs/ai/pathfinder/FlyPathFinder.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java index 50e32ddc9..b008790d1 100644 --- a/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java +++ b/src/main/java/noppes/npcs/ai/pathfinder/FlyPathFinder.java @@ -13,6 +13,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.IntHashMap; import net.minecraft.world.IBlockAccess; +import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import javax.annotation.Nullable; @@ -415,13 +416,10 @@ public class FlyPathFinder extends PathFinder } - - public PathNodeType getPathNodeType(IBlockAccess blockaccessIn, int x, int y, int z, EntityLiving entitylivingIn, int xSize, int ySize, int zSize, boolean canBreakDoorsIn, boolean canEnterDoorsIn) { EnumSet enumset = EnumSet.noneOf(PathNodeType.class); PathNodeType pathnodetype = PathNodeType.BLOCKED; - double d0 = (double)entitylivingIn.width / 2.0D; BlockPos blockpos = new BlockPos(entitylivingIn); pathnodetype = this.getPathNodeType(blockaccessIn, x, y, z, xSize, ySize, zSize, canBreakDoorsIn, canEnterDoorsIn, enumset, pathnodetype, blockpos); @@ -505,19 +503,23 @@ public class FlyPathFinder extends PathFinder if (pathnodetype == PathNodeType.OPEN && y >= 1) { PathNodeType pathnodetype1 = this.getPathNodeTypeRaw(blockaccessIn, x, y - 1, z); - pathnodetype = pathnodetype1 != PathNodeType.WALKABLE && pathnodetype1 != PathNodeType.OPEN && pathnodetype1 != PathNodeType.WATER && pathnodetype1 != PathNodeType.LAVA ? PathNodeType.WALKABLE : PathNodeType.OPEN; - if (pathnodetype1 == PathNodeType.DAMAGE_FIRE) + if (pathnodetype1 != PathNodeType.DAMAGE_FIRE && pathnodetype1 != PathNodeType.LAVA) + { + if (pathnodetype1 == PathNodeType.DAMAGE_CACTUS) + { + pathnodetype = PathNodeType.DAMAGE_CACTUS; + } + else if (pathnodetype1 == PathNodeType.DAMAGE_OTHER) pathnodetype = PathNodeType.DAMAGE_OTHER; + else + { + pathnodetype = pathnodetype1 != PathNodeType.WALKABLE && pathnodetype1 != PathNodeType.OPEN && pathnodetype1 != PathNodeType.WATER ? PathNodeType.WALKABLE : PathNodeType.OPEN; + } + } + else { pathnodetype = PathNodeType.DAMAGE_FIRE; } - - if (pathnodetype1 == PathNodeType.DAMAGE_CACTUS) - { - pathnodetype = PathNodeType.DAMAGE_CACTUS; - } - - if (pathnodetype1 == PathNodeType.DAMAGE_OTHER) pathnodetype = PathNodeType.DAMAGE_OTHER; } pathnodetype = this.checkNeighborBlocks(blockaccessIn, x, y, z, pathnodetype); @@ -575,14 +577,18 @@ public class FlyPathFinder extends PathFinder { return PathNodeType.DAMAGE_CACTUS; } - else if (block instanceof BlockDoor && material == Material.wood) + else if (block instanceof BlockDoor && material == Material.wood && !((BlockDoor)block).getBlocksMovement(this.worldMap, p_189553_2_, p_189553_3_, p_189553_4_)) { return PathNodeType.DOOR_WOOD_CLOSED; } - else if (block instanceof BlockDoor && material == Material.iron) + else if (block instanceof BlockDoor && material == Material.wood && !((BlockDoor)block).getBlocksMovement(this.worldMap, p_189553_2_, p_189553_3_, p_189553_4_)) { return PathNodeType.DOOR_IRON_CLOSED; } + else if (block instanceof BlockDoor && ((BlockDoor)block).getBlocksMovement(this.worldMap, p_189553_2_, p_189553_3_, p_189553_4_)) + { + return PathNodeType.DOOR_OPEN; + } else if (block instanceof BlockRailBase) { return PathNodeType.RAIL; @@ -623,7 +629,7 @@ public class FlyPathFinder extends PathFinder int entitySizeX = MathHelper.floor_double(p_192558_1_.width + 1.0F); int entitySizeY = MathHelper.floor_double(p_192558_1_.height + 1.0F); int entitySizeZ = MathHelper.floor_double(p_192558_1_.width + 1.0F); - return this.getPathNodeType(this.worldMap, p_192558_2_, p_192558_3_, p_192558_4_, p_192558_1_, entitySizeX, entitySizeY, entitySizeZ, false, false); + return this.getPathNodeType(this.worldMap, p_192558_2_, p_192558_3_, p_192558_4_, p_192558_1_, entitySizeX, entitySizeY, entitySizeZ, ((EntityCustomNpc)this.theEntity).ai.doorInteract == 0, ((EntityCustomNpc)this.theEntity).ai.doorInteract == 1); } public float getPathPriority(PathNodeType nodeType) @@ -631,6 +637,4 @@ public class FlyPathFinder extends PathFinder Float f = this.mapPathPriority.get(nodeType); return f == null ? nodeType.getPriority() : f.floatValue(); } - - }