From 5bfe08ecfb08fddbae2d7aca15f922c460d98d11 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 27 Jul 2020 15:56:42 +0800 Subject: [PATCH] Rudimentary movement strategy for non-living entities --- .../npc/ai/AStarNavigationStrategy.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java index f4fb0c708..a93bad6d9 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/AStarNavigationStrategy.java @@ -5,6 +5,7 @@ import java.util.List; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; import org.bukkit.util.Vector; import com.google.common.collect.Lists; @@ -24,6 +25,7 @@ import net.citizensnpcs.api.astar.pathfinder.VectorGoal; import net.citizensnpcs.api.astar.pathfinder.VectorNode; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.Util; public class AStarNavigationStrategy extends AbstractPathStrategy { private final Location destination; @@ -133,7 +135,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { Location currLoc = npc.getEntity().getLocation(NPC_LOCATION); Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5); /* Proper door movement - gets stuck on corners at times - + Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); if (MinecraftBlockExaminer.isDoor(block.getType())) { Door door = (Door) block.getState().getData(); @@ -160,11 +162,23 @@ public class AStarNavigationStrategy extends AbstractPathStrategy { Effect.ENDER_SIGNAL, 0); } double distance = xzDistance + dY * dY; - if (distance > 0 && dY > NMS.getStepHeight(npc.getEntity()) && xzDistance <= 2.75) { - NMS.setShouldJump(npc.getEntity()); - } - NMS.setDestination(npc.getEntity(), destVector.getX(), destVector.getY(), destVector.getZ(), params.speed()); + if (npc.getEntity() instanceof LivingEntity) { + if (distance > 0 && dY >= NMS.getStepHeight(npc.getEntity()) && xzDistance <= 2.75) { + NMS.setShouldJump(npc.getEntity()); + } + + NMS.setDestination(npc.getEntity(), destVector.getX(), destVector.getY(), destVector.getZ(), + params.speed()); + } else { + Vector dir = destVector.subtract(npc.getEntity().getLocation().toVector()).normalize().multiply(0.2); + Material in = npc.getEntity().getLocation().getBlock().getType(); + if (distance > 0 && dY >= 1 && xzDistance <= 2.75 || (dY >= 0.2 && MinecraftBlockExaminer.isLiquid(in))) { + dir.add(new Vector(0, 0.75, 0)); + } + Util.faceLocation(npc.getEntity(), destVector.toLocation(npc.getEntity().getWorld())); + npc.getEntity().setVelocity(dir); + } params.run(); plan.run(npc); return false;