This works but lags, only for 1.8 server.

This commit is contained in:
Myles 2016-06-22 19:22:38 +01:00
parent 9dad0a0d5e
commit b743589d77
5 changed files with 38 additions and 9 deletions

View File

@ -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<CompoundTag> blockEntities;
}

View File

@ -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<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, 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
}

View File

@ -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;

View File

@ -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;
}
/**

View File

@ -97,6 +97,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
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<Chunk, ClientChunks> {
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.