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 2d832b3..0de8a82 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,6 +23,7 @@ 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.util.ChunkUtil; import net.raphimc.vialegacy.ViaLegacy; import net.raphimc.vialegacy.api.model.ChunkCoord; import net.raphimc.vialegacy.api.util.ChunkCoordSpiral; @@ -69,7 +70,7 @@ public void addDataPart(final byte[] part, final int partSize) { this.netBuffer.write(part, 0, partSize); } - public void finish(final int sizeX, final int sizeY, final int sizeZ) { + public void finish(final int sizeX, final int sizeY, final int sizeZ) throws Exception { try { final DataInputStream dis = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(this.netBuffer.toByteArray()), 64 * 1024)); final byte[] blocks = new byte[dis.readInt()]; @@ -95,6 +96,20 @@ public void finish(final int sizeX, final int sizeY, final int sizeZ) { this.subChunkZLength = Math.min(16, sizeZ); this.sectionBitmask = 0; for (int i = 0; i < this.sectionYCount; i++) this.sectionBitmask = (this.sectionBitmask << 1) | 1; + + { // Sodium fix (Sodium requires a ring of empty chunks around the loaded chunks) + for (int chunkX = -1; chunkX <= this.chunkXCount; chunkX++) { + for (int chunkZ = -1; chunkZ <= this.chunkZCount; chunkZ++) { + if (chunkX < 0 || chunkX >= this.chunkXCount || chunkZ < 0 || chunkZ >= this.chunkZCount) { + final Chunk chunk = ChunkUtil.createEmptyChunk(chunkX, chunkZ, Math.max(8, this.sectionYCount), this.sectionBitmask); + ChunkUtil.setDummySkylight(chunk, true); + final PacketWrapper chunkData = PacketWrapper.create(ClientboundPacketsa1_0_15.CHUNK_DATA, this.getUser()); + chunkData.write(Types1_1.CHUNK, chunk); + chunkData.send(Protocola1_0_15toc0_30.class); + } + } + } + } } public void tick() throws Exception { 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 d88b339..01c332f 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 @@ -23,7 +23,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.Position; -import com.viaversion.viaversion.api.minecraft.chunks.*; +import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; +import com.viaversion.viaversion.api.minecraft.chunks.Chunk; +import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; @@ -36,6 +38,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.util.ChunkUtil; import net.raphimc.vialegacy.ViaLegacy; import net.raphimc.vialegacy.api.data.BlockList1_6; import net.raphimc.vialegacy.api.model.IdAndData; @@ -68,7 +71,6 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.logging.Level; @@ -454,15 +456,9 @@ public void register() { if (chunk.isFullChunk() && chunk.getBitmask() == 0) { // Remap to empty chunk ViaLegacy.getPlatform().getLogger().warning("Received empty 1.2.5 chunk packet"); - chunk = new BaseChunk(chunk.getX(), chunk.getZ(), true, false, 65535, new ChunkSection[16], new int[256], new ArrayList<>()); - for (int i = 0; i < chunk.getSections().length; i++) { - final ChunkSection section = chunk.getSections()[i] = new ChunkSectionImpl(true); - section.palette(PaletteType.BLOCKS).addId(0); - if (dimension == Environment.NORMAL) { - final byte[] skyLight = new byte[2048]; - Arrays.fill(skyLight, (byte) 255); - section.getLight().setSkyLight(skyLight); - } + chunk = ChunkUtil.createEmptyChunk(chunk.getX(), chunk.getZ()); + if (dimension == Environment.NORMAL) { + ChunkUtil.setDummySkylight(chunk, true); } }