From decb20d2d1274dafd0401e618de6961c325cf629 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Mon, 2 Dec 2019 11:20:48 +0100 Subject: [PATCH 1/2] Convert biome data to 1.15 format --- .../api/minecraft/chunks/Chunk.java | 2 ++ .../packets/WorldPackets.java | 20 +++++++++++++++ .../types/Chunk1_15Type.java | 25 ++++++++----------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java index 690b45339..2a97adca5 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java @@ -17,6 +17,8 @@ public interface Chunk { int[] getBiomeData(); + void setBiomeData(int[] biomeData); + CompoundTag getHeightMap(); void setHeightMap(CompoundTag heightMap); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index c1510c3f0..285e9d9bb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -83,6 +83,26 @@ public class WorldPackets { Chunk chunk = wrapper.read(new Chunk1_14Type(clientWorld)); wrapper.write(new Chunk1_15Type(clientWorld), chunk); + if (chunk.isGroundUp()) { + int[] biomeData = chunk.getBiomeData(); + int[] newBiomeData = new int[1024]; + // Now in 4x4x4 areas (x, then z, then y) + // Set the x/z data + int i = 0; + for (int z = 1; z <= 16; z += 4) { + for (int x = 1; x <= 16; x += 4) { + int biome = biomeData[(x * z) - 1]; + // Extend it on the y axis + for (int y = 0; y < 1024; y += 16) { + newBiomeData[i + y] = biome; + } + i++; + } + } + + chunk.setBiomeData(newBiomeData); + } + for (int s = 0; s < 16; s++) { ChunkSection section = chunk.getSections()[s]; if (section == null) continue; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java index 780459f55..0de7355fe 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java @@ -31,6 +31,14 @@ public class Chunk1_15Type extends PartialType { boolean groundUp = input.readBoolean(); int primaryBitmask = Type.VAR_INT.read(input); CompoundTag heightMap = Type.NBT.read(input); + + int[] biomeData = groundUp ? new int[1024] : null; + if (groundUp) { + for (int i = 0; i < 1024; i++) { + biomeData[i] = input.readInt(); + } + } + Type.VAR_INT.read(input); BitSet usedSections = new BitSet(16); @@ -42,15 +50,6 @@ public class Chunk1_15Type extends PartialType { } } - int[] biomeData = groundUp ? new int[256] : null; - if (groundUp) { - //TODO Why 1024 ints? - for (int i = 0; i < 1024; i++) { - //biomeData[i] = input.readInt(); - input.readInt(); - } - } - // Read sections for (int i = 0; i < 16; i++) { if (!usedSections.get(i)) continue; // Section not set @@ -84,13 +83,9 @@ public class Chunk1_15Type extends PartialType { // Write biome data if (chunk.isBiomeData()) { - //TODO Why 1024 ints? - for (int i = 0; i < 1024; i++) { - output.writeInt(0); + for (int value : chunk.getBiomeData()) { + output.writeInt(value); } - /*for (int value : chunk.getBiomeData()) { - output.writeInt(value & 0xFF); // This is a temporary workaround, we'll look into fixing this soon :) - }*/ } ByteBuf buf = output.alloc().buffer(); From 68a18df9698ab41bf85d5392e6cc0a8fad2e90f9 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Sat, 7 Dec 2019 11:31:00 +0100 Subject: [PATCH 2/2] Take biome data from same indexes as Mojang ("middle" of 4x4x4 areas) --- .../packets/WorldPackets.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index 285e9d9bb..081ca09d7 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -86,19 +86,19 @@ public class WorldPackets { if (chunk.isGroundUp()) { int[] biomeData = chunk.getBiomeData(); int[] newBiomeData = new int[1024]; - // Now in 4x4x4 areas (x, then z, then y) - // Set the x/z data - int i = 0; - for (int z = 1; z <= 16; z += 4) { - for (int x = 1; x <= 16; x += 4) { - int biome = biomeData[(x * z) - 1]; - // Extend it on the y axis - for (int y = 0; y < 1024; y += 16) { - newBiomeData[i + y] = biome; - } - i++; + // Now in 4x4x4 areas - take the biome of each "middle" + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + int x = (j << 2) + 2; + int z = (i << 2) + 2; + int oldIndex = (z << 4 | x); + newBiomeData[i << 2 | j] = biomeData[oldIndex]; } } + // ... and copy it to the new y layers + for (int i = 1; i < 64; ++i) { + System.arraycopy(newBiomeData, 0, newBiomeData, i * 16, 16); + } chunk.setBiomeData(newBiomeData); }