Skip to content

Commit

Permalink
fix: replaced in LandPathNodeMakerMixin overwrite with injecting and …
Browse files Browse the repository at this point in the history
…cancelling pattern to avoid incompatibilities with other mods. (Thanks for devpelux)
  • Loading branch information
AbdElAziz333 committed Sep 23, 2022
1 parent 529a216 commit 4410a48
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* Determining the type of node offered by a block state is a very slow operation due to the nasty chain of tag,
Expand All @@ -27,8 +29,8 @@ public abstract class LandPathNodeMakerMixin {
* @reason Use optimized implementation
* @author JellySquid
*/
@Overwrite
public static PathNodeType getCommonNodeType(BlockView blockView, BlockPos blockPos) {
@Inject(method = "getCommonNodeType", at = @At("HEAD"), cancellable = true)
private static void getCommonNodeType(BlockView blockView, BlockPos blockPos, CallbackInfoReturnable<PathNodeType> cir) {
BlockState blockState = blockView.getBlockState(blockPos);
PathNodeType type = PathNodeCache.getPathNodeType(blockState);

Expand All @@ -39,23 +41,25 @@ public static PathNodeType getCommonNodeType(BlockView blockView, BlockPos block
// It should be safe to perform it last in actuality and take advantage of the cache for fluid types as well
// since fluids will always pass this check.
if (!blockState.canPathfindThrough(blockView, blockPos, NavigationType.LAND)) {
return PathNodeType.BLOCKED;
cir.setReturnValue(PathNodeType.BLOCKED);
return;
}

// All checks succeed, this path node really is open!
return type;
cir.setReturnValue(type);
return;
}

// Return the cached value since we found an obstacle earlier
return type;
cir.setReturnValue(type);
}

/**
* @reason Use optimized implementation which avoids scanning blocks for dangers where possible
* @author JellySquid
*/
@Overwrite
public static PathNodeType getNodeTypeFromNeighbors(BlockView world, BlockPos.Mutable pos, PathNodeType type) {
@Inject(method = "getNodeTypeFromNeighbors", at = @At("HEAD"), cancellable = true)
private static void getNodeTypeFromNeighbors(BlockView world, BlockPos.Mutable pos, PathNodeType type, CallbackInfoReturnable<PathNodeType> cir) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
Expand All @@ -82,7 +86,8 @@ public static PathNodeType getNodeTypeFromNeighbors(BlockView world, BlockPos.Mu
// section is empty or contains any dangerous blocks within the palette. If not, we can assume any checks
// against this chunk section will always fail, allowing us to fast-exit.
if (section == null || PathNodeCache.isSectionSafeAsNeighbor(section)) {
return type;
cir.setReturnValue(type);
return;
}
}

Expand Down Expand Up @@ -121,12 +126,13 @@ public static PathNodeType getNodeTypeFromNeighbors(BlockView world, BlockPos.Mu
PathNodeType neighborType = PathNodeCache.getNeighborPathNodeType(state);

if (neighborType != PathNodeType.OPEN) {
return neighborType;
cir.setReturnValue(neighborType);
return;
}
}
}
}

return type;
cir.setReturnValue(type);
}
}
}

0 comments on commit 4410a48

Please sign in to comment.