Implemented sodium fix for classic worlds

This commit is contained in:
RaphiMC 2024-03-24 11:50:53 +01:00
parent a55de5e5a3
commit 0a8e70e5dd
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
2 changed files with 23 additions and 12 deletions

View File

@ -23,6 +23,7 @@ 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.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 class ClassicLevelStorage extends StoredObject {
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 class ClassicLevelStorage extends StoredObject {
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 {

View File

@ -23,7 +23,9 @@ import com.viaversion.viaversion.api.connection.ProtocolInfo;
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.CompoundTag;
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.metadata.Me
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 class Protocol1_3_1_2to1_2_4_5 extends StatelessProtocol<ClientboundPacke
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);
}
}