Fixed sky light being treated as biome data in 1.2.x

This commit is contained in:
RaphiMC 2023-08-06 17:09:09 +02:00
parent 4f688893d1
commit 270df05f20
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
9 changed files with 57 additions and 46 deletions

View File

@ -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<ClientboundPacket
handler(wrapper -> {
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));
});
}
});

View File

@ -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<ClientboundPack
@Override
public void register() {
handler(wrapper -> {
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()) {

View File

@ -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);
}

View File

@ -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<ClientboundPackets1_1
@Override
public void register() {
handler(wrapper -> {
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<ClientboundPackets1_1
if (section == null) continue;
final NibbleArray1_1 oldBlockLight = new NibbleArray1_1(section.getLight().getBlockLight(), 4);
final NibbleArray newBlockLight = new NibbleArray(oldBlockLight.size());
NibbleArray1_1 oldSkyLight = null;
NibbleArray newSkyLight = null;
if (section.getLight().hasSkyLight()) {
oldSkyLight = new NibbleArray1_1(section.getLight().getSkyLight(), 4);
newSkyLight = new NibbleArray(oldSkyLight.size());
}
final NibbleArray1_1 oldSkyLight = new NibbleArray1_1(section.getLight().getSkyLight(), 4);
final NibbleArray newSkyLight = new NibbleArray(oldSkyLight.size());
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
newBlockLight.set(x, y, z, oldBlockLight.get(x, y, z));
if (oldSkyLight != null) newSkyLight.set(x, y, z, oldSkyLight.get(x, y, z));
newSkyLight.set(x, y, z, oldSkyLight.get(x, y, z));
}
}
}
section.getLight().setBlockLight(newBlockLight.getHandle());
if (newSkyLight != null) section.getLight().setSkyLight(newSkyLight.getHandle());
section.getLight().setSkyLight(newSkyLight.getHandle());
}
if (chunk.getSections().length < 16) { // Increase available sections to match new world height
@ -216,7 +209,7 @@ public class Protocol1_2_1_3to1_1 extends AbstractProtocol<ClientboundPackets1_1
chunk.setSections(newArray);
}
wrapper.write(new Chunk1_2_4Type(clientWorld), chunk);
wrapper.write(Types1_2_4.CHUNK, chunk);
});
}
});
@ -328,7 +321,6 @@ public class Protocol1_2_1_3to1_1 extends AbstractProtocol<ClientboundPackets1_1
}
private void handleRespawn(final int dimensionId, final UserConnection user) {
user.get(ClientWorld.class).setEnvironment(dimensionId);
if (user.get(DimensionTracker.class).getDimensionId() != dimensionId) {
user.get(DimensionTracker.class).setDimension(dimensionId);
user.get(PendingBlocksTracker.class).clear();
@ -377,9 +369,6 @@ public class Protocol1_2_1_3to1_1 extends AbstractProtocol<ClientboundPackets1_1
userConnection.put(new SeedStorage(userConnection));
userConnection.put(new PendingBlocksTracker(userConnection));
userConnection.put(new DimensionTracker(userConnection));
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
}
}
@Override

View File

@ -17,14 +17,11 @@
*/
package net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types;
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.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.CustomByteType;
import com.viaversion.viaversion.api.type.types.minecraft.BaseChunkType;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import io.netty.buffer.ByteBuf;
import net.raphimc.vialegacy.api.model.IdAndData;
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.chunks.NibbleArray1_1;
@ -35,10 +32,10 @@ import java.util.ArrayList;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
public class Chunk1_1Type extends PartialType<Chunk, ClientWorld> {
public class Chunk1_1Type extends Type<Chunk> {
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<Chunk, ClientWorld> {
}
@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<Chunk, ClientWorld> {
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<Chunk, ClientWorld> {
}
section.getLight().setBlockLight(sectionBlockLight.getHandle());
if (skyLight) {
section.getLight().setSkyLight(sectionSkyLight.getHandle());
}
section.getLight().setSkyLight(sectionSkyLight.getHandle());
}
if (fullChunk) {

View File

@ -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<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new BlockChangeRecordArrayType();
public static Type<Chunk> CHUNK = new Chunk1_1Type();
}

View File

@ -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<ClientboundPacket
public void register() {
handler(wrapper -> {
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<ClientboundPacket
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 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);
});
}

View File

@ -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);
}
}

View File

@ -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[]> ITEM_ARRAY = new ItemArrayType<>(ITEM);
public static final Type<Item[]> COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType<>(COMPRESSED_NBT_ITEM);
public static final Type<Chunk> CHUNK = new Chunk1_2_4Type();
}