use of net.minecraft.world.CollisionView in project roadrunner by MaxNeedsSnacks.
the class LandPathNodeMakerMixin method getNodeTypeFromNeighbors.
/**
* @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) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
ChunkSection section = null;
// reads to just one chunk and avoid hits against the server chunk manager.
if (world instanceof CollisionView && WorldHelper.areNeighborsWithinSameChunk(pos)) {
// if the cached chunk section was initialized will early-exit.
if (!World.isOutOfBuildLimitVertically(y)) {
// This cast is always safe and is necessary to obtain direct references to chunk sections.
Chunk chunk = (Chunk) ((CollisionView) world).getExistingChunk(x >> 4, z >> 4);
// An empty chunk or section will never pose any danger sources, which will be caught later.
if (chunk != null) {
section = chunk.getSectionArray()[y >> 4];
}
}
// against this chunk section will always fail, allowing us to fast-exit.
if (ChunkSection.isEmpty(section) || PathNodeCache.isSectionSafeAsNeighbor(section)) {
return type;
}
}
int xStart = x - 1;
int yStart = y - 1;
int zStart = z - 1;
int xEnd = x + 1;
int yEnd = y + 1;
int zEnd = z + 1;
// Vanilla iteration order is XYZ
for (int adjX = xStart; adjX <= xEnd; adjX++) {
for (int adjY = yStart; adjY <= yEnd; adjY++) {
for (int adjZ = zStart; adjZ <= zEnd; adjZ++) {
// Skip the vertical column of the origin block
if (adjX == x && adjZ == z) {
continue;
}
BlockState state;
// retrieval by calling upon the cached chunk directly.
if (section != null) {
state = section.getBlockState(adjX & 15, adjY & 15, adjZ & 15);
} else {
state = world.getBlockState(pos.set(adjX, adjY, adjZ));
}
// Ensure that the block isn't air first to avoid expensive hash table accesses
if (state.isAir()) {
continue;
}
PathNodeType neighborType = PathNodeCache.getNeighborPathNodeType(state);
if (neighborType != PathNodeType.OPEN) {
return neighborType;
}
}
}
}
return type;
}
use of net.minecraft.world.CollisionView in project lithium-fabric by CaffeineMC.
the class LandPathNodeMakerMixin method getNodeTypeFromNeighbors.
/**
* @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) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
ChunkSection section = null;
// reads to just one chunk and avoid hits against the server chunk manager.
if (world instanceof CollisionView && WorldHelper.areNeighborsWithinSameChunk(pos)) {
// if the cached chunk section was initialized will early-exit.
if (!world.isOutOfHeightLimit(y)) {
// This cast is always safe and is necessary to obtain direct references to chunk sections.
Chunk chunk = (Chunk) ((CollisionView) world).getChunkAsView(Pos.ChunkCoord.fromBlockCoord(x), Pos.ChunkCoord.fromBlockCoord(z));
// An empty chunk or section will never pose any danger sources, which will be caught later.
if (chunk != null) {
section = chunk.getSectionArray()[Pos.SectionYIndex.fromBlockCoord(world, y)];
}
}
// against this chunk section will always fail, allowing us to fast-exit.
if (section == null || PathNodeCache.isSectionSafeAsNeighbor(section)) {
return type;
}
}
int xStart = x - 1;
int yStart = y - 1;
int zStart = z - 1;
int xEnd = x + 1;
int yEnd = y + 1;
int zEnd = z + 1;
// Vanilla iteration order is XYZ
for (int adjX = xStart; adjX <= xEnd; adjX++) {
for (int adjY = yStart; adjY <= yEnd; adjY++) {
for (int adjZ = zStart; adjZ <= zEnd; adjZ++) {
// Skip the vertical column of the origin block
if (adjX == x && adjZ == z) {
continue;
}
BlockState state;
// retrieval by calling upon the cached chunk directly.
if (section != null) {
state = section.getBlockState(adjX & 15, adjY & 15, adjZ & 15);
} else {
state = world.getBlockState(pos.set(adjX, adjY, adjZ));
}
// Ensure that the block isn't air first to avoid expensive hash table accesses
if (state.isAir()) {
continue;
}
PathNodeType neighborType = PathNodeCache.getNeighborPathNodeType(state);
if (neighborType != PathNodeType.OPEN) {
return neighborType;
}
}
}
}
return type;
}
Aggregations