Add WIP falling movement examiner

This commit is contained in:
fullwall 2021-05-13 15:41:49 +08:00
parent cf6cbaf4a3
commit 0ddfcbd0fa
2 changed files with 62 additions and 44 deletions

View File

@ -1,44 +0,0 @@
package net.citizensnpcs.npc.ai;
import java.util.List;
import org.bukkit.util.Vector;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.astar.pathfinder.BlockSource;
import net.citizensnpcs.api.astar.pathfinder.NeighbourGeneratorBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.PathPoint;
public class EnhancedMovementExaminer implements NeighbourGeneratorBlockExaminer {
@Override
public float getCost(BlockSource source, PathPoint point) {
return 0;
}
@Override
public List<PathPoint> getNeighbours(BlockSource source, PathPoint point) {
Vector location = point.getVector();
List<PathPoint> neighbours = Lists.newArrayList();
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && y == 0 && z == 0)
continue;
if (x != 0 && z != 0)
continue;
Vector mod = location.clone().add(new Vector(x, y, z));
if (mod.equals(location))
continue;
neighbours.add(point.createAtOffset(mod));
}
}
}
return neighbours;
}
@Override
public PassableState isPassable(BlockSource source, PathPoint point) {
return null;
}
}

View File

@ -0,0 +1,62 @@
package net.citizensnpcs.npc.ai;
import java.util.List;
import org.bukkit.util.Vector;
import com.google.common.collect.ImmutableList;
import net.citizensnpcs.api.astar.pathfinder.BlockSource;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.NeighbourGeneratorBlockExaminer;
import net.citizensnpcs.api.astar.pathfinder.PathPoint;
import net.citizensnpcs.api.astar.pathfinder.VectorNode;
public class FallMovementExaminer implements NeighbourGeneratorBlockExaminer {
private final int maxFallDistance;
public FallMovementExaminer(int maxFallDistance) {
this.maxFallDistance = maxFallDistance;
}
@Override
public float getCost(BlockSource source, PathPoint point) {
return 0;
}
@Override
public List<PathPoint> getNeighbours(BlockSource source, PathPoint point) {
Vector location = point.getVector();
List<PathPoint> neighbours = ((VectorNode) point).getNeighbours(source, point);
if (location.getBlockY() <= 1 || point.getGoal().getBlockY() >= location.getBlockY())
return neighbours;
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && z == 0)
continue;
Vector mod = location.clone().add(new Vector(x, 0, z));
if (MinecraftBlockExaminer
.canStandOn(source.getMaterialAt(mod.getBlockX(), mod.getBlockY() - 1, mod.getBlockZ())))
continue;
for (int dy = 2; dy < maxFallDistance; dy++) {
if (mod.getBlockY() - dy <= 2 || !MinecraftBlockExaminer
.canStandIn(source.getMaterialAt(mod.getBlockX(), mod.getBlockY() - dy, mod.getBlockZ())))
break;
if (MinecraftBlockExaminer.canStandOn(
source.getMaterialAt(mod.getBlockX(), mod.getBlockY() - dy - 1, mod.getBlockZ()))) {
PathPoint fall = point.createAtOffset(mod.clone().setY(mod.getBlockY() - dy));
fall.setPathVectors(ImmutableList.of(mod, fall.getVector()));
neighbours.add(fall);
break;
}
}
}
}
return neighbours;
}
@Override
public PassableState isPassable(BlockSource source, PathPoint point) {
return PassableState.IGNORE;
}
}