mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 06:57:28 +02:00
Replace getSectionAt to getChunkCoordinate
This commit is contained in:
parent
77a14c0750
commit
f6db75b9aa
@ -16,7 +16,6 @@ import net.minestom.server.utils.chunk.ChunkUtils;
|
|||||||
import net.minestom.server.world.biomes.Biome;
|
import net.minestom.server.world.biomes.Biome;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
|
||||||
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -89,7 +88,7 @@ public abstract class Chunk implements Block.Getter, Block.Setter, Biome.Getter,
|
|||||||
public abstract @NotNull Section getSection(int section);
|
public abstract @NotNull Section getSection(int section);
|
||||||
|
|
||||||
public @NotNull Section getSectionAt(int blockY) {
|
public @NotNull Section getSectionAt(int blockY) {
|
||||||
return getSection(ChunkUtils.getSectionAt(blockY));
|
return getSection(ChunkUtils.getChunkCoordinate(blockY));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +121,7 @@ public class DynamicChunk extends Chunk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Retrieve the block from state id
|
// Retrieve the block from state id
|
||||||
final Section section = sections[ChunkUtils.getSectionAt(y) - minSection];
|
final Section section = sections[ChunkUtils.getChunkCoordinate(y) - minSection];
|
||||||
final int blockStateId = section.blockPalette()
|
final int blockStateId = section.blockPalette()
|
||||||
.get(toChunkRelativeCoordinate(x), y, toChunkRelativeCoordinate(z));
|
.get(toChunkRelativeCoordinate(x), y, toChunkRelativeCoordinate(z));
|
||||||
if (blockStateId == -1) return Block.AIR; // Section is empty
|
if (blockStateId == -1) return Block.AIR; // Section is empty
|
||||||
@ -130,7 +130,7 @@ public class DynamicChunk extends Chunk {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Biome getBiome(int x, int y, int z) {
|
public @NotNull Biome getBiome(int x, int y, int z) {
|
||||||
final Section section = sections[ChunkUtils.getSectionAt(y) - minSection];
|
final Section section = sections[ChunkUtils.getChunkCoordinate(y) - minSection];
|
||||||
final int id = section.biomePalette()
|
final int id = section.biomePalette()
|
||||||
.get(toChunkRelativeCoordinate(x) / 4, y / 4, toChunkRelativeCoordinate(z) / 4);
|
.get(toChunkRelativeCoordinate(x) / 4, y / 4, toChunkRelativeCoordinate(z) / 4);
|
||||||
return MinecraftServer.getBiomeManager().getById(id);
|
return MinecraftServer.getBiomeManager().getById(id);
|
||||||
|
@ -214,7 +214,7 @@ public class ChunkBatch implements Batch<ChunkCallback> {
|
|||||||
inverse.setBlock(x, y, z, prevBlock);
|
inverse.setBlock(x, y, z, prevBlock);
|
||||||
}
|
}
|
||||||
chunk.setBlock(x, y, z, block);
|
chunk.setBlock(x, y, z, block);
|
||||||
return ChunkUtils.getSectionAt(y);
|
return ChunkUtils.getChunkCoordinate(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,10 +139,6 @@ public final class ChunkUtils {
|
|||||||
return (int) index;
|
return (int) index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSectionAt(int y) {
|
|
||||||
return (int) Math.floor((double)y / Chunk.CHUNK_SECTION_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void forDifferingChunksInRange(int newChunkX, int newChunkZ,
|
public static void forDifferingChunksInRange(int newChunkX, int newChunkZ,
|
||||||
int oldChunkX, int oldChunkZ,
|
int oldChunkX, int oldChunkZ,
|
||||||
int range, @NotNull IntegerBiConsumer callback) {
|
int range, @NotNull IntegerBiConsumer callback) {
|
||||||
|
@ -28,15 +28,12 @@ public class CoordinateTest {
|
|||||||
assertEquals(1, ChunkUtils.getChunkCoordinate(16));
|
assertEquals(1, ChunkUtils.getChunkCoordinate(16));
|
||||||
assertEquals(-1, ChunkUtils.getChunkCoordinate(-16));
|
assertEquals(-1, ChunkUtils.getChunkCoordinate(-16));
|
||||||
assertEquals(3, ChunkUtils.getChunkCoordinate(48));
|
assertEquals(3, ChunkUtils.getChunkCoordinate(48));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
assertEquals(4, ChunkUtils.getChunkCoordinate(65));
|
||||||
public void sectionCoordinate() {
|
assertEquals(4, ChunkUtils.getChunkCoordinate(64));
|
||||||
assertEquals(4, ChunkUtils.getSectionAt(65));
|
assertEquals(3, ChunkUtils.getChunkCoordinate(63));
|
||||||
assertEquals(4, ChunkUtils.getSectionAt(64));
|
assertEquals(-2, ChunkUtils.getChunkCoordinate(-25));
|
||||||
assertEquals(3, ChunkUtils.getSectionAt(63));
|
assertEquals(23, ChunkUtils.getChunkCoordinate(380));
|
||||||
assertEquals(-2, ChunkUtils.getSectionAt(-25));
|
|
||||||
assertEquals(23, ChunkUtils.getSectionAt(380));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user