Just store whether to read skylight directly

This commit is contained in:
Nassim Jahnke 2023-10-20 17:09:40 +10:00
parent 54c04a62e0
commit 6481cec270
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
4 changed files with 40 additions and 36 deletions

View File

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.Environment;
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.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import io.netty.buffer.ByteBuf;
@ -37,13 +36,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
public class ChunkType1_13 extends PartialType<Chunk, Environment> {
public class ChunkType1_13 extends Type<Chunk> {
private static final ChunkType1_13 WITH_SKYLIGHT = new ChunkType1_13(Environment.NORMAL);
private static final ChunkType1_13 WITHOUT_SKYLIGHT = new ChunkType1_13(Environment.NETHER);
private static final ChunkType1_13 WITH_SKYLIGHT = new ChunkType1_13(true);
private static final ChunkType1_13 WITHOUT_SKYLIGHT = new ChunkType1_13(false);
private final boolean hasSkyLight;
public ChunkType1_13(Environment environment) {
super(environment, Chunk.class);
public ChunkType1_13(boolean hasSkyLight) {
super(Chunk.class);
this.hasSkyLight = hasSkyLight;
}
public static ChunkType1_13 forEnvironment(Environment environment) {
@ -51,7 +52,7 @@ public class ChunkType1_13 extends PartialType<Chunk, Environment> {
}
@Override
public Chunk read(ByteBuf input, Environment environment) throws Exception {
public Chunk read(ByteBuf input) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
@ -67,7 +68,7 @@ public class ChunkType1_13 extends PartialType<Chunk, Environment> {
ChunkSection section = Types1_13.CHUNK_SECTION.read(data);
sections[i] = section;
section.getLight().readBlockLight(data);
if (environment == Environment.NORMAL) {
if (hasSkyLight) {
section.getLight().readSkyLight(data);
}
}
@ -97,7 +98,7 @@ public class ChunkType1_13 extends PartialType<Chunk, Environment> {
}
@Override
public void write(ByteBuf output, Environment environment, Chunk chunk) throws Exception {
public void write(ByteBuf output, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());

View File

@ -26,20 +26,21 @@ import com.viaversion.viaversion.api.minecraft.Environment;
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.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_8;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
public class ChunkType1_8 extends PartialType<Chunk, Environment> {
public class ChunkType1_8 extends Type<Chunk> {
private static final ChunkType1_8 WITH_SKYLIGHT = new ChunkType1_8(Environment.NORMAL);
private static final ChunkType1_8 WITHOUT_SKYLIGHT = new ChunkType1_8(Environment.NETHER);
private static final ChunkType1_8 WITH_SKYLIGHT = new ChunkType1_8(true);
private static final ChunkType1_8 WITHOUT_SKYLIGHT = new ChunkType1_8(false);
private final boolean hasSkyLight;
public ChunkType1_8(Environment environment) {
super(environment, Chunk.class);
public ChunkType1_8(boolean hasSkyLight) {
super(Chunk.class);
this.hasSkyLight = hasSkyLight;
}
public static ChunkType1_8 forEnvironment(Environment environment) {
@ -47,7 +48,7 @@ public class ChunkType1_8 extends PartialType<Chunk, Environment> {
}
@Override
public Chunk read(ByteBuf input, Environment environment) throws Exception {
public Chunk read(ByteBuf input) throws Exception {
final int chunkX = input.readInt();
final int chunkZ = input.readInt();
final boolean fullChunk = input.readBoolean();
@ -61,11 +62,11 @@ public class ChunkType1_8 extends PartialType<Chunk, Environment> {
return new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>());
}
return deserialize(chunkX, chunkZ, fullChunk, environment == Environment.NORMAL, bitmask, data);
return deserialize(chunkX, chunkZ, fullChunk, hasSkyLight, bitmask, data);
}
@Override
public void write(ByteBuf output, Environment environment, Chunk chunk) throws Exception {
public void write(ByteBuf output, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());

View File

@ -26,20 +26,21 @@ import com.viaversion.viaversion.api.minecraft.Environment;
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.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.BitSet;
public class ChunkType1_9_1 extends PartialType<Chunk, Environment> {
public class ChunkType1_9_1 extends Type<Chunk> {
private static final ChunkType1_9_1 WITH_SKYLIGHT = new ChunkType1_9_1(Environment.NORMAL);
private static final ChunkType1_9_1 WITHOUT_SKYLIGHT = new ChunkType1_9_1(Environment.NETHER);
private static final ChunkType1_9_1 WITH_SKYLIGHT = new ChunkType1_9_1(true);
private static final ChunkType1_9_1 WITHOUT_SKYLIGHT = new ChunkType1_9_1(false);
private final boolean hasSkyLight;
public ChunkType1_9_1(Environment environment) {
super(environment, Chunk.class);
public ChunkType1_9_1(boolean hasSkyLight) {
super(Chunk.class);
this.hasSkyLight = hasSkyLight;
}
public static ChunkType1_9_1 forEnvironment(Environment environment) {
@ -47,7 +48,7 @@ public class ChunkType1_9_1 extends PartialType<Chunk, Environment> {
}
@Override
public Chunk read(ByteBuf input, Environment environment) throws Exception {
public Chunk read(ByteBuf input) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
@ -71,7 +72,7 @@ public class ChunkType1_9_1 extends PartialType<Chunk, Environment> {
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
sections[i] = section;
section.getLight().readBlockLight(input);
if (environment == Environment.NORMAL) {
if (hasSkyLight) {
section.getLight().readSkyLight(input);
}
}
@ -87,7 +88,7 @@ public class ChunkType1_9_1 extends PartialType<Chunk, Environment> {
}
@Override
public void write(ByteBuf output, Environment environment, Chunk chunk) throws Exception {
public void write(ByteBuf output, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());

View File

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.Environment;
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.type.PartialType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import io.netty.buffer.ByteBuf;
@ -36,13 +35,15 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ChunkType1_9_3 extends PartialType<Chunk, Environment> {
public class ChunkType1_9_3 extends Type<Chunk> {
private static final ChunkType1_9_3 WITH_SKYLIGHT = new ChunkType1_9_3(Environment.NORMAL);
private static final ChunkType1_9_3 WITHOUT_SKYLIGHT = new ChunkType1_9_3(Environment.NETHER);
private static final ChunkType1_9_3 WITH_SKYLIGHT = new ChunkType1_9_3(true);
private static final ChunkType1_9_3 WITHOUT_SKYLIGHT = new ChunkType1_9_3(false);
private final boolean hasSkyLight;
public ChunkType1_9_3(Environment environment) {
super(environment, Chunk.class);
public ChunkType1_9_3(boolean hasSkyLight) {
super(Chunk.class);
this.hasSkyLight = hasSkyLight;
}
public static ChunkType1_9_3 forEnvironment(Environment environment) {
@ -50,7 +51,7 @@ public class ChunkType1_9_3 extends PartialType<Chunk, Environment> {
}
@Override
public Chunk read(ByteBuf input, Environment environment) throws Exception {
public Chunk read(ByteBuf input) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
@ -66,7 +67,7 @@ public class ChunkType1_9_3 extends PartialType<Chunk, Environment> {
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
sections[i] = section;
section.getLight().readBlockLight(input);
if (environment == Environment.NORMAL) {
if (hasSkyLight) {
section.getLight().readSkyLight(input);
}
}
@ -92,7 +93,7 @@ public class ChunkType1_9_3 extends PartialType<Chunk, Environment> {
}
@Override
public void write(ByteBuf output, Environment environment, Chunk chunk) throws Exception {
public void write(ByteBuf output, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());