Skip to content

Commit

Permalink
Actually pass mob to pathfinding methods
Browse files Browse the repository at this point in the history
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
Matyrobbrt committed Dec 6, 2024
1 parent e59a37f commit e91858f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 9 deletions.
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;
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;
+ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
if (i != 0 || k != 0) {
PathType pathtype = p_331893_.getPathTypeFromState(p_332169_ + i, p_330433_ + j, p_331506_ + k);
+ BlockState blockState = p_331893_.level().getBlockState(p_331893_.currentEvalPos());
+ PathType blockPathType = blockState.getAdjacentBlockPathType(p_331893_.level(), p_331893_.currentEvalPos(), null, pathtype);
+ PathType blockPathType = blockState.getAdjacentBlockPathType(p_331893_.level(), p_331893_.currentEvalPos(), p_331893_.mob, pathtype);
+ if (blockPathType != null) return blockPathType;
+ net.minecraft.world.level.material.FluidState fluidState = blockState.getFluidState();
+ PathType fluidPathType = fluidState.getAdjacentBlockPathType(p_331893_.level(), p_331893_.currentEvalPos(), null, pathtype);
+ PathType fluidPathType = fluidState.getAdjacentBlockPathType(p_331893_.level(), p_331893_.currentEvalPos(), p_331893_.mob, pathtype);
+ if (fluidPathType != null) return fluidPathType;
if (pathtype == PathType.DAMAGE_OTHER) {
return PathType.DANGER_OTHER;
}
@@ -496,6 +_,8 @@
@@ -494,8 +_,16 @@
return p_326944_;
}

+ /** @deprecated NeoForge: use {@link #getPathTypeFromState(BlockGetter, BlockPos, Mob) the mob-sensitive version} */
+ @Deprecated
protected static PathType getPathTypeFromState(BlockGetter p_77644_, BlockPos p_77645_) {
+ return getPathTypeFromState(p_77644_, p_77645_, null);
+ }
+
+ protected static PathType getPathTypeFromState(BlockGetter p_77644_, BlockPos p_77645_, @Nullable Mob mob) {
BlockState blockstate = p_77644_.getBlockState(p_77645_);
+ PathType type = blockstate.getBlockPathType(p_77644_, p_77645_, null);
+ PathType type = blockstate.getBlockPathType(p_77644_, p_77645_, mob);
+ if (type != null) return type;
Block block = blockstate.getBlock();
if (blockstate.isAir()) {
Expand All @@ -26,7 +34,7 @@
return PathType.COCOA;
} else if (!blockstate.is(Blocks.WITHER_ROSE) && !blockstate.is(Blocks.POINTED_DRIPSTONE)) {
FluidState fluidstate = blockstate.getFluidState();
+ PathType nonLoggableFluidPathType = fluidstate.getBlockPathType(p_77644_, p_77645_, null, false);
+ PathType nonLoggableFluidPathType = fluidstate.getBlockPathType(p_77644_, p_77645_, mob, false);
+ if (nonLoggableFluidPathType != null) return nonLoggableFluidPathType;
if (fluidstate.is(FluidTags.LAVA)) {
return PathType.LAVA;
Expand All @@ -35,7 +43,7 @@
if (!blockstate.isPathfindable(PathComputationType.LAND)) {
return PathType.BLOCKED;
} else {
+ PathType loggableFluidPathType = fluidstate.getBlockPathType(p_77644_, p_77645_, null, true);
+ PathType loggableFluidPathType = fluidstate.getBlockPathType(p_77644_, p_77645_, mob, true);
+ if (loggableFluidPathType != null) return loggableFluidPathType;
return fluidstate.is(FluidTags.WATER) ? PathType.WATER : PathType.OPEN;
}
Expand Down

0 comments on commit e91858f

Please sign in to comment.