Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Use generic y section count in 1.17 chunk reading
Dieser Commit ist enthalten in:
Ursprung
e56ff898eb
Commit
137680ed9f
@ -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) {
|
public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
|
||||||
return wrapper -> {
|
return wrapper -> {
|
||||||
for (RegistryType type : RegistryType.getValues()) {
|
for (RegistryType type : RegistryType.getValues()) {
|
||||||
|
@ -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);
|
new StatisticsRewriter(this, null).register(ClientboundPackets1_13.STATISTICS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 us.myles.ViaVersion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WorldPackets {
|
public class WorldPackets {
|
||||||
@ -83,7 +82,7 @@ public class WorldPackets {
|
|||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
Chunk chunk = wrapper.read(new Chunk1_16_2Type());
|
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);
|
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
|
||||||
if (chunk.isFullChunk()) {
|
if (chunk.isFullChunk()) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.types;
|
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.types;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
|
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
|
||||||
@ -16,9 +17,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Chunk1_17Type extends Type<Chunk> {
|
public class Chunk1_17Type extends Type<Chunk> {
|
||||||
private static final CompoundTag[] EMPTY_COMPOUNDS = new CompoundTag[0];
|
private static final CompoundTag[] EMPTY_COMPOUNDS = new CompoundTag[0];
|
||||||
|
private final int ySectionCount;
|
||||||
|
|
||||||
public Chunk1_17Type() {
|
public Chunk1_17Type(int ySectionCount) {
|
||||||
super(Chunk.class);
|
super(Chunk.class);
|
||||||
|
Preconditions.checkArgument(ySectionCount > 0);
|
||||||
|
this.ySectionCount = ySectionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -26,7 +30,7 @@ public class Chunk1_17Type extends Type<Chunk> {
|
|||||||
int chunkX = input.readInt();
|
int chunkX = input.readInt();
|
||||||
int chunkZ = 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);
|
CompoundTag heightMap = Type.NBT.read(input);
|
||||||
|
|
||||||
int[] biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.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
|
Type.VAR_INT.readPrimitive(input); // data size in bytes
|
||||||
|
|
||||||
// Read sections
|
// Read sections
|
||||||
ChunkSection[] sections = new ChunkSection[16];
|
ChunkSection[] sections = new ChunkSection[ySectionCount];
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < ySectionCount; i++) {
|
||||||
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
|
if ((sectionsMask & (1 << i)) == 0) continue; // Section not set
|
||||||
|
|
||||||
short nonAirBlocksCount = input.readShort();
|
short nonAirBlocksCount = input.readShort();
|
||||||
ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
|
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
|
@Override
|
||||||
@ -70,8 +74,8 @@ public class Chunk1_17Type extends Type<Chunk> {
|
|||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < 16; i++) {
|
ChunkSection[] sections = chunk.getSections();
|
||||||
ChunkSection section = chunk.getSections()[i];
|
for (ChunkSection section : sections) {
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
|
|
||||||
buf.writeShort(section.getNonAirBlocksCount());
|
buf.writeShort(section.getNonAirBlocksCount());
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren