3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-17 01:23:43 +02: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) { 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; int bitsPerValue = 0;
while (palette.size() > 1 << bitsPerValue) { while (palette.size() > 1 << bitsPerValue) {
bitsPerValue += 1; bitsPerValue += 1;
@ -121,7 +114,7 @@ public class ChunkSectionType1_18 extends Type<ChunkSection> {
if (bitsPerValue == 0) { if (bitsPerValue == 0) {
// Write single value // 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 Type.VAR_INT.writePrimitive(buffer, 0); // Empty values length
return; 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.Protocol1_18To1_17_1;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type; 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.ArrayList;
import java.util.List; import java.util.List;
public final class WorldPackets { 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) { public static void register(final Protocol1_18To1_17_1 protocol) {
protocol.registerClientbound(ClientboundPackets1_17_1.BLOCK_ENTITY_DATA, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_17_1.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override @Override
@ -61,8 +64,8 @@ public final class WorldPackets {
@Override @Override
public void registerMap() { public void registerMap() {
handler(wrapper -> { handler(wrapper -> {
final int chunkX = wrapper.read(Type.VAR_INT); final int chunkX = wrapper.passthrough(Type.VAR_INT);
final int chunkZ = wrapper.read(Type.VAR_INT); final int chunkZ = wrapper.passthrough(Type.VAR_INT);
if (wrapper.user().get(ChunkLightStorage.class).isLoaded(chunkX, chunkZ)) { if (wrapper.user().get(ChunkLightStorage.class).isLoaded(chunkX, chunkZ)) {
// Light packets updating already sent chunks are the same as before // Light packets updating already sent chunks are the same as before
return; return;
@ -130,28 +133,35 @@ public final class WorldPackets {
final int[] biomeData = oldChunk.getBiomeData(); final int[] biomeData = oldChunk.getBiomeData();
final ChunkSection[] sections = oldChunk.getSections(); final ChunkSection[] sections = oldChunk.getSections();
for (int i = 0; i < sections.length; i++) { for (int i = 0; i < sections.length; i++) {
final ChunkSection section = sections[i]; ChunkSection section = sections[i];
if (section == null) { if (section == null) {
// There's no section mask anymore // There's no section mask anymore
final ChunkSectionImpl emptySection = new ChunkSectionImpl(false); section = new ChunkSectionImpl();
sections[i] = emptySection; sections[i] = section;
emptySection.setNonAirBlocksCount(0); section.setNonAirBlocksCount(0);
emptySection.addPalette(new DataPaletteImpl(PaletteType.BIOMES));
continue; final DataPaletteImpl blockPalette = new DataPaletteImpl(PaletteType.BLOCKS);
blockPalette.addEntry(0);
section.addPalette(blockPalette);
} }
// Fill biome palette // Fill biome palette
//TODO Use single value palette if given the possibility
final DataPaletteImpl biomePalette = new DataPaletteImpl(PaletteType.BIOMES); final DataPaletteImpl biomePalette = new DataPaletteImpl(PaletteType.BIOMES);
//TODO section.addPalette(biomePalette);
for (int x = 0; x < 16; x++) { for (int biomeIndex = i * BIOMES_PER_CHUNK; biomeIndex < (i * BIOMES_PER_CHUNK) + BIOMES_PER_CHUNK; biomeIndex++) {
for (int y = 0; y < 16; y++) { final int biome = biomeData[biomeIndex];
for (int z = 0; z < 16; z++) { final int minX = (biomeIndex & HORIZONTAL_MASK) << 2;
biomePalette.setValue(x, y, z, 0); 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); 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 @Override
public Chunk read(final ByteBuf input) throws Exception { public Chunk read(final ByteBuf buffer) throws Exception {
final int chunkX = input.readInt(); final int chunkX = buffer.readInt();
final int chunkZ = input.readInt(); final int chunkZ = buffer.readInt();
final CompoundTag heightMap = Type.NBT.read(input); 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 // Read sections
final ChunkSection[] sections = new ChunkSection[ySectionCount]; final ChunkSection[] sections = new ChunkSection[ySectionCount];
for (int i = 0; i < ySectionCount; i++) { 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); final List<BlockEntity> blockEntities = new ArrayList<>(blockEntitiesLength);
for (int i = 0; i < blockEntitiesLength; i++) { 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) // Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) { if (buffer.readableBytes() > 0) {
final byte[] array = Type.REMAINING_BYTES.read(input); final byte[] array = Type.REMAINING_BYTES.read(buffer);
if (Via.getManager().isDebug()) { if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); 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 @Override
public void write(final ByteBuf output, final Chunk chunk) throws Exception { public void write(final ByteBuf buffer, final Chunk chunk) throws Exception {
output.writeInt(chunk.getX()); buffer.writeInt(chunk.getX());
output.writeInt(chunk.getZ()); 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 { try {
for (final ChunkSection section : chunk.getSections()) { for (final ChunkSection section : chunk.getSections()) {
Types1_18.CHUNK_SECTION.write(buf, section); Types1_18.CHUNK_SECTION.write(sectionBuffer, section);
} }
buf.readerIndex(0); sectionBuffer.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes()); Type.VAR_INT.writePrimitive(buffer, sectionBuffer.readableBytes());
output.writeBytes(buf); buffer.writeBytes(sectionBuffer);
} finally { } finally {
buf.release(); // release buffer sectionBuffer.release(); // release buffer
} }
Type.VAR_INT.writePrimitive(buffer, chunk.blockEntities().size());
for (final BlockEntity blockEntity : chunk.blockEntities()) { 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 { dependencyResolutionManagement {
// configures repositories for all projects // configures repositories for all projects
repositories { repositories {
mavenLocal()
maven("https://repo.viaversion.com") maven("https://repo.viaversion.com")
maven("https://papermc.io/repo/repository/maven-public/") maven("https://papermc.io/repo/repository/maven-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/repositories/snapshots/")