Make the new pathfinder go through door corners instead of the middle of the door to avoid getting caught

This commit is contained in:
fullwall 2018-03-15 15:46:10 +08:00
parent 32e71968e0
commit 680af76457

View File

@ -4,6 +4,9 @@ import java.util.List;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.material.Door;
import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
@ -14,6 +17,7 @@ import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.AStarMachine;
import net.citizensnpcs.api.astar.pathfinder.ChunkBlockSource;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.Path;
import net.citizensnpcs.api.astar.pathfinder.VectorGoal;
import net.citizensnpcs.api.astar.pathfinder.VectorNode;
@ -108,6 +112,15 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
NMS.setShouldJump(npc.getEntity());
}
double destX = vector.getX() + 0.5, destZ = vector.getZ() + 0.5;
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData();
if (door.isOpen()) {
BlockFace targetFace = door.getFacing().getOppositeFace();
destX = vector.getX() + targetFace.getModX();
destZ = vector.getZ() + targetFace.getModZ();
}
}
NMS.setDestination(npc.getEntity(), destX, vector.getY(), destZ, params.speed());
params.run();
plan.run(npc);