3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 00:50:13 +01:00

Write biomes to palette

Dieser Commit ist enthalten in:
Nassim Jahnke 2021-09-16 11:35:05 +02:00
Ursprung f72412484a
Commit bfe6389377
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 50 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -101,13 +101,6 @@ public class ChunkSectionType1_18 extends Type<ChunkSection> {
}
private void writePalette(final ByteBuf buffer, final DataPalette palette) {
// Make sure this works for 1.17 chunk sections //TODO ?
if (palette.size() == 0) {
buffer.writeByte(GLOBAL_PALETTE);
Type.VAR_INT.writePrimitive(buffer, 0);
return;
}
int bitsPerValue = 0;
while (palette.size() > 1 << bitsPerValue) {
bitsPerValue += 1;
@ -121,7 +114,7 @@ public class ChunkSectionType1_18 extends Type<ChunkSection> {
if (bitsPerValue == 0) {
// Write single value
Type.VAR_INT.writePrimitive(buffer, palette.entry(0)); //TODO right?
Type.VAR_INT.writePrimitive(buffer, palette.entry(0));
Type.VAR_INT.writePrimitive(buffer, 0); // Empty values length
return;
}

Datei anzeigen

@ -38,13 +38,16 @@ import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.BlockEntityIds;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.List;
public final class WorldPackets {
private static final int WIDTH_BITS = 2;
private static final int HORIZONTAL_MASK = 3;
private static final int BIOMES_PER_CHUNK = 4 * 4 * 4;
public static void register(final Protocol1_18To1_17_1 protocol) {
protocol.registerClientbound(ClientboundPackets1_17_1.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
@ -61,8 +64,8 @@ public final class WorldPackets {
@Override
public void registerMap() {
handler(wrapper -> {
final int chunkX = wrapper.read(Type.VAR_INT);
final int chunkZ = wrapper.read(Type.VAR_INT);
final int chunkX = wrapper.passthrough(Type.VAR_INT);
final int chunkZ = wrapper.passthrough(Type.VAR_INT);
if (wrapper.user().get(ChunkLightStorage.class).isLoaded(chunkX, chunkZ)) {
// Light packets updating already sent chunks are the same as before
return;
@ -130,28 +133,35 @@ public final class WorldPackets {
final int[] biomeData = oldChunk.getBiomeData();
final ChunkSection[] sections = oldChunk.getSections();
for (int i = 0; i < sections.length; i++) {
final ChunkSection section = sections[i];
ChunkSection section = sections[i];
if (section == null) {
// There's no section mask anymore
final ChunkSectionImpl emptySection = new ChunkSectionImpl(false);
sections[i] = emptySection;
emptySection.setNonAirBlocksCount(0);
emptySection.addPalette(new DataPaletteImpl(PaletteType.BIOMES));
continue;
section = new ChunkSectionImpl();
sections[i] = section;
section.setNonAirBlocksCount(0);
final DataPaletteImpl blockPalette = new DataPaletteImpl(PaletteType.BLOCKS);
blockPalette.addEntry(0);
section.addPalette(blockPalette);
}
// Fill biome palette
//TODO Use single value palette if given the possibility
final DataPaletteImpl biomePalette = new DataPaletteImpl(PaletteType.BIOMES);
//TODO
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
biomePalette.setValue(x, y, z, 0);
section.addPalette(biomePalette);
for (int biomeIndex = i * BIOMES_PER_CHUNK; biomeIndex < (i * BIOMES_PER_CHUNK) + BIOMES_PER_CHUNK; biomeIndex++) {
final int biome = biomeData[biomeIndex];
final int minX = (biomeIndex & HORIZONTAL_MASK) << 2;
final int minY = ((biomeIndex >> WIDTH_BITS + WIDTH_BITS) << 2) & 15;
final int minZ = (biomeIndex >> WIDTH_BITS & HORIZONTAL_MASK) << 2;
for (int x = minX; x < minX + 4; x++) {
for (int y = minY; y < minY + 4; y++) {
for (int z = minZ; z < minZ + 4; z++) {
biomePalette.setValue(x, y, z, biome);
}
}
}
}
//TODO
section.addPalette(biomePalette);
}
final Chunk chunk = new Chunk1_18(oldChunk.getX(), oldChunk.getZ(), oldChunk.getSections(), oldChunk.getHeightMap(), blockEntities);

Datei anzeigen

@ -42,28 +42,28 @@ public final class Chunk1_18Type extends Type<Chunk> {
}
@Override
public Chunk read(final ByteBuf input) throws Exception {
final int chunkX = input.readInt();
final int chunkZ = input.readInt();
final CompoundTag heightMap = Type.NBT.read(input);
public Chunk read(final ByteBuf buffer) throws Exception {
final int chunkX = buffer.readInt();
final int chunkZ = buffer.readInt();
final CompoundTag heightMap = Type.NBT.read(buffer);
Type.VAR_INT.readPrimitive(input); // Data size in bytes
Type.VAR_INT.readPrimitive(buffer); // Data size in bytes
// Read sections
final ChunkSection[] sections = new ChunkSection[ySectionCount];
for (int i = 0; i < ySectionCount; i++) {
sections[i] = Types1_18.CHUNK_SECTION.read(input);
sections[i] = Types1_18.CHUNK_SECTION.read(buffer);
}
final int blockEntitiesLength = Type.VAR_INT.readPrimitive(input);
final int blockEntitiesLength = Type.VAR_INT.readPrimitive(buffer);
final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength);
for (int i = 0; i < blockEntitiesLength; i++) {
blockEntities.add(Types1_18.BLOCK_ENTITY.read(input));
blockEntities.add(Types1_18.BLOCK_ENTITY.read(buffer));
}
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
final byte[] array = Type.REMAINING_BYTES.read(input);
if (buffer.readableBytes() > 0) {
final byte[] array = Type.REMAINING_BYTES.read(buffer);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
@ -73,26 +73,27 @@ public final class Chunk1_18Type extends Type<Chunk> {
}
@Override
public void write(final ByteBuf output, final Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
public void write(final ByteBuf buffer, final Chunk chunk) throws Exception {
buffer.writeInt(chunk.getX());
buffer.writeInt(chunk.getZ());
Type.NBT.write(output, chunk.getHeightMap());
Type.NBT.write(buffer, chunk.getHeightMap());
final ByteBuf buf = output.alloc().buffer();
final ByteBuf sectionBuffer = buffer.alloc().buffer();
try {
for (final ChunkSection section : chunk.getSections()) {
Types1_18.CHUNK_SECTION.write(buf, section);
Types1_18.CHUNK_SECTION.write(sectionBuffer, section);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf);
sectionBuffer.readerIndex(0);
Type.VAR_INT.writePrimitive(buffer, sectionBuffer.readableBytes());
buffer.writeBytes(sectionBuffer);
} finally {
buf.release(); // release buffer
sectionBuffer.release(); // release buffer
}
Type.VAR_INT.writePrimitive(buffer, chunk.blockEntities().size());
for (final BlockEntity blockEntity : chunk.blockEntities()) {
Types1_18.BLOCK_ENTITY.write(output, blockEntity);
Types1_18.BLOCK_ENTITY.write(buffer, blockEntity);
}
}

Datei anzeigen

@ -4,6 +4,7 @@ enableFeaturePreview("VERSION_CATALOGS")
dependencyResolutionManagement {
// configures repositories for all projects
repositories {
mavenLocal()
maven("https://repo.viaversion.com")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")