From 270df05f20211e3dc63ec265fdff7ba987a40819 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sun, 6 Aug 2023 17:09:09 +0200 Subject: [PATCH] Fixed sky light being treated as biome data in 1.2.x --- .../Protocolb1_2_0_2tob1_1_2.java | 3 +-- .../Protocolb1_8_0_1tob1_7_0_3.java | 5 ++-- .../storage/ClassicLevelStorage.java | 5 ++-- .../Protocol1_2_1_3to1_1.java | 25 ++++++------------- .../types/Chunk1_1Type.java | 21 ++++++---------- .../protocol1_2_1_3to1_1/types/Types1_1.java | 2 ++ .../Protocol1_3_1_2to1_2_4_5.java | 16 ++++++++---- .../types/Chunk1_2_4Type.java | 23 +++++++++++++++-- .../types/Types1_2_4.java | 3 +++ 9 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_2_0_2tob1_1_2/Protocolb1_2_0_2tob1_1_2.java b/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_2_0_2tob1_1_2/Protocolb1_2_0_2tob1_1_2.java index a79649a..aa23f41 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_2_0_2tob1_1_2/Protocolb1_2_0_2tob1_1_2.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_2_0_2tob1_1_2/Protocolb1_2_0_2tob1_1_2.java @@ -35,7 +35,6 @@ import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.Clientbou import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.ServerboundPacketsb1_2; import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types.MetaTypeb1_2; import net.raphimc.vialegacy.protocols.beta.protocolb1_3_0_1tob1_2_0_2.types.Typesb1_2; -import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Chunk1_1Type; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Types1_1; import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1; import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2; @@ -139,7 +138,7 @@ public class Protocolb1_2_0_2tob1_1_2 extends AbstractProtocol { final ClientWorld clientWorld = new ClientWorld(wrapper.user()); clientWorld.setEnvironment(0); - BLOCK_DATA_REWRITER.remapChunk(wrapper.passthrough(new Chunk1_1Type(clientWorld))); + BLOCK_DATA_REWRITER.remapChunk(wrapper.passthrough(Types1_1.CHUNK)); }); } }); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_8_0_1tob1_7_0_3/Protocolb1_8_0_1tob1_7_0_3.java b/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_8_0_1tob1_7_0_3/Protocolb1_8_0_1tob1_7_0_3.java index b106b2a..b0994a2 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_8_0_1tob1_7_0_3/Protocolb1_8_0_1tob1_7_0_3.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/beta/protocolb1_8_0_1tob1_7_0_3/Protocolb1_8_0_1tob1_7_0_3.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import net.raphimc.vialegacy.api.data.BlockList1_6; import net.raphimc.vialegacy.api.data.ItemList1_6; import net.raphimc.vialegacy.api.splitter.PreNettySplitter; @@ -42,7 +41,7 @@ import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typ import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_0_20a_27.Protocolc0_30toc0_27; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.chunks.NibbleArray1_1; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.storage.SeedStorage; -import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Chunk1_1Type; +import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Types1_1; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.storage.EntityTracker; import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1; import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2; @@ -189,7 +188,7 @@ public class Protocolb1_8_0_1tob1_7_0_3 extends AbstractProtocol { - final Chunk chunk = wrapper.passthrough(new Chunk1_1Type(wrapper.user().get(ClientWorld.class))); + final Chunk chunk = wrapper.passthrough(Types1_1.CHUNK); boolean hasChest = false; for (ChunkSection section : chunk.getSections()) { diff --git a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocola1_0_15toc0_28_30/storage/ClassicLevelStorage.java b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocola1_0_15toc0_28_30/storage/ClassicLevelStorage.java index 0a31ddd..608b830 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocola1_0_15toc0_28_30/storage/ClassicLevelStorage.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocola1_0_15toc0_28_30/storage/ClassicLevelStorage.java @@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.*; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.util.MathUtil; import net.raphimc.vialegacy.ViaLegacy; import net.raphimc.vialegacy.api.model.ChunkCoord; @@ -33,7 +32,7 @@ import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.Protoco import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.model.ClassicLevel; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.chunks.NibbleArray1_1; -import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Chunk1_1Type; +import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Types1_1; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -158,7 +157,7 @@ public class ClassicLevelStorage extends StoredObject { final Chunk viaChunk = new BaseChunk(coord.chunkX, coord.chunkZ, true, false, this.sectionBitmask, modernSections, new int[256], new ArrayList<>()); final PacketWrapper chunkData = PacketWrapper.create(ClientboundPacketsa1_0_15.CHUNK_DATA, this.getUser()); - chunkData.write(new Chunk1_1Type(this.getUser().get(ClientWorld.class)), viaChunk); + chunkData.write(Types1_1.CHUNK, viaChunk); chunkData.send(Protocola1_0_15toc0_30.class); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java index 1f6c96c..e700acc 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java @@ -30,7 +30,6 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import net.raphimc.vialegacy.ViaLegacy; import net.raphimc.vialegacy.api.model.IdAndData; import net.raphimc.vialegacy.api.remapper.LegacyItemRewriter; @@ -49,11 +48,10 @@ import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.storage.Dime import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.storage.PendingBlocksTracker; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.storage.SeedStorage; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.tasks.BlockReceiveInvalidatorTask; -import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Chunk1_1Type; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Types1_1; import net.raphimc.vialegacy.protocols.release.protocol1_2_4_5to1_2_1_3.ClientboundPackets1_2_1; import net.raphimc.vialegacy.protocols.release.protocol1_2_4_5to1_2_1_3.ServerboundPackets1_2_1; -import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types.Chunk1_2_4Type; +import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types.Types1_2_4; import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.types.Types1_3_1; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Types1_6_4; @@ -151,11 +149,10 @@ public class Protocol1_2_1_3to1_1 extends AbstractProtocol { - final ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); final ChunkTracker chunkTracker = wrapper.user().get(ChunkTracker.class); final SeedStorage seedStorage = wrapper.user().get(SeedStorage.class); final PendingBlocksTracker pendingBlocksTracker = wrapper.user().get(PendingBlocksTracker.class); - Chunk chunk = wrapper.read(new Chunk1_1Type(clientWorld)); + final Chunk chunk = wrapper.read(Types1_1.CHUNK); if (chunk instanceof NonFullChunk1_1) { if (!chunkTracker.isChunkLoaded(chunk.getX(), chunk.getZ())) { // Cancel because update in unloaded area is ignored by mc @@ -191,23 +188,19 @@ public class Protocol1_2_1_3to1_1 extends AbstractProtocol { +public class Chunk1_1Type extends Type { - public Chunk1_1Type(ClientWorld clientWorld) { - super(clientWorld, Chunk.class); + public Chunk1_1Type() { + super(Chunk.class); } @Override @@ -47,7 +44,7 @@ public class Chunk1_1Type extends PartialType { } @Override - public Chunk read(ByteBuf byteBuf, ClientWorld clientWorld) throws Exception { + public Chunk read(ByteBuf byteBuf) throws Exception { final int xPosition = byteBuf.readInt(); final int yPosition = byteBuf.readShort(); final int zPosition = byteBuf.readInt(); @@ -67,15 +64,15 @@ public class Chunk1_1Type extends PartialType { inflater.end(); } - return deserialize(xPosition, yPosition, zPosition, xSize, ySize, zSize, clientWorld.getEnvironment() == Environment.NORMAL, uncompressedData); + return deserialize(xPosition, yPosition, zPosition, xSize, ySize, zSize, uncompressedData); } @Override - public void write(ByteBuf byteBuf, ClientWorld clientWorld, Chunk chunk) throws Exception { + public void write(ByteBuf byteBuf, Chunk chunk) throws Exception { throw new UnsupportedOperationException(); } - public static Chunk deserialize(final int xPosition, final int yPosition, final int zPosition, final int xSize, final int ySize, final int zSize, final boolean skyLight, final byte[] chunkData) { + public static Chunk deserialize(final int xPosition, final int yPosition, final int zPosition, final int xSize, final int ySize, final int zSize, final byte[] chunkData) { final int chunkX = xPosition >> 4; final int chunkZ = zPosition >> 4; final int endChunkX = xPosition + xSize - 1 >> 4; @@ -165,9 +162,7 @@ public class Chunk1_1Type extends PartialType { } section.getLight().setBlockLight(sectionBlockLight.getHandle()); - if (skyLight) { - section.getLight().setSkyLight(sectionSkyLight.getHandle()); - } + section.getLight().setSkyLight(sectionSkyLight.getHandle()); } if (fullChunk) { diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/Types1_1.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/Types1_1.java index e61f36f..737fa7e 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/Types1_1.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/Types1_1.java @@ -18,10 +18,12 @@ package net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; +import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.type.Type; public class Types1_1 { public static Type BLOCK_CHANGE_RECORD_ARRAY = new BlockChangeRecordArrayType(); + public static Type CHUNK = new Chunk1_1Type(); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java index a2292a1..c249bfc 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java @@ -56,7 +56,6 @@ import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.storage. import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.storage.DimensionTracker; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.storage.EntityTracker; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.task.EntityTrackerTickTask; -import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types.Chunk1_2_4Type; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types.Types1_2_4; import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.ClientboundPackets1_3_1; import net.raphimc.vialegacy.protocols.release.protocol1_4_2to1_3_1_2.ServerboundPackets1_3_1; @@ -450,7 +449,7 @@ public class Protocol1_3_1_2to1_2_4_5 extends AbstractProtocol { final ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.read(new Chunk1_2_4Type(clientWorld)); + Chunk chunk = wrapper.read(Types1_2_4.CHUNK); wrapper.user().get(ChestStateTracker.class).unload(chunk.getX(), chunk.getZ()); @@ -458,16 +457,23 @@ public class Protocol1_3_1_2to1_2_4_5 extends AbstractProtocol()); for (int i = 0; i < chunk.getSections().length; i++) { - final ChunkSection chunkSection = chunk.getSections()[i] = new ChunkSectionImpl(true); - chunkSection.palette(PaletteType.BLOCKS).addId(0); + final ChunkSection section = chunk.getSections()[i] = new ChunkSectionImpl(true); + section.palette(PaletteType.BLOCKS).addId(0); if (clientWorld.getEnvironment() == Environment.NORMAL) { final byte[] skyLight = new byte[2048]; Arrays.fill(skyLight, (byte) 255); - chunkSection.getLight().setSkyLight(skyLight); + section.getLight().setSkyLight(skyLight); } } } + if (clientWorld.getEnvironment() != Environment.NORMAL) { + for (ChunkSection section : chunk.getSections()) { + if (section != null) { + section.getLight().setSkyLight(null); + } + } + } wrapper.write(new Chunk1_7_6Type(clientWorld), chunk); }); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Chunk1_2_4Type.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Chunk1_2_4Type.java index cee55ba..6f8dddb 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Chunk1_2_4Type.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Chunk1_2_4Type.java @@ -17,15 +17,23 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types; +import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; +import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import io.netty.buffer.ByteBuf; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Chunk1_7_6Type; public class Chunk1_2_4Type extends Chunk1_7_6Type { - public Chunk1_2_4Type(ClientWorld clientWorld) { - super(clientWorld); + private static final ClientWorld OVERWORLD = new ClientWorld(null); + + static { + OVERWORLD.setEnvironment(Environment.NORMAL.id()); + } + + public Chunk1_2_4Type() { + super(OVERWORLD); } @Override @@ -38,4 +46,15 @@ public class Chunk1_2_4Type extends Chunk1_7_6Type { byteBuf.writeInt(0); } + @Override + public void write(ByteBuf byteBuf, ClientWorld clientWorld, Chunk chunk) throws Exception { + for (ChunkSection section : chunk.getSections()) { + if (section != null && !section.getLight().hasSkyLight()) { + throw new IllegalStateException("Chunk section does not have skylight"); + } + } + + super.write(byteBuf, clientWorld, chunk); + } + } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java index 1ab2f0a..7623d22 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java @@ -17,6 +17,7 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.types; +import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ItemArrayType; @@ -29,4 +30,6 @@ public class Types1_2_4 { public static final Type ITEM_ARRAY = new ItemArrayType<>(ITEM); public static final Type COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType<>(COMPRESSED_NBT_ITEM); + public static final Type CHUNK = new Chunk1_2_4Type(); + }