Minor changes

This commit is contained in:
fullwall 2023-10-14 00:08:49 +08:00
parent 7f6b6df4cf
commit 3ae2c0d538
3 changed files with 25 additions and 26 deletions

View File

@ -6,7 +6,7 @@ import java.util.stream.Stream;
import com.google.common.collect.ImmutableSet;
import net.citizensnpcs.Settings;
import net.citizensnpcs.Settings.Setting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.tags.BlockTags;
@ -60,7 +60,7 @@ public class EntityNavigation extends PathNavigation {
this.followRange = entityinsentient.getAttribute(Attributes.FOLLOW_RANGE);
this.nodeEvaluator = new EntityNodeEvaluator();
this.nodeEvaluator.setCanPassDoors(true);
this.pathFinder = new EntityPathfinder(this.nodeEvaluator, Settings.Setting.MAXIMUM_VISITED_NODES.asInt());
this.pathFinder = new EntityPathfinder(this.nodeEvaluator, Setting.MAXIMUM_VISITED_NODES.asInt());
this.setRange(24);
}
@ -186,24 +186,25 @@ public class EntityNavigation extends PathNavigation {
}
@Override
protected Path createPath(Set<BlockPos> var0, int var1, boolean var2, int var3) {
return createPath(var0, var1, var2, var3, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE));
protected Path createPath(Set<BlockPos> var0, int var1, boolean var2, int reachRange) {
return createPath(var0, var1, var2, reachRange, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE));
}
@Override
protected Path createPath(Set<BlockPos> var0, int var1, boolean var2, int var3, float var4) {
protected Path createPath(Set<BlockPos> var0, int var1, boolean headAbove, int reachRange, float range) {
if (var0.isEmpty() || (this.mob.getY() < this.level.getMinBuildHeight()) || !canUpdatePath())
return null;
if (this.path != null && !this.path.isDone() && var0.contains(this.targetPos))
return this.path;
BlockPos var5 = var2 ? this.mob.blockPosition().above() : this.mob.blockPosition();
int var6 = (int) (var4 + var1);
PathNavigationRegion var7 = new PathNavigationRegion(this.level, var5.offset(-var6, -var6, -var6),
var5.offset(var6, var6, var6));
Path var8 = this.pathFinder.findPath(var7, this.mob, var0, var4, var3, this.maxVisitedNodesMultiplier);
BlockPos headPos = headAbove ? this.mob.blockPosition().above() : this.mob.blockPosition();
int blockRange = (int) (range + var1);
PathNavigationRegion region = new PathNavigationRegion(this.level,
headPos.offset(-blockRange, -blockRange, -blockRange),
headPos.offset(blockRange, blockRange, blockRange));
Path var8 = this.pathFinder.findPath(region, this.mob, var0, range, reachRange, this.maxVisitedNodesMultiplier);
if (var8 != null && var8.getTarget() != null) {
this.targetPos = var8.getTarget();
this.reachRange = var3;
this.reachRange = reachRange;
this.resetStuckTimeout();
}

View File

@ -247,16 +247,16 @@ public class EntityNodeEvaluator extends EntityNodeEvaluatorBase {
while (var9.hasNext()) {
BlockPathTypes varr9 = (BlockPathTypes) var9.next();
if (var4.getPathfindingMalus(varr9) < 0.0F) {
if (mvmt.getPathfindingMalus(varr9) < 0.0F) {
return varr9;
}
if (var4.getPathfindingMalus(varr9) >= var4.getPathfindingMalus(var7)) {
if (mvmt.getPathfindingMalus(varr9) >= mvmt.getPathfindingMalus(var7)) {
var7 = varr9;
}
}
if (var6 == BlockPathTypes.OPEN && var4.getPathfindingMalus(var7) == 0.0F && this.entityWidth <= 1) {
if (var6 == BlockPathTypes.OPEN && mvmt.getPathfindingMalus(var7) == 0.0F && this.entityWidth <= 1) {
return BlockPathTypes.OPEN;
} else {
return var7;
@ -477,7 +477,7 @@ public class EntityNodeEvaluator extends EntityNodeEvaluatorBase {
@Override
public void prepare(PathNavigationRegion var0, Mob var1) {
super.prepare(var0, var1);
this.oldWaterCost = var1.getPathfindingMalus(BlockPathTypes.WATER);
this.oldWaterCost = mvmt.getPathfindingMalus(BlockPathTypes.WATER);
}
public static BlockPathTypes checkNeighbourBlocks(BlockGetter var0, BlockPos.MutableBlockPos var1,
@ -618,7 +618,5 @@ public class EntityNodeEvaluator extends EntityNodeEvaluatorBase {
|| CampfireBlock.isLitCampfire(var0) || var0.is(Blocks.LAVA_CAULDRON);
}
private static final double DEFAULT_MOB_JUMP_HEIGHT = 1.125;
public static final double SPACE_BETWEEN_WALL_POSTS = 0.5;
}

View File

@ -39,14 +39,14 @@ public class EntityPathfinder extends PathFinder {
this.maxVisitedNodes = var1;
}
public Path findPath(PathNavigationRegion var0, LivingEntity var1, Set<BlockPos> var2, float var3, int var4,
float var5) {
public Path findPath(PathNavigationRegion var0, LivingEntity var1, Set<BlockPos> var2, float range, int reachRange,
float maxVisitedNodesMultiplier) {
this.openSet.clear();
this.nodeEvaluator.prepare(var0, var1);
Node var6 = this.nodeEvaluator.getStart();
Map<Target, BlockPos> var7 = var2.stream().collect(
Collectors.toMap(p -> this.nodeEvaluator.getGoal(p.getX(), p.getY(), p.getZ()), Function.identity()));
Path var8 = findPath(null, var6, var7, var3, var4, var5);
Path var8 = findPath(null, var6, var7, range, reachRange, maxVisitedNodesMultiplier);
this.nodeEvaluator.done();
return var8;
}
@ -63,7 +63,7 @@ public class EntityPathfinder extends PathFinder {
return var8;
}
private Path findPath(ProfilerFiller var0, Node var1, Map<Target, BlockPos> var2, float var3, int var4,
private Path findPath(ProfilerFiller var0, Node var1, Map<Target, BlockPos> var2, float range, int reachRange,
float var5) {
Set<Target> var6 = var2.keySet();
var1.f = 0.0F;
@ -74,11 +74,11 @@ public class EntityPathfinder extends PathFinder {
Set var7 = ImmutableSet.of();
int var8 = 0;
Set<Target> var9 = Sets.newHashSetWithExpectedSize(var6.size());
int var10 = (int) (this.maxVisitedNodes * var5);
int maxVisitedNodesScaled = (int) (this.maxVisitedNodes * var5);
while (!this.openSet.isEmpty()) {
++var8;
if (var8 >= var10) {
if (var8 >= maxVisitedNodesScaled) {
break;
}
@ -88,7 +88,7 @@ public class EntityPathfinder extends PathFinder {
while (var13i.hasNext()) {
Target var13 = (Target) var13i.next();
if (var11.distanceManhattan(var13) <= var4) {
if (var11.distanceManhattan(var13) <= reachRange) {
var13.setReached();
var9.add(var13);
}
@ -98,7 +98,7 @@ public class EntityPathfinder extends PathFinder {
break;
}
if (!(var11.distanceTo(var1) >= var3)) {
if (!(var11.distanceTo(var1) >= range)) {
int var12 = this.nodeEvaluator.getNeighbors(this.neighbors, var11);
for (int var13 = 0; var13 < var12; ++var13) {
@ -106,7 +106,7 @@ public class EntityPathfinder extends PathFinder {
float var15 = this.distance(var11, var14);
var14.walkedDistance = var11.walkedDistance + var15;
float var16 = var11.f + var15 + var14.costMalus;
if (var14.walkedDistance < var3 && (!var14.inOpenSet() || var16 < var14.f)) {
if (var14.walkedDistance < range && (!var14.inOpenSet() || var16 < var14.f)) {
var14.cameFrom = var11;
var14.f = var16;
var14.h = this.getBestH(var14, var6) * 1.5F;