mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-15 23:26:16 +01:00
Rudimentary movement strategy for non-living entities
This commit is contained in:
parent
e8c57acac1
commit
5bfe08ecfb
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user