mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
Attempt to fix falling with new pathfinder
This commit is contained in:
parent
7bc0d82de7
commit
f659205d61
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@ -119,7 +120,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
|
||||
if (params.debug()) {
|
||||
npc.getEntity().getWorld().playEffect(dest, Effect.ENDER_SIGNAL, 0);
|
||||
}
|
||||
if (npc.getEntity() instanceof LivingEntity && !npc.getEntity().getType().name().contains("ARMOR_STAND")) {
|
||||
if (npc.getEntity() instanceof LivingEntity && npc.getEntity().getType() != EntityType.ARMOR_STAND) {
|
||||
NMS.setDestination(npc.getEntity(), dest.getX(), dest.getY(), dest.getZ(), params.speed());
|
||||
} else {
|
||||
Vector dir = dest.toVector().subtract(npc.getEntity().getLocation().toVector()).normalize().multiply(0.2);
|
||||
|
@ -328,8 +328,30 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
public void setTarget(Function<NavigatorParameters, PathStrategy> strategy) {
|
||||
if (!npc.isSpawned())
|
||||
throw new IllegalStateException("npc is not spawned");
|
||||
switchParams();
|
||||
switchStrategyTo(strategy.apply(localParams));
|
||||
|
||||
if (executing != null) {
|
||||
stopNavigating(CancelReason.REPLACE);
|
||||
}
|
||||
localParams = defaultParams.clone();
|
||||
int fallDistance = npc.data().get(NPC.Metadata.PATHFINDER_FALL_DISTANCE,
|
||||
Setting.PATHFINDER_FALL_DISTANCE.asInt());
|
||||
if (fallDistance != -1) {
|
||||
localParams.examiner(new FallingExaminer(fallDistance));
|
||||
}
|
||||
if (npc.data().get(NPC.Metadata.PATHFINDER_OPEN_DOORS, Setting.NEW_PATHFINDER_OPENS_DOORS.asBoolean())) {
|
||||
localParams.examiner(new DoorExaminer());
|
||||
}
|
||||
if (Setting.NEW_PATHFINDER_CHECK_BOUNDING_BOXES.asBoolean()) {
|
||||
localParams.examiner(new BoundingBoxExaminer(npc.getEntity()));
|
||||
}
|
||||
updatePathfindingRange();
|
||||
executing = strategy.apply(localParams);
|
||||
stationaryTicks = 0;
|
||||
if (npc.isSpawned()) {
|
||||
NMS.updateNavigationWorld(npc.getEntity(), npc.getEntity().getWorld());
|
||||
updateTicket(executing.getTargetAsLocation());
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -431,7 +453,8 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
return;
|
||||
}
|
||||
}
|
||||
NavigationCancelEvent event = new NavigationCancelEvent(this, reason);
|
||||
NavigationCancelEvent event = reason == CancelReason.REPLACE ? new NavigationReplaceEvent(this)
|
||||
: new NavigationCancelEvent(this, reason);
|
||||
PathStrategy old = executing;
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (old == executing) {
|
||||
@ -439,35 +462,6 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void switchParams() {
|
||||
localParams = defaultParams.clone();
|
||||
int fallDistance = npc.data().get(NPC.Metadata.PATHFINDER_FALL_DISTANCE,
|
||||
Setting.PATHFINDER_FALL_DISTANCE.asInt());
|
||||
if (fallDistance != -1) {
|
||||
localParams.examiner(new FallingExaminer(fallDistance));
|
||||
}
|
||||
if (npc.data().get(NPC.Metadata.PATHFINDER_OPEN_DOORS, Setting.NEW_PATHFINDER_OPENS_DOORS.asBoolean())) {
|
||||
localParams.examiner(new DoorExaminer());
|
||||
}
|
||||
if (Setting.NEW_PATHFINDER_CHECK_BOUNDING_BOXES.asBoolean()) {
|
||||
localParams.examiner(new BoundingBoxExaminer(npc.getEntity()));
|
||||
}
|
||||
}
|
||||
|
||||
private void switchStrategyTo(PathStrategy newStrategy) {
|
||||
updatePathfindingRange();
|
||||
if (executing != null) {
|
||||
Bukkit.getPluginManager().callEvent(new NavigationReplaceEvent(this));
|
||||
}
|
||||
executing = newStrategy;
|
||||
stationaryTicks = 0;
|
||||
if (npc.isSpawned()) {
|
||||
NMS.updateNavigationWorld(npc.getEntity(), npc.getEntity().getWorld());
|
||||
updateTicket(executing.getTargetAsLocation());
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this));
|
||||
}
|
||||
|
||||
private void updateMountedStatus() {
|
||||
// TODO: this method seems to break assumptions: better to let the NPC pathfind for itself rather than
|
||||
// "commanding" the NPC below on the stack
|
||||
|
@ -35,6 +35,7 @@ public class FallingExaminer implements BlockExaminer {
|
||||
if (fall.containsKey(point))
|
||||
return PassableState.PASSABLE;
|
||||
|
||||
Vector ppos = point.getParentPoint().getVector();
|
||||
if (!MinecraftBlockExaminer
|
||||
.canStandOn(source.getBlockAt(pos.getBlockX(), pos.getBlockY() - 1, pos.getBlockZ()))) {
|
||||
Integer dist = fall.get(point.getParentPoint());
|
||||
@ -42,9 +43,9 @@ public class FallingExaminer implements BlockExaminer {
|
||||
// start a fall
|
||||
fall.put(point, 0);
|
||||
return PassableState.PASSABLE;
|
||||
} else if (dist != null && pos.getBlockY() < point.getParentPoint().getVector().getBlockY()
|
||||
&& pos.getBlockX() == point.getParentPoint().getVector().getBlockX()
|
||||
&& pos.getBlockZ() == point.getParentPoint().getVector().getBlockZ() && dist < maxFallDistance) {
|
||||
} else if (dist != null && dist < maxFallDistance && pos.getBlockY() < ppos.getBlockY()
|
||||
&& pos.getBlockX() == ppos.getBlockX() && pos.getBlockZ() == ppos.getBlockZ()
|
||||
&& MinecraftBlockExaminer.canStandIn(source.getBlockAt(pos))) {
|
||||
fall.put(point, dist + 1);
|
||||
return PassableState.PASSABLE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user