Skip to content

Commit

Permalink
Rudimentary movement strategy for non-living entities
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 27, 2020
1 parent e8c57ac commit 5bfe08e
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -24,6 +25,7 @@
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;
Expand Down Expand Up @@ -133,7 +135,7 @@ public boolean update() {
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();
Expand All @@ -160,11 +162,23 @@ public boolean update() {
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;
Expand Down

0 comments on commit 5bfe08e

Please sign in to comment.