forked from neoforged/NeoForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually pass mob to pathfinding methods
The current code would only pass `null` to `getAdjacentBlockPathType` and `getBlockPathType`. This PR fixes it by introducing overloads with the mob and storing the mob in the `PathfindingContext`
- Loading branch information
1 parent
e59a37f
commit e91858f
Showing
3 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
patches/net/minecraft/world/level/pathfinder/PathTypeCache.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- a/net/minecraft/world/level/pathfinder/PathTypeCache.java | ||
+++ b/net/minecraft/world/level/pathfinder/PathTypeCache.java | ||
@@ -11,11 +_,16 @@ | ||
private final long[] positions = new long[4096]; | ||
private final PathType[] pathTypes = new PathType[4096]; | ||
|
||
+ /** @deprecated NeoForge: use {@link #getOrCompute(BlockGetter, BlockPos, net.minecraft.world.entity.Mob) mob-sensitive version} */ | ||
+ @Deprecated | ||
public PathType getOrCompute(BlockGetter p_330930_, BlockPos p_331162_) { | ||
+ return getOrCompute(p_330930_, p_331162_, null); | ||
+ } | ||
+ public PathType getOrCompute(BlockGetter p_330930_, BlockPos p_331162_, @Nullable net.minecraft.world.entity.Mob mob) { | ||
long i = p_331162_.asLong(); | ||
int j = index(i); | ||
PathType pathtype = this.get(j, i); | ||
- return pathtype != null ? pathtype : this.compute(p_330930_, p_331162_, j, i); | ||
+ return pathtype != null ? pathtype : this.compute(p_330930_, p_331162_, j, i, mob); | ||
} | ||
|
||
@Nullable | ||
@@ -23,8 +_,13 @@ | ||
return this.positions[p_330588_] == p_331771_ ? this.pathTypes[p_330588_] : null; | ||
} | ||
|
||
+ /** @deprecated NeoForge: use {@link #compute(BlockGetter, BlockPos, int, long, net.minecraft.world.entity.Mob) mob-sensitive version} */ | ||
+ @Deprecated | ||
private PathType compute(BlockGetter p_330773_, BlockPos p_330311_, int p_330671_, long p_332065_) { | ||
- PathType pathtype = WalkNodeEvaluator.getPathTypeFromState(p_330773_, p_330311_); | ||
+ return compute(p_330773_, p_330311_, p_330671_, p_332065_, null); | ||
+ } | ||
+ private PathType compute(BlockGetter p_330773_, BlockPos p_330311_, int p_330671_, long p_332065_, @Nullable net.minecraft.world.entity.Mob mob) { | ||
+ PathType pathtype = WalkNodeEvaluator.getPathTypeFromState(p_330773_, p_330311_, mob); | ||
this.positions[p_330671_] = p_332065_; | ||
this.pathTypes[p_330671_] = pathtype; | ||
return pathtype; |
29 changes: 26 additions & 3 deletions
29
patches/net/minecraft/world/level/pathfinder/PathfindingContext.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
--- a/net/minecraft/world/level/pathfinder/PathfindingContext.java | ||
+++ b/net/minecraft/world/level/pathfinder/PathfindingContext.java | ||
@@ -41,4 +_,8 @@ | ||
@@ -13,6 +_,7 @@ | ||
private final PathTypeCache cache; | ||
private final BlockPos mobPosition; | ||
private final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(); | ||
+ final Mob mob; | ||
|
||
public PathfindingContext(CollisionGetter p_331783_, Mob p_331698_) { | ||
this.level = p_331783_; | ||
@@ -23,11 +_,12 @@ | ||
} | ||
|
||
this.mobPosition = p_331698_.blockPosition(); | ||
+ this.mob = p_331698_; | ||
} | ||
|
||
public PathType getPathTypeFromState(int p_331972_, int p_330358_, int p_330334_) { | ||
BlockPos blockpos = this.mutablePos.set(p_331972_, p_330358_, p_330334_); | ||
- return this.cache == null ? WalkNodeEvaluator.getPathTypeFromState(this.level, blockpos) : this.cache.getOrCompute(this.level, blockpos); | ||
+ return this.cache == null ? WalkNodeEvaluator.getPathTypeFromState(this.level, blockpos, mob) : this.cache.getOrCompute(this.level, blockpos, mob); | ||
} | ||
|
||
public BlockState getBlockState(BlockPos p_330575_) { | ||
@@ -40,5 +_,9 @@ | ||
|
||
public BlockPos mobPosition() { | ||
return this.mobPosition; | ||
} | ||
+ } | ||
+ | ||
+ BlockPos currentEvalPos() { | ||
+ return this.mutablePos; | ||
+ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters