mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 03:27:56 +01:00
Move and rename ChunkUtils.toSectionRelativeCoordinate, added tests
This commit is contained in:
parent
2d1102e0e8
commit
83d751ecf2
@ -66,7 +66,7 @@ public class DynamicChunk extends Chunk {
|
||||
}
|
||||
Section section = getSectionAt(y);
|
||||
section.blockPalette()
|
||||
.set(toChunkRelativeCoordinate(x), y, toChunkRelativeCoordinate(z), block.stateId());
|
||||
.set(ChunkUtils.toSectionRelativeCoordinate(x), ChunkUtils.toSectionRelativeCoordinate(y), ChunkUtils.toSectionRelativeCoordinate(z), block.stateId());
|
||||
|
||||
final int index = ChunkUtils.getBlockIndex(x, y, z);
|
||||
// Handler
|
||||
@ -89,9 +89,9 @@ public class DynamicChunk extends Chunk {
|
||||
this.chunkCache.invalidate();
|
||||
Section section = getSectionAt(y);
|
||||
section.biomePalette().set(
|
||||
toChunkRelativeCoordinate(x) / 4,
|
||||
toChunkRelativeCoordinate(y) / 4,
|
||||
toChunkRelativeCoordinate(z) / 4, biome.id());
|
||||
ChunkUtils.toSectionRelativeCoordinate(x) / 4,
|
||||
ChunkUtils.toSectionRelativeCoordinate(y) / 4,
|
||||
ChunkUtils.toSectionRelativeCoordinate(z) / 4, biome.id());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,7 +130,7 @@ public class DynamicChunk extends Chunk {
|
||||
// Retrieve the block from state id
|
||||
final Section section = getSectionAt(y);
|
||||
final int blockStateId = section.blockPalette()
|
||||
.get(toChunkRelativeCoordinate(x), y, toChunkRelativeCoordinate(z));
|
||||
.get(ChunkUtils.toSectionRelativeCoordinate(x), y, ChunkUtils.toSectionRelativeCoordinate(z));
|
||||
return Objects.requireNonNullElse(Block.fromStateId((short) blockStateId), Block.AIR);
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ public class DynamicChunk extends Chunk {
|
||||
public @NotNull Biome getBiome(int x, int y, int z) {
|
||||
final Section section = getSectionAt(y);
|
||||
final int id = section.biomePalette()
|
||||
.get(toChunkRelativeCoordinate(x) / 4, y / 4, toChunkRelativeCoordinate(z) / 4);
|
||||
.get(ChunkUtils.toSectionRelativeCoordinate(x) / 4, y / 4, ChunkUtils.toSectionRelativeCoordinate(z) / 4);
|
||||
return MinecraftServer.getBiomeManager().getById(id);
|
||||
}
|
||||
|
||||
@ -237,11 +237,4 @@ public class DynamicChunk extends Chunk {
|
||||
skyLights, blockLights);
|
||||
}
|
||||
|
||||
private static int toChunkRelativeCoordinate(int xz) {
|
||||
xz %= 16;
|
||||
if (xz < 0) {
|
||||
xz += Chunk.CHUNK_SECTION_SIZE;
|
||||
}
|
||||
return xz;
|
||||
}
|
||||
}
|
||||
|
@ -233,4 +233,18 @@ public final class ChunkUtils {
|
||||
public static int blockIndexToChunkPositionZ(int index) {
|
||||
return (index >> 28) & 0xF; // 28-32 bits
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a global coordinate value to a section coordinate
|
||||
*
|
||||
* @param xyz global coordinate
|
||||
* @return section coordinate
|
||||
*/
|
||||
public static int toSectionRelativeCoordinate(int xyz) {
|
||||
xyz %= 16;
|
||||
if (xyz < 0) {
|
||||
xyz += Chunk.CHUNK_SECTION_SIZE;
|
||||
}
|
||||
return xyz;
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,11 @@ public class CoordinateTest {
|
||||
assertEquals(0, temp.y());
|
||||
assertEquals(0, temp.z());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toSectionRelativeCoordinate() {
|
||||
assertEquals(12, ChunkUtils.toSectionRelativeCoordinate(-20));
|
||||
assertEquals(5, ChunkUtils.toSectionRelativeCoordinate(5));
|
||||
assertEquals(4, ChunkUtils.toSectionRelativeCoordinate(20));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user