mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-25 01:21:24 +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.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
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.astar.pathfinder.VectorNode;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
|
||||||
public class AStarNavigationStrategy extends AbstractPathStrategy {
|
public class AStarNavigationStrategy extends AbstractPathStrategy {
|
||||||
private final Location destination;
|
private final Location destination;
|
||||||
@ -160,11 +162,23 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
|
|||||||
Effect.ENDER_SIGNAL, 0);
|
Effect.ENDER_SIGNAL, 0);
|
||||||
}
|
}
|
||||||
double distance = xzDistance + dY * dY;
|
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();
|
params.run();
|
||||||
plan.run(npc);
|
plan.run(npc);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user