3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-08 22:02:50 +02:00

Use generic y section count in 1.17 chunk reading

Dieser Commit ist enthalten in:
KennyTV 2020-12-03 11:53:05 +01:00
Ursprung e56ff898eb
Commit 137680ed9f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 14 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -64,15 +64,6 @@ public class TagRewriter {
});
}
/**
* Registers the handler, reading and processing until and including the entity tags.
*
* @param packetType packet type
*/
public void register(ClientboundPacketType packetType) {
register(packetType, RegistryType.ENTITY);
}
public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
return wrapper -> {
for (RegistryType type : RegistryType.getValues()) {

Datei anzeigen

@ -124,7 +124,7 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
}
});
new TagRewriter(this, null).register(ClientboundPackets1_13.TAGS, RegistryType.BLOCK);
new TagRewriter(this, null).register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
new StatisticsRewriter(this, null).register(ClientboundPackets1_13.STATISTICS);
}

Datei anzeigen

@ -21,7 +21,6 @@ import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.EntityTracker1
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
public class WorldPackets {
@ -83,7 +82,7 @@ public class WorldPackets {
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16_2Type());
wrapper.write(new Chunk1_17Type(), chunk);
wrapper.write(new Chunk1_17Type(16), chunk);
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
if (chunk.isFullChunk()) {

Datei anzeigen

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
@ -16,9 +17,12 @@ import java.util.List;
public class Chunk1_17Type extends Type<Chunk> {
private static final CompoundTag[] EMPTY_COMPOUNDS = new CompoundTag[0];
private final int ySectionCount;
public Chunk1_17Type() {
public Chunk1_17Type(int ySectionCount) {
super(Chunk.class);
Preconditions.checkArgument(ySectionCount > 0);
this.ySectionCount = ySectionCount;
}
@Override
@ -26,7 +30,7 @@ public class Chunk1_17Type extends Type<Chunk> {
int chunkX = input.readInt();
int chunkZ = input.readInt();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
int sectionsMask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
int[] biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input);
@ -34,9 +38,9 @@ public class Chunk1_17Type extends Type<Chunk> {
Type.VAR_INT.readPrimitive(input); // data size in bytes
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
ChunkSection[] sections = new ChunkSection[ySectionCount];
for (int i = 0; i < ySectionCount; i++) {
if ((sectionsMask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
@ -54,7 +58,7 @@ public class Chunk1_17Type extends Type<Chunk> {
}
}
return new BaseChunk(chunkX, chunkZ, true, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
return new BaseChunk(chunkX, chunkZ, true, false, sectionsMask, sections, biomeData, heightMap, nbtData);
}
@Override
@ -70,8 +74,8 @@ public class Chunk1_17Type extends Type<Chunk> {
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
ChunkSection[] sections = chunk.getSections();
for (ChunkSection section : sections) {
if (section == null) continue; // Section not set
buf.writeShort(section.getNonAirBlocksCount());