mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-06-23 13:14:43 +02:00
Start work on 1.9.2 chunk stuff, no where near done bit stuck on detecting skylight.
This commit is contained in:
parent
808a9a7d82
commit
b3060e0dc8
|
@ -15,7 +15,10 @@ public class Chunk1_9_1_2 implements Chunk {
|
|||
private boolean groundUp;
|
||||
private int bitmask;
|
||||
private final ChunkSection1_9_1_2[] sections;
|
||||
private final byte[] biomeData;
|
||||
private byte[] biomeData;
|
||||
List<CompoundTag> blockEntities;
|
||||
|
||||
public boolean isBiomeData() {
|
||||
return biomeData != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.ChunkSection1_9to1_8;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
public class Chunk1_9_1_2Type extends BaseChunkType {
|
||||
public Chunk1_9_1_2Type() {
|
||||
|
@ -24,56 +25,71 @@ public class Chunk1_9_1_2Type extends BaseChunkType {
|
|||
int primaryBitmask = Type.VAR_INT.read(input);
|
||||
int size = Type.VAR_INT.read(input);
|
||||
|
||||
// byte[] sections = new byte[size];
|
||||
// input.readBytes(sections);
|
||||
|
||||
BitSet usedSections = new BitSet(16);
|
||||
ChunkSection1_9_1_2[] sections = new ChunkSection1_9_1_2[16];
|
||||
byte[] biomeData = null;
|
||||
|
||||
// Calculate section count from bitmask
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((primaryBitmask & (1 << i)) != 0) {
|
||||
usedSections.set(i);
|
||||
}
|
||||
}
|
||||
int sectionCount = usedSections.cardinality(); // the amount of sections set
|
||||
|
||||
// Read sections
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (!usedSections.get(i)) continue; // Section not set
|
||||
ChunkSection1_9_1_2 section = new ChunkSection1_9_1_2();
|
||||
sections[i] = section;
|
||||
|
||||
short bitsPerBlock = input.readUnsignedByte();
|
||||
Integer[] palette = Type.VAR_INT_ARRAY.read(input); // 0 if none
|
||||
// Read blocks
|
||||
Long[] data = Type.LONG_ARRAY.read(input);
|
||||
|
||||
// WIP.
|
||||
// section.readBlocks(input);
|
||||
// section.readBlockLight(input);
|
||||
// section.readSkyLight(input);
|
||||
/*
|
||||
BlockStorage blocks = new BlockStorage(in);
|
||||
NibbleArray3d blocklight = new NibbleArray3d(in, 2048); (1024 bytes)
|
||||
NibbleArray3d skylight = hasSkylight ? new NibbleArray3d(in, 2048) : null; (1024 bytes)
|
||||
chunks[index] = new Chunk(blocks, blocklight, skylight);
|
||||
*/
|
||||
}
|
||||
byte[] biomeData = groundUp ? new byte[256] : null;
|
||||
if (groundUp)
|
||||
input.readBytes(biomeData);
|
||||
|
||||
int blockEntities = Type.VAR_INT.read(input);
|
||||
List<CompoundTag> nbtData = new ArrayList<>();
|
||||
for (int i = 0; i < blockEntities; i++) {
|
||||
nbtData.add(Type.NBT.read(input));
|
||||
}
|
||||
return new Chunk1_9_1_2(chunkX, chunkZ, groundUp, primaryBitmask, sections, new byte[0], nbtData);
|
||||
return new Chunk1_9_1_2(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, new ArrayList<CompoundTag>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Chunk input) throws Exception {
|
||||
public void write(ByteBuf output, Chunk input) throws Exception {
|
||||
if (!(input instanceof Chunk1_9_1_2))
|
||||
throw new Exception("Tried to send the wrong chunk type from 1.9.3-4 chunk: " + input.getClass());
|
||||
Chunk1_9_1_2 chunk = (Chunk1_9_1_2) input;
|
||||
|
||||
buffer.writeInt(chunk.getX());
|
||||
buffer.writeInt(chunk.getZ());
|
||||
output.writeInt(chunk.getX());
|
||||
output.writeInt(chunk.getZ());
|
||||
|
||||
buffer.writeBoolean(chunk.isGroundUp());
|
||||
Type.VAR_INT.write(buffer, chunk.getBitmask());
|
||||
output.writeBoolean(chunk.isGroundUp());
|
||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||
|
||||
Type.VAR_INT.write(buffer, chunk.getSections().length);
|
||||
// buffer.writeBytes(chunk.getSections());
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection1_9_1_2 section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
section.writeBlocks(buf);
|
||||
section.writeBlockLight(buf);
|
||||
|
||||
// no block entities as it's earlier
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
buf.release(); // release buffer
|
||||
|
||||
// Write biome data
|
||||
if (chunk.isBiomeData()) {
|
||||
output.writeBytes(chunk.getBiomeData());
|
||||
}
|
||||
|
||||
// Type.NBT_ARRAY.write(output, tags.toArray(new CompoundTag[0])); Written by the handler
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wrapper.write(type, chunk);
|
||||
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue
Block a user