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