From b743589d77b165190d8ad416e6a68f9f1cddc2d2 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 22 Jun 2016 19:22:38 +0100 Subject: [PATCH] This works but lags, only for 1.8 server. --- .../protocol1_9_3to1_9_1_2/Chunk1_9_1_2.java | 3 +- .../Chunk1_9_1_2Type.java | 33 ++++++++++++++++--- .../FakeTileEntity.java | 2 +- .../chunks/ChunkSection1_9to1_8.java | 2 +- .../protocol1_9to1_8/types/ChunkType.java | 7 ++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2.java index dc9171f4e..3bce5e8b9 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2.java @@ -14,7 +14,8 @@ public class Chunk1_9_1_2 implements Chunk { private int z; private boolean groundUp; private int bitmask; - private byte[] sections; + private final ChunkSection1_9_1_2[] sections; + private final byte[] biomeData; List blockEntities; } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2Type.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2Type.java index a14a1e260..2981cb145 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2Type.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Chunk1_9_1_2Type.java @@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType; import java.util.ArrayList; +import java.util.BitSet; import java.util.List; public class Chunk1_9_1_2Type extends BaseChunkType { @@ -23,15 +24,39 @@ 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); +// 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); + + } int blockEntities = Type.VAR_INT.read(input); List 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, nbtData); + return new Chunk1_9_1_2(chunkX, chunkZ, groundUp, primaryBitmask, sections, new byte[0], nbtData); } @Override @@ -47,7 +72,7 @@ public class Chunk1_9_1_2Type extends BaseChunkType { Type.VAR_INT.write(buffer, chunk.getBitmask()); Type.VAR_INT.write(buffer, chunk.getSections().length); - buffer.writeBytes(chunk.getSections()); +// buffer.writeBytes(chunk.getSections()); // no block entities as it's earlier } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/FakeTileEntity.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/FakeTileEntity.java index a3823fe79..7e58ffb98 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/FakeTileEntity.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/FakeTileEntity.java @@ -104,7 +104,7 @@ public class FakeTileEntity { tag.put(new IntTag("x", x)); tag.put(new IntTag("y", y)); tag.put(new IntTag("z", z)); - System.out.println("Found tile entity " + block + " at position " + x + " " + y + " " + z); +// System.out.println("Found tile entity " + block + " at position " + x + " " + y + " " + z); return tag; } return null; diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java index cc7921d04..7825bb2fb 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java @@ -47,7 +47,7 @@ public class ChunkSection1_9to1_8 { public int getBlockId(int x, int y, int z){ int index = blocks[index(x, y, z)]; - return palette.indexOf(index) >> 4; + return palette.get(index) >> 4; } /** diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java index fc08862be..c5b6c0d4e 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java @@ -97,6 +97,7 @@ public class ChunkType extends PartialType { int mask = blockBuf.get(); int type = mask >> 4; int data = mask & 0xF; + section.setBlock(j, type, data); } } @@ -161,8 +162,10 @@ public class ChunkType extends PartialType { for (int y = 0; y < 16; y++) for (int z = 0; z < 16; z++) { int block = section.getBlockId(x, y, z); - if (FakeTileEntity.hasBlock(block)) - tags.add(FakeTileEntity.getFromBlock(x * chunk.getX(), y, z * chunk.getZ(), block)); + if (FakeTileEntity.hasBlock(block)) { + // NOT SURE WHY Y AND Z WORK THIS WAY, TODO: WORK OUT WHY THIS IS OR FIX W/E BROKE IT + tags.add(FakeTileEntity.getFromBlock(x + (chunk.getX() << 4), z + (i << 4), y + (chunk.getZ() << 4), block)); + } } if (!section.hasSkyLight()) continue; // No sky light, we're done here.