Not sure if i'm working forward or backwards on this, but pushing for progress

This commit is contained in:
Myles 2016-07-01 20:17:25 +01:00
parent 20bbe7cec6
commit 598d0f96d8
4 changed files with 73 additions and 52 deletions

View File

@ -8,8 +8,7 @@ import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.sotrage.ClientWorld;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.ArrayList;
import java.util.BitSet;

View File

@ -7,7 +7,6 @@ import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
import us.myles.ViaVersion.api.type.Type;
import java.util.Arrays;
import java.util.List;
public class ChunkSection1_9_1_2 implements ChunkSection {
@ -47,7 +46,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
setBlock(index(x, y, z), type, data);
}
public int getBlockId(int x, int y, int z){
public int getBlockId(int x, int y, int z) {
int index = blocks[index(x, y, z)];
return palette.indexOf(index) >> 4;
}
@ -97,9 +96,9 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
* Read blocks from input stream.
* This reads all the block related data:
* <ul>
* <li>Block length/palette type</li>
* <li>Palette</li>
* <li>Block hashes/palette reference</li>
* <li>Block length/palette type</li>
* <li>Palette</li>
* <li>Block hashes/palette reference</li>
* </ul>
*
* @param input The buffer to read from.
@ -111,34 +110,62 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
palette.clear();
// Reaad bits per block
int bitsPerBlock = input.readByte();
int bitsPerBlock = input.readUnsignedByte();
long maxEntryValue = (1L << bitsPerBlock) - 1;
if(bitsPerBlock == 0) {
throw new RuntimeException("Aye me m8 its the global palette!");
if (bitsPerBlock == 0) {
bitsPerBlock = 13;
}
if (bitsPerBlock < 4) {
bitsPerBlock = 4;
}
if (bitsPerBlock > 8) {
bitsPerBlock = 13;
}
System.out.println("bps: " + bitsPerBlock);
if(bitsPerBlock != 13) {
// Read palette
int paletteLength = Type.VAR_INT.read(input);
// Read palette
int paletteLength = Type.VAR_INT.read(input);
for(int i = 0; i < paletteLength; i++) {
palette.add(Type.VAR_INT.read(input));
for (int i = 0; i < paletteLength; i++) {
if (bitsPerBlock != 13) {
palette.add(Type.VAR_INT.read(input));
} else {
Type.VAR_INT.read(input);
}
}
System.out.println("length of palette: " + paletteLength);
}
// Read blocks
int blockLength = Type.VAR_INT.read(input);
long[] blockData = new long[blockLength];
for(int i = 0; i < blocks.length; i++) {
int bitIndex = i * bitsPerBlock;
int startIndex = bitIndex / 64;
int endIndex = ((i + 1) * bitsPerBlock - 1) / 64;
int startBitSubIndex = bitIndex % 64;
if(startIndex == endIndex) {
blocks[i] = (int) (blockData[startIndex] >>> startBitSubIndex & maxEntryValue);
} else {
int endBitSubIndex = 64 - startBitSubIndex;
blocks[i] = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
if (blockLength > 0) {
long[] blockData = new long[blockLength];
System.out.println("Block Length: " + blockData.length);
for (int i = 0; i < blocks.length; i++) {
int bitIndex = i * bitsPerBlock;
int startIndex = bitIndex / 64;
int endIndex = ((i + 1) * bitsPerBlock - 1) / 64;
int startBitSubIndex = bitIndex % 64;
int val;
if (startIndex == endIndex) {
val = (int) (blockData[startIndex] >>> startBitSubIndex & maxEntryValue);
} else {
int endBitSubIndex = 64 - startBitSubIndex;
val = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
}
if (bitsPerBlock == 13) {
int type = val >> 4;
int data = val & 0xF;
setBlock(i, type, data);
} else {
blocks[i] = val;
}
}
}
System.out.println("done");
}
/**
@ -161,7 +188,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
public void readSkyLight(ByteBuf input) {
byte[] handle = new byte[LIGHT_LENGTH];
input.readBytes(handle);
if(skyLight != null) {
if (skyLight != null) {
skyLight.setHandle(handle);
return;
}

View File

@ -13,15 +13,10 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.sotrage.ClientWorld;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.Chunk1_9to1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.ChunkSection1_9to1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.ChunkType;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Protocol1_9_3TO1_9_1_2 extends Protocol {
@Override
@ -81,34 +76,34 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld);
if (wrapper.isReadable(type, 0)) {
Chunk chunk = wrapper.read(type);
// if (wrapper.isReadable(type, 0)) {
Chunk chunk = wrapper.read(type);
// if(rawChunk instanceof Chunk1_9to1_8) {
// throw new RuntimeException("Sweet berry candies");
// }
// Chunk1_9_1_2 chunk = (Chunk1_9_1_2) rawChunk;
List<CompoundTag> tags = new ArrayList<>();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
List<CompoundTag> tags = new ArrayList<>();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int x = 0; x < 16; x++)
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)) {
// 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));
}
for (int x = 0; x < 16; x++)
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)) {
// 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));
}
}
wrapper.write(type, chunk);
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
}
}
wrapper.write(type, chunk);
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
}
// }
});
}
});

View File

@ -1,4 +1,4 @@
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.sotrage;
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage;
import lombok.Getter;
import org.bukkit.World;