mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 03:11:25 +01:00
Convenient SECTION vec
This commit is contained in:
parent
78f7cffbb3
commit
dd96c907d9
@ -15,6 +15,7 @@ import java.util.function.DoubleUnaryOperator;
|
||||
public record Vec(double x, double y, double z) implements Point {
|
||||
public static final Vec ZERO = new Vec(0);
|
||||
public static final Vec ONE = new Vec(1);
|
||||
public static final Vec SECTION = new Vec(16);
|
||||
|
||||
public static final double EPSILON = 0.000001;
|
||||
|
||||
|
@ -22,8 +22,6 @@ import static net.minestom.server.utils.chunk.ChunkUtils.*;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class GeneratorImpl {
|
||||
private static final Vec SECTION_SIZE = new Vec(16);
|
||||
|
||||
public record GenSection(Palette blocks, Palette biomes, Int2ObjectMap<Block> specials) {
|
||||
public GenSection(Palette blocks, Palette biomes) {
|
||||
this(blocks, biomes, new Int2ObjectOpenHashMap<>(0));
|
||||
@ -37,9 +35,9 @@ public final class GeneratorImpl {
|
||||
static GenerationUnit section(DynamicRegistry<Biome> biomeRegistry, GenSection section,
|
||||
int sectionX, int sectionY, int sectionZ,
|
||||
boolean fork) {
|
||||
final Vec start = SECTION_SIZE.mul(sectionX, sectionY, sectionZ);
|
||||
final Vec end = start.add(SECTION_SIZE);
|
||||
final UnitModifier modifier = new SectionModifierImpl(biomeRegistry, SECTION_SIZE,
|
||||
final Vec start = Vec.SECTION.mul(sectionX, sectionY, sectionZ);
|
||||
final Vec end = start.add(Vec.SECTION);
|
||||
final UnitModifier modifier = new SectionModifierImpl(biomeRegistry, Vec.SECTION,
|
||||
start, end, section, fork);
|
||||
return unit(biomeRegistry, modifier, start, end, null);
|
||||
}
|
||||
@ -49,7 +47,7 @@ public final class GeneratorImpl {
|
||||
}
|
||||
|
||||
public static UnitImpl chunk(DynamicRegistry<Biome> biomeRegistry, GenSection[] chunkSections, int chunkX, int minSection, int chunkZ) {
|
||||
final Vec start = SECTION_SIZE.mul(chunkX, minSection, chunkZ);
|
||||
final Vec start = Vec.SECTION.mul(chunkX, minSection, chunkZ);
|
||||
return area(biomeRegistry, start, 1, chunkSections.length, 1, chunkSections);
|
||||
}
|
||||
|
||||
@ -72,7 +70,7 @@ public final class GeneratorImpl {
|
||||
}
|
||||
sections = List.copyOf(sections);
|
||||
|
||||
final Point size = SECTION_SIZE.mul(width, height, depth);
|
||||
final Point size = Vec.SECTION.mul(width, height, depth);
|
||||
final Point end = start.add(size);
|
||||
final UnitModifier modifier = new AreaModifierImpl(size, start, end, width, height, depth, sections);
|
||||
return unit(biomeRegistry, modifier, start, end, sections);
|
||||
@ -119,7 +117,7 @@ public final class GeneratorImpl {
|
||||
final int sectionY = getChunkCoordinate(y);
|
||||
final int sectionZ = getChunkCoordinate(z);
|
||||
if (sections == null) {
|
||||
this.minSection = SECTION_SIZE.mul(sectionX, sectionY, sectionZ);
|
||||
this.minSection = Vec.SECTION.mul(sectionX, sectionY, sectionZ);
|
||||
this.width = 1;
|
||||
this.height = 1;
|
||||
this.depth = 1;
|
||||
@ -200,7 +198,7 @@ public final class GeneratorImpl {
|
||||
}
|
||||
}
|
||||
final List<GenerationUnit> sections = List.of(units);
|
||||
final Point startSection = SECTION_SIZE.mul(minSectionX, minSectionY, minSectionZ);
|
||||
final Point startSection = Vec.SECTION.mul(minSectionX, minSectionY, minSectionZ);
|
||||
return registerFork(startSection, sections, width, height, depth);
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
public class GeneratorTest {
|
||||
@Test
|
||||
public void unitSize() {
|
||||
assertDoesNotThrow(() -> dummyUnit(Vec.ZERO, new Vec(16)));
|
||||
assertDoesNotThrow(() -> dummyUnit(new Vec(16), new Vec(32)));
|
||||
assertDoesNotThrow(() -> dummyUnit(Vec.ZERO, Vec.SECTION));
|
||||
assertDoesNotThrow(() -> dummyUnit(Vec.SECTION, new Vec(32)));
|
||||
assertThrows(IllegalArgumentException.class, () -> dummyUnit(new Vec(15), Vec.ZERO));
|
||||
assertThrows(IllegalArgumentException.class, () -> dummyUnit(new Vec(15), new Vec(32)));
|
||||
assertThrows(IllegalArgumentException.class, () -> dummyUnit(new Vec(15), new Vec(31)));
|
||||
@ -107,7 +107,7 @@ public class GeneratorTest {
|
||||
final int sectionY = -5;
|
||||
final int sectionZ = -2;
|
||||
GenerationUnit section = GeneratorImpl.section(null, new GenSection(), sectionX, sectionY, sectionZ);
|
||||
assertEquals(new Vec(16), section.size());
|
||||
assertEquals(Vec.SECTION, section.size());
|
||||
assertEquals(new Vec(sectionX * 16, sectionY * 16, sectionZ * 16), section.absoluteStart());
|
||||
assertEquals(new Vec(sectionX * 16 + 16, sectionY * 16 + 16, sectionZ * 16 + 16), section.absoluteEnd());
|
||||
}
|
||||
@ -126,7 +126,7 @@ public class GeneratorTest {
|
||||
assertEquals(sectionCount, subUnits.size());
|
||||
for (int i = 0; i < sectionCount; i++) {
|
||||
var subUnit = subUnits.get(i);
|
||||
assertEquals(new Vec(16, 16, 16), subUnit.size());
|
||||
assertEquals(Vec.SECTION, subUnit.size());
|
||||
assertEquals(new Vec(chunkX * 16, (i + minSection) * 16, chunkZ * 16), subUnit.absoluteStart());
|
||||
assertEquals(subUnit.absoluteStart().add(16), subUnit.absoluteEnd());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user