mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-01 04:51:29 +01:00
Update light packet, fix biome count
This commit is contained in:
parent
6b5125bcff
commit
a63c16892c
@ -55,8 +55,6 @@ public abstract class Chunk implements Viewable, Tickable, DataContainer {
|
||||
public static final int CHUNK_SIZE_Z = 16;
|
||||
public static final int CHUNK_SECTION_SIZE = 16;
|
||||
|
||||
public static final int BIOME_COUNT = 1024; // 4x4x4 blocks group
|
||||
|
||||
private final UUID identifier;
|
||||
|
||||
protected Instance instance;
|
||||
@ -85,10 +83,11 @@ public abstract class Chunk implements Viewable, Tickable, DataContainer {
|
||||
this.chunkZ = chunkZ;
|
||||
this.shouldGenerate = shouldGenerate;
|
||||
|
||||
if (biomes != null && biomes.length == BIOME_COUNT) {
|
||||
final int biomeCount = Biome.getBiomeCount(instance.getDimensionType());
|
||||
if (biomes != null && biomes.length == biomeCount) {
|
||||
this.biomes = biomes;
|
||||
} else {
|
||||
this.biomes = new Biome[BIOME_COUNT];
|
||||
this.biomes = new Biome[biomeCount];
|
||||
}
|
||||
}
|
||||
|
||||
@ -389,19 +388,17 @@ public abstract class Chunk implements Viewable, Tickable, DataContainer {
|
||||
UpdateLightPacket updateLightPacket = new UpdateLightPacket(getIdentifier(), getLastChangeTime());
|
||||
updateLightPacket.chunkX = getChunkX();
|
||||
updateLightPacket.chunkZ = getChunkZ();
|
||||
updateLightPacket.skyLightMask = 0b111111111111111111;
|
||||
updateLightPacket.emptySkyLightMask = 0b000000000000000000;
|
||||
updateLightPacket.blockLightMask = 0b000000000000000000;
|
||||
updateLightPacket.emptyBlockLightMask = 0b111111111111111111;
|
||||
//updateLightPacket.skyLightMask = 0b111111111111111111;
|
||||
//updateLightPacket.emptySkyLightMask = 0b000000000000000000;
|
||||
//updateLightPacket.blockLightMask = 0b000000000000000000;
|
||||
//updateLightPacket.emptyBlockLightMask = 0b111111111111111111;
|
||||
byte[] bytes = new byte[2048];
|
||||
Arrays.fill(bytes, (byte) 0xFF);
|
||||
final List<byte[]> temp = new ArrayList<>(18);
|
||||
for (int i = 0; i < 18; ++i) {
|
||||
temp.add(bytes);
|
||||
}
|
||||
updateLightPacket.skyLight = temp;
|
||||
updateLightPacket.blockLight = new ArrayList<>(0);
|
||||
|
||||
//updateLightPacket.skyLight = temp;
|
||||
return updateLightPacket;
|
||||
}
|
||||
|
||||
@ -494,7 +491,7 @@ public abstract class Chunk implements Viewable, Tickable, DataContainer {
|
||||
return;
|
||||
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
//playerConnection.sendPacket(getLightPacket());
|
||||
playerConnection.sendPacket(getLightPacket());
|
||||
playerConnection.sendPacket(createChunkPacket());
|
||||
}
|
||||
|
||||
@ -502,7 +499,7 @@ public abstract class Chunk implements Viewable, Tickable, DataContainer {
|
||||
if (!isLoaded()) {
|
||||
return;
|
||||
}
|
||||
//sendPacketToViewers(getLightPacket());
|
||||
sendPacketToViewers(getLightPacket());
|
||||
sendPacketToViewers(createChunkPacket());
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ public class DynamicChunk extends Chunk {
|
||||
}
|
||||
|
||||
// Write the biomes id
|
||||
for (int i = 0; i < BIOME_COUNT; i++) {
|
||||
for (int i = 0; i < 1024; i++) { // TODO variable biome count
|
||||
final byte id = (byte) biomes[i].getId();
|
||||
chunkWriter.writeByte(id);
|
||||
}
|
||||
@ -346,7 +346,7 @@ public class DynamicChunk extends Chunk {
|
||||
}
|
||||
|
||||
// Biomes
|
||||
for (int i = 0; i < BIOME_COUNT; i++) {
|
||||
for (int i = 0; i < 1024; i++) { // TODO variable biome count
|
||||
final byte id = reader.readByte();
|
||||
this.biomes[i] = BIOME_MANAGER.getById(id);
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
@Override
|
||||
protected void createChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
|
||||
Biome[] biomes = new Biome[Chunk.BIOME_COUNT];
|
||||
Biome[] biomes = new Biome[Biome.getBiomeCount(getDimensionType())];
|
||||
if (chunkGenerator == null) {
|
||||
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
|
||||
} else {
|
||||
|
@ -87,7 +87,7 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
final Section section = entry.getValue();
|
||||
|
||||
final int lengthIndex = index % 64;
|
||||
final int maskIndex = index / (16 + 1);
|
||||
final int maskIndex = index / 64;
|
||||
|
||||
long mask = maskMap.get(maskIndex);
|
||||
mask |= 1L << lengthIndex;
|
||||
@ -96,8 +96,12 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
Utils.writeSectionBlocks(blocks, section);
|
||||
}
|
||||
|
||||
writer.writeVarInt(maskMap.size());
|
||||
maskMap.values().forEach(writer::writeLong);
|
||||
final int maskSize = maskMap.size();
|
||||
writer.writeVarInt(maskSize);
|
||||
for (int i = 0; i < maskSize; i++) {
|
||||
final long value = maskMap.containsKey(i) ? maskMap.get(i) : 0;
|
||||
writer.writeLong(value);
|
||||
}
|
||||
|
||||
// TODO: don't hardcode heightmaps
|
||||
// Heightmap
|
||||
@ -130,7 +134,7 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
|
||||
// Data
|
||||
writer.writeVarInt(blocks.writerIndex());
|
||||
writer.getBuffer().writeBytes(blocks);
|
||||
writer.write(blocks);
|
||||
blocks.release();
|
||||
|
||||
// Block entities
|
||||
|
@ -23,14 +23,14 @@ public class UpdateLightPacket implements ServerPacket, CacheablePacket {
|
||||
//todo make changeable
|
||||
public boolean trustEdges = true;
|
||||
|
||||
public int skyLightMask;
|
||||
public int blockLightMask;
|
||||
public long[] skyLightMask = new long[0];
|
||||
public long[] blockLightMask = new long[0];
|
||||
|
||||
public int emptySkyLightMask;
|
||||
public int emptyBlockLightMask;
|
||||
public long[] emptySkyLightMask = new long[0];
|
||||
public long[] emptyBlockLightMask = new long[0];
|
||||
|
||||
public List<byte[]> skyLight;
|
||||
public List<byte[]> blockLight;
|
||||
public List<byte[]> skyLight = new ArrayList<>();
|
||||
public List<byte[]> blockLight = new ArrayList<>();
|
||||
|
||||
// Cacheable data
|
||||
private final UUID identifier;
|
||||
@ -42,19 +42,11 @@ public class UpdateLightPacket implements ServerPacket, CacheablePacket {
|
||||
*/
|
||||
public UpdateLightPacket() {
|
||||
this(UUID.randomUUID(), Long.MAX_VALUE);
|
||||
for (int i = 0; i < 14; i++) {
|
||||
skyLight.add(new byte[2048]);
|
||||
}
|
||||
for (int i = 0; i < 6; i++) {
|
||||
blockLight.add(new byte[2048]);
|
||||
}
|
||||
}
|
||||
|
||||
public UpdateLightPacket(@Nullable UUID identifier, long timestamp) {
|
||||
this.identifier = identifier;
|
||||
this.timestamp = timestamp;
|
||||
skyLight = new ArrayList<>(14);
|
||||
blockLight = new ArrayList<>(6);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,19 +56,19 @@ public class UpdateLightPacket implements ServerPacket, CacheablePacket {
|
||||
|
||||
writer.writeBoolean(trustEdges);
|
||||
|
||||
writer.writeVarInt(skyLightMask);
|
||||
writer.writeVarInt(blockLightMask);
|
||||
writer.writeLongArray(skyLightMask);
|
||||
writer.writeLongArray(blockLightMask);
|
||||
|
||||
writer.writeVarInt(emptySkyLightMask);
|
||||
writer.writeVarInt(emptyBlockLightMask);
|
||||
writer.writeLongArray(emptySkyLightMask);
|
||||
writer.writeLongArray(emptyBlockLightMask);
|
||||
|
||||
//writer.writeVarInt(skyLight.size());
|
||||
writer.writeVarInt(skyLight.size());
|
||||
for (byte[] bytes : skyLight) {
|
||||
writer.writeVarInt(2048); // Always 2048 length
|
||||
writer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
//writer.writeVarInt(blockLight.size());
|
||||
writer.writeVarInt(blockLight.size());
|
||||
for (byte[] bytes : blockLight) {
|
||||
writer.writeVarInt(2048); // Always 2048 length
|
||||
writer.writeBytes(bytes);
|
||||
@ -90,11 +82,11 @@ public class UpdateLightPacket implements ServerPacket, CacheablePacket {
|
||||
|
||||
trustEdges = reader.readBoolean();
|
||||
|
||||
skyLightMask = reader.readVarInt();
|
||||
blockLightMask = reader.readVarInt();
|
||||
skyLightMask = reader.readLongArray();
|
||||
blockLightMask = reader.readLongArray();
|
||||
|
||||
emptySkyLightMask = reader.readVarInt();
|
||||
emptyBlockLightMask = reader.readVarInt();
|
||||
emptySkyLightMask = reader.readLongArray();
|
||||
emptyBlockLightMask = reader.readLongArray();
|
||||
|
||||
// sky light
|
||||
skyLight.clear();
|
||||
|
@ -143,6 +143,15 @@ public class BinaryReader extends InputStream {
|
||||
return array;
|
||||
}
|
||||
|
||||
public long[] readLongArray() {
|
||||
final int size = readVarInt();
|
||||
long[] array = new long[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = readLong();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #readRemainingBytes()} (same semantics, but more consistent naming)
|
||||
*/
|
||||
|
@ -181,7 +181,7 @@ public class BinaryWriter extends OutputStream {
|
||||
* Writes a null terminated string to the buffer. This method adds the null character
|
||||
* to the end of the string before writing.
|
||||
*
|
||||
* @param string the string to write
|
||||
* @param string the string to write
|
||||
* @param charset the charset to encode in
|
||||
*/
|
||||
public void writeNullTerminatedString(@NotNull String string, @NotNull Charset charset) {
|
||||
@ -216,6 +216,17 @@ public class BinaryWriter extends OutputStream {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeLongArray(long[] array) {
|
||||
if (array == null) {
|
||||
writeVarInt(0);
|
||||
return;
|
||||
}
|
||||
writeVarInt(array.length);
|
||||
for (long element : array) {
|
||||
writeLong(element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a byte array.
|
||||
* <p>
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.minestom.server.world.biomes;
|
||||
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
@ -164,6 +166,11 @@ public class Biome {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getBiomeCount(DimensionType dimensionType) {
|
||||
final int height = dimensionType.getLogicalHeight();
|
||||
return 4 * 4 * 4 * (height / Chunk.CHUNK_SECTION_SIZE);
|
||||
}
|
||||
|
||||
public static class BiomeBuilder {
|
||||
|
||||
private NamespaceID name;
|
||||
|
@ -25,7 +25,7 @@ public class ChunkGeneratorDemo implements ChunkGenerator {
|
||||
|
||||
for (short x = 0; x < Chunk.CHUNK_SIZE_X; x++)
|
||||
for (short z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
|
||||
for (short y = 300; y < 500; y++) {
|
||||
for (short y = 250; y < 300; y++) {
|
||||
batch.setBlock(x, y, z, Block.STONE);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user