mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-30 05:53:57 +01:00
Not sure if i'm working forward or backwards on this, but pushing for progress
This commit is contained in:
parent
20bbe7cec6
commit
598d0f96d8
@ -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.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
|
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_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
@ -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.minecraft.chunks.NibbleArray;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChunkSection1_9_1_2 implements ChunkSection {
|
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);
|
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)];
|
int index = blocks[index(x, y, z)];
|
||||||
return palette.indexOf(index) >> 4;
|
return palette.indexOf(index) >> 4;
|
||||||
}
|
}
|
||||||
@ -97,9 +96,9 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
|
|||||||
* Read blocks from input stream.
|
* Read blocks from input stream.
|
||||||
* This reads all the block related data:
|
* This reads all the block related data:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Block length/palette type</li>
|
* <li>Block length/palette type</li>
|
||||||
* <li>Palette</li>
|
* <li>Palette</li>
|
||||||
* <li>Block hashes/palette reference</li>
|
* <li>Block hashes/palette reference</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param input The buffer to read from.
|
* @param input The buffer to read from.
|
||||||
@ -111,34 +110,62 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
|
|||||||
palette.clear();
|
palette.clear();
|
||||||
|
|
||||||
// Reaad bits per block
|
// Reaad bits per block
|
||||||
int bitsPerBlock = input.readByte();
|
int bitsPerBlock = input.readUnsignedByte();
|
||||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
|
||||||
if(bitsPerBlock == 0) {
|
if (bitsPerBlock == 0) {
|
||||||
throw new RuntimeException("Aye me m8 its the global palette!");
|
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
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
int paletteLength = Type.VAR_INT.read(input);
|
if (bitsPerBlock != 13) {
|
||||||
for(int i = 0; i < paletteLength; i++) {
|
palette.add(Type.VAR_INT.read(input));
|
||||||
palette.add(Type.VAR_INT.read(input));
|
} else {
|
||||||
|
Type.VAR_INT.read(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("length of palette: " + paletteLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read blocks
|
// Read blocks
|
||||||
int blockLength = Type.VAR_INT.read(input);
|
int blockLength = Type.VAR_INT.read(input);
|
||||||
long[] blockData = new long[blockLength];
|
if (blockLength > 0) {
|
||||||
for(int i = 0; i < blocks.length; i++) {
|
long[] blockData = new long[blockLength];
|
||||||
int bitIndex = i * bitsPerBlock;
|
System.out.println("Block Length: " + blockData.length);
|
||||||
int startIndex = bitIndex / 64;
|
for (int i = 0; i < blocks.length; i++) {
|
||||||
int endIndex = ((i + 1) * bitsPerBlock - 1) / 64;
|
int bitIndex = i * bitsPerBlock;
|
||||||
int startBitSubIndex = bitIndex % 64;
|
int startIndex = bitIndex / 64;
|
||||||
if(startIndex == endIndex) {
|
int endIndex = ((i + 1) * bitsPerBlock - 1) / 64;
|
||||||
blocks[i] = (int) (blockData[startIndex] >>> startBitSubIndex & maxEntryValue);
|
int startBitSubIndex = bitIndex % 64;
|
||||||
} else {
|
int val;
|
||||||
int endBitSubIndex = 64 - startBitSubIndex;
|
if (startIndex == endIndex) {
|
||||||
blocks[i] = (int) ((blockData[startIndex] >>> startBitSubIndex | blockData[endIndex] << endBitSubIndex) & maxEntryValue);
|
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) {
|
public void readSkyLight(ByteBuf input) {
|
||||||
byte[] handle = new byte[LIGHT_LENGTH];
|
byte[] handle = new byte[LIGHT_LENGTH];
|
||||||
input.readBytes(handle);
|
input.readBytes(handle);
|
||||||
if(skyLight != null) {
|
if (skyLight != null) {
|
||||||
skyLight.setHandle(handle);
|
skyLight.setHandle(handle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,10 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
|
|||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
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_9_3to1_9_1_2.storage.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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
||||||
@Override
|
@Override
|
||||||
@ -81,34 +76,34 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||||
|
|
||||||
Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld);
|
Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld);
|
||||||
if (wrapper.isReadable(type, 0)) {
|
// if (wrapper.isReadable(type, 0)) {
|
||||||
Chunk chunk = wrapper.read(type);
|
Chunk chunk = wrapper.read(type);
|
||||||
// if(rawChunk instanceof Chunk1_9to1_8) {
|
// if(rawChunk instanceof Chunk1_9to1_8) {
|
||||||
// throw new RuntimeException("Sweet berry candies");
|
// throw new RuntimeException("Sweet berry candies");
|
||||||
// }
|
// }
|
||||||
// Chunk1_9_1_2 chunk = (Chunk1_9_1_2) rawChunk;
|
// Chunk1_9_1_2 chunk = (Chunk1_9_1_2) rawChunk;
|
||||||
|
|
||||||
List<CompoundTag> tags = new ArrayList<>();
|
List<CompoundTag> tags = new ArrayList<>();
|
||||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null)
|
if (section == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int x = 0; x < 16; x++)
|
for (int x = 0; x < 16; x++)
|
||||||
for (int y = 0; y < 16; y++)
|
for (int y = 0; y < 16; y++)
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
int block = section.getBlockId(x, y, z);
|
int block = section.getBlockId(x, y, z);
|
||||||
if (FakeTileEntity.hasBlock(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
|
// 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));
|
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]));
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -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 lombok.Getter;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
Loading…
Reference in New Issue
Block a user