From e91858f076088e95dbba385be6c5a422c41caabe Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Fri, 6 Dec 2024 19:56:05 +0200 Subject: [PATCH] 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` --- .../level/pathfinder/PathTypeCache.java.patch | 35 +++++++++++++++++++ .../pathfinder/PathfindingContext.java.patch | 29 +++++++++++++-- .../pathfinder/WalkNodeEvaluator.java.patch | 20 +++++++---- 3 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 patches/net/minecraft/world/level/pathfinder/PathTypeCache.java.patch diff --git a/patches/net/minecraft/world/level/pathfinder/PathTypeCache.java.patch b/patches/net/minecraft/world/level/pathfinder/PathTypeCache.java.patch new file mode 100644 index 00000000000..331e068414b --- /dev/null +++ b/patches/net/minecraft/world/level/pathfinder/PathTypeCache.java.patch @@ -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; diff --git a/patches/net/minecraft/world/level/pathfinder/PathfindingContext.java.patch b/patches/net/minecraft/world/level/pathfinder/PathfindingContext.java.patch index 42c87e81c83..f49343d64d8 100644 --- a/patches/net/minecraft/world/level/pathfinder/PathfindingContext.java.patch +++ b/patches/net/minecraft/world/level/pathfinder/PathfindingContext.java.patch @@ -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; -+ } + } } diff --git a/patches/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch b/patches/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch index 65153f5d5ea..cb84cb52b90 100644 --- a/patches/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch +++ b/patches/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java.patch @@ -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()) { @@ -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; @@ -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; }