mirror of https://github.com/Minestom/Minestom.git
Prepare changes for the biome api
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
00e5e6b2cc
commit
f52cc8d82b
|
@ -87,6 +87,8 @@ public class AnvilLoader implements IChunkLoader {
|
|||
if (fileChunk == null)
|
||||
return CompletableFuture.completedFuture(null);
|
||||
|
||||
Chunk chunk = new DynamicChunk(instance, chunkX, chunkZ);
|
||||
// TODO Biomes
|
||||
Biome[] biomes;
|
||||
if (fileChunk.getGenerationStatus().compareTo(ChunkColumn.GenerationStatus.Biomes) > 0) {
|
||||
int[] fileChunkBiomes = fileChunk.getBiomes();
|
||||
|
@ -99,7 +101,6 @@ public class AnvilLoader implements IChunkLoader {
|
|||
biomes = new Biome[1024]; // TODO don't hardcode
|
||||
Arrays.fill(biomes, BIOME);
|
||||
}
|
||||
Chunk chunk = new DynamicChunk(instance, biomes, chunkX, chunkZ);
|
||||
// Blocks
|
||||
loadBlocks(chunk, fileChunk);
|
||||
loadTileEntities(chunk, fileChunk);
|
||||
|
@ -260,10 +261,10 @@ public class AnvilLoader implements IChunkLoader {
|
|||
// Block
|
||||
BlockState state = new BlockState(block.name(), block.properties());
|
||||
chunkColumn.setBlockState(x, y, z, state);
|
||||
// Biome
|
||||
int index = ((y >> 2) & 63) << 4 | ((z >> 2) & 3) << 2 | ((x >> 2) & 3); // https://wiki.vg/Chunk_Format#Biomes
|
||||
Biome biome = chunk.getBiomes()[index];
|
||||
chunkColumn.setBiome(x, 0, z, biome.getId());
|
||||
// TODO Biome
|
||||
//int index = ((y >> 2) & 63) << 4 | ((z >> 2) & 3) << 2 | ((x >> 2) & 3); // https://wiki.vg/Chunk_Format#Biomes
|
||||
//Biome biome = chunk.getBiomes()[index];
|
||||
//chunkColumn.setBiome(x, 0, z, biome.getId());
|
||||
|
||||
// Tile entity
|
||||
var nbt = block.nbt();
|
||||
|
|
|
@ -14,7 +14,6 @@ import net.minestom.server.tag.Tag;
|
|||
import net.minestom.server.tag.TagHandler;
|
||||
import net.minestom.server.utils.ViewEngine;
|
||||
import net.minestom.server.utils.chunk.ChunkSupplier;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
@ -44,8 +43,6 @@ public abstract class Chunk implements BlockGetter, BlockSetter, Viewable, Ticka
|
|||
private final UUID identifier;
|
||||
|
||||
protected Instance instance;
|
||||
@NotNull
|
||||
protected final Biome[] biomes;
|
||||
protected final int chunkX, chunkZ;
|
||||
|
||||
// Options
|
||||
|
@ -61,20 +58,13 @@ public abstract class Chunk implements BlockGetter, BlockSetter, Viewable, Ticka
|
|||
// Data
|
||||
private final NBTCompound nbt = new NBTCompound();
|
||||
|
||||
public Chunk(@NotNull Instance instance, @Nullable Biome[] biomes, int chunkX, int chunkZ, boolean shouldGenerate) {
|
||||
public Chunk(@NotNull Instance instance, int chunkX, int chunkZ, boolean shouldGenerate) {
|
||||
this.identifier = UUID.randomUUID();
|
||||
this.instance = instance;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.shouldGenerate = shouldGenerate;
|
||||
|
||||
final int biomeCount = Biome.getBiomeCount(instance.getDimensionType());
|
||||
if (biomes != null && biomes.length == biomeCount) {
|
||||
this.biomes = biomes;
|
||||
} else {
|
||||
this.biomes = new Biome[biomeCount];
|
||||
}
|
||||
|
||||
final EntityTracker tracker = instance.getEntityTracker();
|
||||
this.viewers.updateTracker(toPosition(), tracker);
|
||||
}
|
||||
|
@ -169,10 +159,6 @@ public abstract class Chunk implements BlockGetter, BlockSetter, Viewable, Ticka
|
|||
return instance;
|
||||
}
|
||||
|
||||
public Biome[] getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk X.
|
||||
*
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.minestom.server.instance;
|
|||
|
||||
import net.minestom.server.instance.batch.ChunkBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -27,15 +26,6 @@ public interface ChunkGenerator {
|
|||
*/
|
||||
void generateChunkData(@NotNull ChunkBatch batch, int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* Defines all the {@link Biome} in the {@link Chunk}.
|
||||
*
|
||||
* @param biomes the array of {@link Biome}
|
||||
* @param chunkX the chunk X
|
||||
* @param chunkZ the chunk Z
|
||||
*/
|
||||
void fillBiomes(@NotNull Biome[] biomes, int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* Gets all the {@link ChunkPopulator} of this generator.
|
||||
*
|
||||
|
@ -43,5 +33,4 @@ public interface ChunkGenerator {
|
|||
*/
|
||||
@Nullable
|
||||
List<ChunkPopulator> getPopulators();
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import net.minestom.server.utils.MathUtils;
|
|||
import net.minestom.server.utils.Utils;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
@ -43,8 +42,8 @@ public class DynamicChunk extends Chunk {
|
|||
private final CachedPacket chunkCache = new CachedPacket(this::createChunkPacket);
|
||||
private final CachedPacket lightCache = new CachedPacket(this::createLightPacket);
|
||||
|
||||
public DynamicChunk(@NotNull Instance instance, @Nullable Biome[] biomes, int chunkX, int chunkZ) {
|
||||
super(instance, biomes, chunkX, chunkZ, true);
|
||||
public DynamicChunk(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
super(instance, chunkX, chunkZ, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,7 +138,7 @@ public class DynamicChunk extends Chunk {
|
|||
@NotNull
|
||||
@Override
|
||||
public Chunk copy(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
DynamicChunk dynamicChunk = new DynamicChunk(instance, biomes.clone(), chunkX, chunkZ);
|
||||
DynamicChunk dynamicChunk = new DynamicChunk(instance, chunkX, chunkZ);
|
||||
for (var entry : sectionMap.int2ObjectEntrySet()) {
|
||||
dynamicChunk.sectionMap.put(entry.getIntKey(), entry.getValue().clone());
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.minestom.server.instance;
|
|||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Entity;
|
||||
|
@ -26,7 +25,6 @@ import net.minestom.server.utils.chunk.ChunkSupplier;
|
|||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -284,13 +282,7 @@ public class InstanceContainer extends Instance {
|
|||
|
||||
protected @NotNull CompletableFuture<@NotNull Chunk> createChunk(int chunkX, int chunkZ) {
|
||||
final ChunkGenerator generator = this.chunkGenerator;
|
||||
Biome[] biomes = new Biome[Biome.getBiomeCount(getDimensionType())];
|
||||
if (generator == null) {
|
||||
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
|
||||
} else {
|
||||
generator.fillBiomes(biomes, chunkX, chunkZ);
|
||||
}
|
||||
final Chunk chunk = chunkSupplier.createChunk(this, biomes, chunkX, chunkZ);
|
||||
final Chunk chunk = chunkSupplier.createChunk(this, chunkX, chunkZ);
|
||||
Check.notNull(chunk, "Chunks supplied by a ChunkSupplier cannot be null.");
|
||||
if (generator != null && chunk.shouldGenerate()) {
|
||||
// Execute the chunk generator to populate the chunk
|
||||
|
|
|
@ -2,9 +2,7 @@ package net.minestom.server.utils.chunk;
|
|||
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Used to customize which type of {@link Chunk} an implementation should use.
|
||||
|
@ -16,11 +14,9 @@ public interface ChunkSupplier {
|
|||
* Creates a {@link Chunk} object.
|
||||
*
|
||||
* @param instance the linked instance
|
||||
* @param biomes the biomes of the chunk, can be null
|
||||
* @param chunkX the chunk X
|
||||
* @param chunkZ the chunk Z
|
||||
* @return a newly {@link Chunk} object, cannot be null
|
||||
*/
|
||||
@NotNull
|
||||
Chunk createChunk(@NotNull Instance instance, @Nullable Biome[] biomes, int chunkX, int chunkZ);
|
||||
@NotNull Chunk createChunk(@NotNull Instance instance, int chunkX, int chunkZ);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package demo;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.GlobalEventHandler;
|
||||
import net.minestom.server.event.player.PlayerLoginEvent;
|
||||
import net.minestom.server.instance.*;
|
||||
import net.minestom.server.instance.batch.ChunkBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MainDemo {
|
||||
|
@ -51,11 +49,6 @@ public class MainDemo {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillBiomes(@NotNull Biome[] biomes, int chunkX, int chunkZ) {
|
||||
Arrays.fill(biomes, Biome.PLAINS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChunkPopulator> getPopulators() {
|
||||
return null;
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package demo.generator;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.ChunkGenerator;
|
||||
import net.minestom.server.instance.ChunkPopulator;
|
||||
import net.minestom.server.instance.batch.ChunkBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ChunkGeneratorDemo implements ChunkGenerator {
|
||||
|
@ -24,11 +21,6 @@ public class ChunkGeneratorDemo implements ChunkGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillBiomes(@NotNull Biome[] biomes, int chunkX, int chunkZ) {
|
||||
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChunkPopulator> getPopulators() {
|
||||
return null;
|
||||
|
|
|
@ -2,18 +2,15 @@ package demo.generator;
|
|||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import de.articdive.jnoise.interpolation.InterpolationType;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.ChunkGenerator;
|
||||
import net.minestom.server.instance.ChunkPopulator;
|
||||
import net.minestom.server.instance.batch.ChunkBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -55,11 +52,6 @@ public class NoiseTestGenerator implements ChunkGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillBiomes(@NotNull Biome[] biomes, int chunkX, int chunkZ) {
|
||||
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChunkPopulator> getPopulators() {
|
||||
List<ChunkPopulator> list = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue