Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Merge branch 'chunk_section_rewrite' into 1.14
# Conflicts: # common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java # common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/chunks/ChunkSection1_13.java # common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/types/Chunk1_14Type.java # common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/ChunkSection1_9_3_4.java # common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/ChunkSection1_9_1_2.java # common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java
Dieser Commit ist enthalten in:
Commit
928cd9de94
@ -0,0 +1,24 @@
|
|||||||
|
package us.myles.ViaVersion.api.minecraft.chunks;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class BaseChunk implements Chunk {
|
||||||
|
protected int x;
|
||||||
|
protected int z;
|
||||||
|
protected boolean groundUp;
|
||||||
|
protected int bitmask;
|
||||||
|
protected ChunkSection[] sections;
|
||||||
|
protected byte[] biomeData;
|
||||||
|
protected List<CompoundTag> blockEntities;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBiomeData() {
|
||||||
|
return biomeData != null;
|
||||||
|
}
|
||||||
|
}
|
@ -9,15 +9,15 @@ public interface Chunk {
|
|||||||
|
|
||||||
int getZ();
|
int getZ();
|
||||||
|
|
||||||
ChunkSection[] getSections();
|
|
||||||
|
|
||||||
boolean isGroundUp();
|
|
||||||
|
|
||||||
boolean isBiomeData();
|
boolean isBiomeData();
|
||||||
|
|
||||||
byte[] getBiomeData();
|
|
||||||
|
|
||||||
int getBitmask();
|
int getBitmask();
|
||||||
|
|
||||||
|
ChunkSection[] getSections();
|
||||||
|
|
||||||
|
byte[] getBiomeData();
|
||||||
|
|
||||||
List<CompoundTag> getBlockEntities();
|
List<CompoundTag> getBlockEntities();
|
||||||
|
|
||||||
|
boolean isGroundUp();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package us.myles.ViaVersion.api.minecraft.chunks;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Chunk1_8 extends BaseChunk {
|
||||||
|
@Getter
|
||||||
|
private boolean unloadPacket = false;
|
||||||
|
|
||||||
|
public Chunk1_8(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, byte[] biomeData, List<CompoundTag> blockEntities) {
|
||||||
|
super(x, z, groundUp, bitmask, sections, biomeData, blockEntities);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chunk unload.
|
||||||
|
*
|
||||||
|
* @param x coord
|
||||||
|
* @param z coord
|
||||||
|
*/
|
||||||
|
public Chunk1_8(int x, int z) {
|
||||||
|
this(x, z, true, 0, new ChunkSection[16], null, new ArrayList<CompoundTag>());
|
||||||
|
this.unloadPacket = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this chunks have biome data
|
||||||
|
*
|
||||||
|
* @return True if the chunks has biome data
|
||||||
|
*/
|
||||||
|
public boolean hasBiomeData() {
|
||||||
|
return biomeData != null && groundUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBiomeData() {
|
||||||
|
return biomeData != null;
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,29 @@
|
|||||||
package us.myles.ViaVersion.api.minecraft.chunks;
|
package us.myles.ViaVersion.api.minecraft.chunks;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ChunkSection {
|
public class ChunkSection {
|
||||||
/**
|
/**
|
||||||
* Gets a block state id (< 1.13: block_id << 4 | data & 0xF)
|
* Size (dimensions) of blocks in a chunks section.
|
||||||
*
|
|
||||||
* @param x Block X
|
|
||||||
* @param y Block Y
|
|
||||||
* @param z Block Z
|
|
||||||
* @return Block raw id
|
|
||||||
*/
|
*/
|
||||||
int getBlock(int x, int y, int z);
|
public static final int SIZE = 16 * 16 * 16; // width * depth * height
|
||||||
|
/**
|
||||||
|
* Length of the sky and block light nibble arrays.
|
||||||
|
*/
|
||||||
|
public static final int LIGHT_LENGTH = 16 * 16 * 16 / 2; // size * size * size / 2 (nibble bit count)
|
||||||
|
private final List<Integer> palette = Lists.newArrayList();
|
||||||
|
private final int[] blocks;
|
||||||
|
private NibbleArray blockLight;
|
||||||
|
private NibbleArray skyLight;
|
||||||
|
|
||||||
|
public ChunkSection() {
|
||||||
|
this.blocks = new int[SIZE];
|
||||||
|
this.blockLight = new NibbleArray(SIZE);
|
||||||
|
palette.add(0); // AIR
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a block in the chunks
|
* Set a block in the chunks
|
||||||
@ -22,63 +32,158 @@ public interface ChunkSection {
|
|||||||
* @param x Block X
|
* @param x Block X
|
||||||
* @param y Block Y
|
* @param y Block Y
|
||||||
* @param z Block Z
|
* @param z Block Z
|
||||||
* @param type The block id
|
* @param type The type of the block
|
||||||
* @param data The data value of the block
|
* @param data The data value of the block
|
||||||
*/
|
*/
|
||||||
void setBlock(int x, int y, int z, int type, int data);
|
public void setBlock(int x, int y, int z, int type, int data) {
|
||||||
|
setFlatBlock(index(x, y, z), type << 4 | (data & 0xF));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlatBlock(int x, int y, int z, int type) {
|
||||||
|
setFlatBlock(index(x, y, z), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockId(int x, int y, int z) {
|
||||||
|
return getFlatBlock(x, y, z) >> 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlockData(int x, int y, int z) {
|
||||||
|
return getFlatBlock(x, y, z) & 0xF;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFlatBlock(int x, int y, int z) {
|
||||||
|
int index = blocks[index(x, y, z)];
|
||||||
|
return palette.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFlatBlock(int idx) {
|
||||||
|
int index = blocks[idx];
|
||||||
|
return palette.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlock(int idx, int type, int data) {
|
||||||
|
setFlatBlock(idx, type << 4 | (data & 0xF));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaletteIndex(int idx, int index) {
|
||||||
|
blocks[idx] = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPaletteIndex(int idx) {
|
||||||
|
return blocks[idx];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a block state in the chunk
|
* Set a block state in the chunk
|
||||||
* This method will not update non-air blocks count
|
* This method will not update non-air blocks count
|
||||||
*
|
*
|
||||||
* @param x Block X
|
* @param idx Index
|
||||||
* @param y Block Y
|
* @param id The raw or flat id of the block
|
||||||
* @param z Block Z
|
|
||||||
* @param blockState The block state id
|
|
||||||
*/
|
*/
|
||||||
void setFlatBlock(int x, int y, int z, int blockState);
|
public void setFlatBlock(int idx, int id) {
|
||||||
|
int index = palette.indexOf(id);
|
||||||
|
if (index == -1) {
|
||||||
|
index = palette.size();
|
||||||
|
palette.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks[idx] = index;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a block id (without data)
|
* Set the block light array
|
||||||
* /!\ YOU SHOULD NOT USE THIS ON 1.13
|
|
||||||
*
|
*
|
||||||
* @param x Block X
|
* @param data The value to set the block light to
|
||||||
* @param y Block Y
|
|
||||||
* @param z Block Z
|
|
||||||
* @return Block id (without data)
|
|
||||||
*/
|
*/
|
||||||
int getBlockId(int x, int y, int z);
|
public void setBlockLight(byte[] data) {
|
||||||
|
if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH);
|
||||||
|
if (this.blockLight == null) {
|
||||||
|
this.blockLight = new NibbleArray(data);
|
||||||
|
} else {
|
||||||
|
this.blockLight.setHandle(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the blocks in < 1.13 format to a buffer.
|
* Set the sky light array
|
||||||
*
|
*
|
||||||
* @param output The buffer to write to.
|
* @param data The value to set the sky light to
|
||||||
* @throws Exception Throws if it failed to write.
|
|
||||||
*/
|
*/
|
||||||
void writeBlocks(ByteBuf output) throws Exception;
|
public void setSkyLight(byte[] data) {
|
||||||
|
if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH);
|
||||||
|
if (this.skyLight == null) {
|
||||||
|
this.skyLight = new NibbleArray(data);
|
||||||
|
} else {
|
||||||
|
this.skyLight.setHandle(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getBlockLight() {
|
||||||
|
return blockLight == null ? null : blockLight.getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getSkyLight() {
|
||||||
|
return skyLight == null ? null : skyLight.getHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readBlockLight(ByteBuf input) {
|
||||||
|
if (this.blockLight == null) {
|
||||||
|
this.blockLight = new NibbleArray(LIGHT_LENGTH * 2);
|
||||||
|
}
|
||||||
|
input.readBytes(this.blockLight.getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readSkyLight(ByteBuf input) {
|
||||||
|
if (this.skyLight == null) {
|
||||||
|
this.skyLight = new NibbleArray(LIGHT_LENGTH * 2);
|
||||||
|
}
|
||||||
|
input.readBytes(this.skyLight.getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int index(int x, int y, int z) {
|
||||||
|
return y << 8 | z << 4 | x;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the blocks in 1.13 format to a buffer.
|
* Write the block light to a buffer
|
||||||
*
|
*
|
||||||
* @param output The buffer to write to.
|
* @param output The buffer to write to
|
||||||
* @throws Exception Throws if it failed to write.
|
|
||||||
*/
|
*/
|
||||||
void writeBlocks1_13(ByteBuf output) throws Exception;
|
public void writeBlockLight(ByteBuf output) {
|
||||||
|
output.writeBytes(blockLight.getHandle());
|
||||||
void writeBlockLight(ByteBuf output) throws Exception;
|
}
|
||||||
|
|
||||||
boolean hasSkyLight();
|
|
||||||
|
|
||||||
void writeSkyLight(ByteBuf output) throws Exception;
|
|
||||||
|
|
||||||
List<Integer> getPalette();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the non-air(air, cave_air, void_air) blocks count
|
* Write the sky light to a buffer
|
||||||
*
|
*
|
||||||
* @return number or non-air blocks
|
* @param output The buffer to write to
|
||||||
*/
|
*/
|
||||||
int getNonAirBlocksCount();
|
public void writeSkyLight(ByteBuf output) {
|
||||||
|
output.writeBytes(skyLight.getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
void setNonAirBlocksCount(int count);
|
public List<Integer> getPalette() {
|
||||||
|
return palette;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if sky light is present
|
||||||
|
*
|
||||||
|
* @return True if skylight is present
|
||||||
|
*/
|
||||||
|
public boolean hasSkyLight() {
|
||||||
|
return skyLight != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasBlockLight() {
|
||||||
|
return blockLight != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNonAirBlocksCount() {
|
||||||
|
return this.nonAirBlocksCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNonAirBlocksCount(int nonAirBlocksCount) {
|
||||||
|
this.nonAirBlocksCount = nonAirBlocksCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChunkSectionType1_13 extends Type<ChunkSection> {
|
||||||
|
|
||||||
|
public ChunkSectionType1_13() {
|
||||||
|
super("Chunk Section Type", ChunkSection.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSection read(ByteBuf buffer) throws Exception {
|
||||||
|
ChunkSection chunkSection = new ChunkSection();
|
||||||
|
List<Integer> palette = chunkSection.getPalette();
|
||||||
|
palette.clear();
|
||||||
|
|
||||||
|
// Reaad bits per block
|
||||||
|
int bitsPerBlock = buffer.readUnsignedByte();
|
||||||
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
|
||||||
|
if (bitsPerBlock == 0) {
|
||||||
|
bitsPerBlock = 14;
|
||||||
|
}
|
||||||
|
if (bitsPerBlock < 4) {
|
||||||
|
bitsPerBlock = 4;
|
||||||
|
}
|
||||||
|
if (bitsPerBlock > 8) {
|
||||||
|
bitsPerBlock = 14;
|
||||||
|
}
|
||||||
|
int paletteLength = bitsPerBlock == 14 ? 0 : Type.VAR_INT.read(buffer);
|
||||||
|
// Read palette
|
||||||
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
|
palette.add(Type.VAR_INT.read(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read blocks
|
||||||
|
long[] blockData = new long[Type.VAR_INT.read(buffer)];
|
||||||
|
if (blockData.length > 0) {
|
||||||
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
|
blockData[i] = buffer.readLong();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < ChunkSection.SIZE; 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 == 14) {
|
||||||
|
chunkSection.setFlatBlock(i, val);
|
||||||
|
} else {
|
||||||
|
chunkSection.setPaletteIndex(i, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunkSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
|
||||||
|
List<Integer> palette = chunkSection.getPalette();
|
||||||
|
|
||||||
|
int bitsPerBlock = 4;
|
||||||
|
while (palette.size() > 1 << bitsPerBlock) {
|
||||||
|
bitsPerBlock += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bitsPerBlock > 8) {
|
||||||
|
bitsPerBlock = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
buffer.writeByte(bitsPerBlock);
|
||||||
|
|
||||||
|
|
||||||
|
// Write pallet (or not)
|
||||||
|
if (bitsPerBlock != 14) {
|
||||||
|
Type.VAR_INT.write(buffer, palette.size());
|
||||||
|
for (int mappedId : palette) {
|
||||||
|
Type.VAR_INT.write(buffer, mappedId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||||
|
Type.VAR_INT.write(buffer, length);
|
||||||
|
long[] data = new long[length];
|
||||||
|
for (int index = 0; index < ChunkSection.SIZE; index++) {
|
||||||
|
int value = bitsPerBlock == 14 ? chunkSection.getFlatBlock(index) : chunkSection.getPaletteIndex(index);
|
||||||
|
int bitIndex = index * bitsPerBlock;
|
||||||
|
int startIndex = bitIndex / 64;
|
||||||
|
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
||||||
|
int startBitSubIndex = bitIndex % 64;
|
||||||
|
data[startIndex] = data[startIndex] & ~(maxEntryValue << startBitSubIndex) | ((long) value & maxEntryValue) << startBitSubIndex;
|
||||||
|
if (startIndex != endIndex) {
|
||||||
|
int endBitSubIndex = 64 - startBitSubIndex;
|
||||||
|
data[endIndex] = data[endIndex] >>> endBitSubIndex << endBitSubIndex | ((long) value & maxEntryValue) >> endBitSubIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (long l : data) {
|
||||||
|
buffer.writeLong(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.ShortBuffer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChunkSectionType1_8 extends Type<ChunkSection> {
|
||||||
|
|
||||||
|
public ChunkSectionType1_8() {
|
||||||
|
super("Chunk Section Type", ChunkSection.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSection read(ByteBuf buffer) throws Exception {
|
||||||
|
ChunkSection chunkSection = new ChunkSection();
|
||||||
|
List<Integer> palette = chunkSection.getPalette();
|
||||||
|
palette.clear();
|
||||||
|
|
||||||
|
byte[] blockData = new byte[ChunkSection.SIZE * 2];
|
||||||
|
buffer.readBytes(blockData);
|
||||||
|
ShortBuffer blockBuf = ByteBuffer.wrap(blockData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
||||||
|
|
||||||
|
for (int i = 0; i < ChunkSection.SIZE; i++) {
|
||||||
|
int mask = blockBuf.get();
|
||||||
|
int type = mask >> 4;
|
||||||
|
int data = mask & 0xF;
|
||||||
|
chunkSection.setBlock(i, type, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunkSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChunkSectionType1_9 extends Type<ChunkSection> {
|
||||||
|
|
||||||
|
public ChunkSectionType1_9() {
|
||||||
|
super("Chunk Section Type", ChunkSection.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkSection read(ByteBuf buffer) throws Exception {
|
||||||
|
ChunkSection chunkSection = new ChunkSection();
|
||||||
|
List<Integer> palette = chunkSection.getPalette();
|
||||||
|
palette.clear();
|
||||||
|
|
||||||
|
// Reaad bits per block
|
||||||
|
int bitsPerBlock = buffer.readUnsignedByte();
|
||||||
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
|
||||||
|
if (bitsPerBlock == 0) {
|
||||||
|
bitsPerBlock = 13;
|
||||||
|
}
|
||||||
|
if (bitsPerBlock < 4) {
|
||||||
|
bitsPerBlock = 4;
|
||||||
|
}
|
||||||
|
if (bitsPerBlock > 8) {
|
||||||
|
bitsPerBlock = 13;
|
||||||
|
}
|
||||||
|
int paletteLength = Type.VAR_INT.read(buffer);
|
||||||
|
// Read palette
|
||||||
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
|
if (bitsPerBlock != 13) {
|
||||||
|
palette.add(Type.VAR_INT.read(buffer));
|
||||||
|
} else {
|
||||||
|
Type.VAR_INT.read(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read blocks
|
||||||
|
long[] blockData = new long[Type.VAR_INT.read(buffer)];
|
||||||
|
if (blockData.length > 0) {
|
||||||
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
|
blockData[i] = buffer.readLong();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < ChunkSection.SIZE; 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) {
|
||||||
|
chunkSection.setBlock(i, val >> 4, val & 0xF);
|
||||||
|
} else {
|
||||||
|
chunkSection.setPaletteIndex(i, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunkSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
|
||||||
|
List<Integer> palette = chunkSection.getPalette();
|
||||||
|
|
||||||
|
int bitsPerBlock = 4;
|
||||||
|
while (palette.size() > 1 << bitsPerBlock) {
|
||||||
|
bitsPerBlock += 1;
|
||||||
|
}
|
||||||
|
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||||
|
buffer.writeByte(bitsPerBlock);
|
||||||
|
|
||||||
|
// Write pallet
|
||||||
|
Type.VAR_INT.write(buffer, palette.size());
|
||||||
|
for (int mappedId : palette) {
|
||||||
|
Type.VAR_INT.write(buffer, mappedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
|
||||||
|
Type.VAR_INT.write(buffer, length);
|
||||||
|
long[] data = new long[length];
|
||||||
|
for (int index = 0; index < ChunkSection.SIZE; index++) {
|
||||||
|
int value = chunkSection.getPaletteIndex(index);
|
||||||
|
int bitIndex = index * bitsPerBlock;
|
||||||
|
int startIndex = bitIndex / 64;
|
||||||
|
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
||||||
|
int startBitSubIndex = bitIndex % 64;
|
||||||
|
data[startIndex] = data[startIndex] & ~(maxEntryValue << startBitSubIndex) | ((long) value & maxEntryValue) << startBitSubIndex;
|
||||||
|
if (startIndex != endIndex) {
|
||||||
|
int endBitSubIndex = 64 - startBitSubIndex;
|
||||||
|
data[endIndex] = data[endIndex] >>> endBitSubIndex << endBitSubIndex | ((long) value & maxEntryValue) >> endBitSubIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (long l : data) {
|
||||||
|
buffer.writeLong(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package us.myles.ViaVersion.api.type.types.version;
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
@ -15,4 +16,6 @@ public class Types1_13 {
|
|||||||
* Metadata type for 1.13
|
* Metadata type for 1.13
|
||||||
*/
|
*/
|
||||||
public static final Type<Metadata> METADATA = new Metadata1_13Type();
|
public static final Type<Metadata> METADATA = new Metadata1_13Type();
|
||||||
|
|
||||||
|
public static final Type<ChunkSection> CHUNK_SECTION = new ChunkSectionType1_13();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package us.myles.ViaVersion.api.type.types.version;
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
@ -15,4 +16,6 @@ public class Types1_8 {
|
|||||||
* Metadata type for 1.8
|
* Metadata type for 1.8
|
||||||
*/
|
*/
|
||||||
public static final Type<Metadata> METADATA = new Metadata1_8Type();
|
public static final Type<Metadata> METADATA = new Metadata1_8Type();
|
||||||
|
|
||||||
|
public static final Type<ChunkSection> CHUNK_SECTION = new ChunkSectionType1_8();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package us.myles.ViaVersion.api.type.types.version;
|
package us.myles.ViaVersion.api.type.types.version;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
@ -15,4 +16,6 @@ public class Types1_9 {
|
|||||||
* Metadata type for 1.9
|
* Metadata type for 1.9
|
||||||
*/
|
*/
|
||||||
public static final Type<Metadata> METADATA = new Metadata1_9Type();
|
public static final Type<Metadata> METADATA = new Metadata1_9Type();
|
||||||
|
|
||||||
|
public static final Type<ChunkSection> CHUNK_SECTION = new ChunkSectionType1_9();
|
||||||
}
|
}
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks;
|
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Chunk1_13 implements Chunk {
|
|
||||||
private int x;
|
|
||||||
private int z;
|
|
||||||
private boolean groundUp;
|
|
||||||
private int bitmask;
|
|
||||||
private ChunkSection1_13[] sections;
|
|
||||||
private byte[] biomeData;
|
|
||||||
private List<CompoundTag> blockEntities;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBiomeData() {
|
|
||||||
return biomeData != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -254,7 +254,7 @@ public class WorldPackets {
|
|||||||
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.getBlock(x, y, z);
|
int block = section.getFlatBlock(x, y, z);
|
||||||
if (storage.isWelcome(block)) {
|
if (storage.isWelcome(block)) {
|
||||||
storage.store(new Position(
|
storage.store(new Position(
|
||||||
(long) (x + (chunk.getX() << 4)),
|
(long) (x + (chunk.getX() << 4)),
|
||||||
|
@ -4,13 +4,13 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.Environment;
|
import us.myles.ViaVersion.api.minecraft.Environment;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
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.PartialType;
|
import us.myles.ViaVersion.api.type.PartialType;
|
||||||
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_13to1_12_2.chunks.Chunk1_13;
|
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.ChunkSection1_13;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -33,7 +33,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.VAR_INT.read(input);
|
Type.VAR_INT.read(input);
|
||||||
|
|
||||||
BitSet usedSections = new BitSet(16);
|
BitSet usedSections = new BitSet(16);
|
||||||
ChunkSection1_13[] sections = new ChunkSection1_13[16];
|
ChunkSection[] sections = new ChunkSection[16];
|
||||||
// Calculate section count from bitmask
|
// Calculate section count from bitmask
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if ((primaryBitmask & (1 << i)) != 0) {
|
if ((primaryBitmask & (1 << i)) != 0) {
|
||||||
@ -44,9 +44,8 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
// Read sections
|
// Read sections
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set
|
if (!usedSections.get(i)) continue; // Section not set
|
||||||
ChunkSection1_13 section = new ChunkSection1_13();
|
ChunkSection section = Types1_13.CHUNK_SECTION.read(input);
|
||||||
sections[i] = section;
|
sections[i] = section;
|
||||||
section.readBlocks(input);
|
|
||||||
section.readBlockLight(input);
|
section.readBlockLight(input);
|
||||||
if (world.getEnvironment() == Environment.NORMAL) {
|
if (world.getEnvironment() == Environment.NORMAL) {
|
||||||
section.readSkyLight(input);
|
section.readSkyLight(input);
|
||||||
@ -71,7 +70,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Chunk1_13(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,7 +85,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
section.writeBlocks1_13(buf);
|
Types1_13.CHUNK_SECTION.write(buf, section);
|
||||||
section.writeBlockLight(buf);
|
section.writeBlockLight(buf);
|
||||||
|
|
||||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||||
|
@ -3,13 +3,13 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
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.PartialType;
|
import us.myles.ViaVersion.api.type.PartialType;
|
||||||
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_13to1_12_2.chunks.Chunk1_13;
|
import us.myles.ViaVersion.api.type.types.version.Types1_13;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.chunks.ChunkSection1_13;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -33,7 +33,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.VAR_INT.read(input);
|
Type.VAR_INT.read(input);
|
||||||
|
|
||||||
BitSet usedSections = new BitSet(16);
|
BitSet usedSections = new BitSet(16);
|
||||||
ChunkSection1_13[] sections = new ChunkSection1_13[16];
|
ChunkSection[] sections = new ChunkSection[16];
|
||||||
// Calculate section count from bitmask
|
// Calculate section count from bitmask
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if ((primaryBitmask & (1 << i)) != 0) {
|
if ((primaryBitmask & (1 << i)) != 0) {
|
||||||
@ -44,10 +44,10 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
// Read sections
|
// Read sections
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set
|
if (!usedSections.get(i)) continue; // Section not set
|
||||||
ChunkSection1_13 section = new ChunkSection1_13();
|
short nonAirBlocksCount = input.readShort();
|
||||||
|
ChunkSection section = Types1_13.CHUNK_SECTION.read(input);
|
||||||
|
section.setNonAirBlocksCount(nonAirBlocksCount);
|
||||||
sections[i] = section;
|
sections[i] = section;
|
||||||
section.setNonAirBlocksCount(input.readShort());
|
|
||||||
section.readBlocks(input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] biomeData = groundUp ? new byte[256] : null;
|
byte[] biomeData = groundUp ? new byte[256] : null;
|
||||||
@ -67,7 +67,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Chunk1_13(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,8 +82,8 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
buf.writeShort(section.getNonAirBlocksCount()); //TODO find out what this short does (number of air blocks, important?)
|
buf.writeShort(section.getNonAirBlocksCount());
|
||||||
section.writeBlocks1_13(buf);
|
Types1_13.CHUNK_SECTION.write(buf, section);
|
||||||
}
|
}
|
||||||
buf.readerIndex(0);
|
buf.readerIndex(0);
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks;
|
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Chunk1_9_3_4 implements Chunk {
|
|
||||||
private int x;
|
|
||||||
private int z;
|
|
||||||
private boolean groundUp;
|
|
||||||
private int bitmask;
|
|
||||||
private ChunkSection1_9_3_4[] sections;
|
|
||||||
private byte[] biomeData;
|
|
||||||
private List<CompoundTag> blockEntities;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBiomeData() {
|
|
||||||
return biomeData != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,13 +4,13 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.Environment;
|
import us.myles.ViaVersion.api.minecraft.Environment;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
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.PartialType;
|
import us.myles.ViaVersion.api.type.PartialType;
|
||||||
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_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.ChunkSection1_9_3_4;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -34,7 +34,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
Type.VAR_INT.read(input);
|
Type.VAR_INT.read(input);
|
||||||
|
|
||||||
BitSet usedSections = new BitSet(16);
|
BitSet usedSections = new BitSet(16);
|
||||||
ChunkSection1_9_3_4[] sections = new ChunkSection1_9_3_4[16];
|
ChunkSection[] sections = new ChunkSection[16];
|
||||||
// Calculate section count from bitmask
|
// Calculate section count from bitmask
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if ((primaryBitmask & (1 << i)) != 0) {
|
if ((primaryBitmask & (1 << i)) != 0) {
|
||||||
@ -45,9 +45,8 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
// Read sections
|
// Read sections
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set
|
if (!usedSections.get(i)) continue; // Section not set
|
||||||
ChunkSection1_9_3_4 section = new ChunkSection1_9_3_4();
|
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
|
||||||
sections[i] = section;
|
sections[i] = section;
|
||||||
section.readBlocks(input);
|
|
||||||
section.readBlockLight(input);
|
section.readBlockLight(input);
|
||||||
if (world.getEnvironment() == Environment.NORMAL) {
|
if (world.getEnvironment() == Environment.NORMAL) {
|
||||||
section.readSkyLight(input);
|
section.readSkyLight(input);
|
||||||
@ -69,7 +68,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Chunk1_9_3_4(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,7 +83,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
section.writeBlocks(buf);
|
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||||
section.writeBlockLight(buf);
|
section.writeBlockLight(buf);
|
||||||
|
|
||||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks;
|
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Chunk1_9_1_2 implements Chunk {
|
|
||||||
private int x;
|
|
||||||
private int z;
|
|
||||||
private boolean groundUp;
|
|
||||||
private int bitmask;
|
|
||||||
private final ChunkSection1_9_1_2[] sections;
|
|
||||||
private byte[] biomeData;
|
|
||||||
private List<CompoundTag> blockEntities;
|
|
||||||
|
|
||||||
public boolean isBiomeData() {
|
|
||||||
return biomeData != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,15 +4,15 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.Environment;
|
import us.myles.ViaVersion.api.minecraft.Environment;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
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.PartialType;
|
import us.myles.ViaVersion.api.type.PartialType;
|
||||||
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.api.type.types.version.Types1_9;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks.Chunk1_9_1_2;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks.ChunkSection1_9_1_2;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -37,7 +37,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
int size = Type.VAR_INT.read(input);
|
int size = Type.VAR_INT.read(input);
|
||||||
|
|
||||||
BitSet usedSections = new BitSet(16);
|
BitSet usedSections = new BitSet(16);
|
||||||
ChunkSection1_9_1_2[] sections = new ChunkSection1_9_1_2[16];
|
ChunkSection[] sections = new ChunkSection[16];
|
||||||
// Calculate section count from bitmask
|
// Calculate section count from bitmask
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if ((primaryBitmask & (1 << i)) != 0) {
|
if ((primaryBitmask & (1 << i)) != 0) {
|
||||||
@ -48,9 +48,8 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
// Read sections
|
// Read sections
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set
|
if (!usedSections.get(i)) continue; // Section not set
|
||||||
ChunkSection1_9_1_2 section = new ChunkSection1_9_1_2();
|
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
|
||||||
sections[i] = section;
|
sections[i] = section;
|
||||||
section.readBlocks(input);
|
|
||||||
section.readBlockLight(input);
|
section.readBlockLight(input);
|
||||||
if (world.getEnvironment() == Environment.NORMAL) {
|
if (world.getEnvironment() == Environment.NORMAL) {
|
||||||
section.readSkyLight(input);
|
section.readSkyLight(input);
|
||||||
@ -67,7 +66,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
input.readBytes(biomeData);
|
input.readBytes(biomeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Chunk1_9_1_2(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, new ArrayList<CompoundTag>());
|
return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, new ArrayList<CompoundTag>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,7 +81,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ChunkSection section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
section.writeBlocks(buf);
|
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||||
section.writeBlockLight(buf);
|
section.writeBlockLight(buf);
|
||||||
|
|
||||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks;
|
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.ToString;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Getter
|
|
||||||
@ToString
|
|
||||||
public class Chunk1_9to1_8 implements Chunk {
|
|
||||||
private final int x;
|
|
||||||
private final int z;
|
|
||||||
private final boolean groundUp;
|
|
||||||
private final int primaryBitmask;
|
|
||||||
private final ChunkSection1_9to1_8[] sections;
|
|
||||||
private final byte[] biomeData;
|
|
||||||
private final List<CompoundTag> blockEntities;
|
|
||||||
private boolean unloadPacket = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chunk unload.
|
|
||||||
*
|
|
||||||
* @param x coord
|
|
||||||
* @param z coord
|
|
||||||
*/
|
|
||||||
public Chunk1_9to1_8(int x, int z) {
|
|
||||||
this(x, z, true, 0, new ChunkSection1_9to1_8[16], null,
|
|
||||||
new ArrayList<CompoundTag>());
|
|
||||||
this.unloadPacket = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this chunks have biome data
|
|
||||||
*
|
|
||||||
* @return True if the chunks has biome data
|
|
||||||
*/
|
|
||||||
public boolean hasBiomeData() {
|
|
||||||
return biomeData != null && groundUp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBiomeData() {
|
|
||||||
return biomeData != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBitmask() {
|
|
||||||
return primaryBitmask;
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,7 +16,7 @@ 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_9to1_8.ItemRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.Chunk1_9to1_8;
|
import us.myles.ViaVersion.api.minecraft.chunks.Chunk1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
||||||
@ -24,7 +24,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.PlaceBlockTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.PlaceBlockTracker;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.ChunkType;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Chunk1_9to1_8Type;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -121,7 +121,7 @@ public class WorldPackets {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
|
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
|
||||||
Chunk1_9to1_8 chunk = (Chunk1_9to1_8) wrapper.passthrough(new ChunkType(clientChunks));
|
Chunk1_8 chunk = (Chunk1_8) wrapper.passthrough(new Chunk1_9to1_8Type(clientChunks));
|
||||||
if (chunk.isUnloadPacket()) {
|
if (chunk.isUnloadPacket()) {
|
||||||
wrapper.setId(0x1D);
|
wrapper.setId(0x1D);
|
||||||
|
|
||||||
|
@ -4,23 +4,22 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||||
import us.myles.ViaVersion.api.type.PartialType;
|
import us.myles.ViaVersion.api.type.PartialType;
|
||||||
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.api.type.types.version.Types1_8;
|
||||||
|
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
|
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.Chunk1_9to1_8;
|
import us.myles.ViaVersion.api.minecraft.chunks.Chunk1_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.storage.ClientChunks;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.nio.ShortBuffer;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
|
||||||
/**
|
/**
|
||||||
* Amount of sections in a chunks.
|
* Amount of sections in a chunks.
|
||||||
*/
|
*/
|
||||||
@ -34,7 +33,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
*/
|
*/
|
||||||
private static final int BIOME_DATA_LENGTH = 256;
|
private static final int BIOME_DATA_LENGTH = 256;
|
||||||
|
|
||||||
public ChunkType(ClientChunks chunks) {
|
public Chunk1_9to1_8Type(ClientChunks chunks) {
|
||||||
super(chunks, Chunk.class);
|
super(chunks, Chunk.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
|
|
||||||
// Data to be read
|
// Data to be read
|
||||||
BitSet usedSections = new BitSet(16);
|
BitSet usedSections = new BitSet(16);
|
||||||
ChunkSection1_9to1_8[] sections = new ChunkSection1_9to1_8[16];
|
ChunkSection[] sections = new ChunkSection[16];
|
||||||
byte[] biomeData = null;
|
byte[] biomeData = null;
|
||||||
|
|
||||||
// Calculate section count from bitmask
|
// Calculate section count from bitmask
|
||||||
@ -78,7 +77,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
if (sectionCount == 0 && groundUp && !isBulkPacket && param.getLoadedChunks().contains(chunkHash)) {
|
if (sectionCount == 0 && groundUp && !isBulkPacket && param.getLoadedChunks().contains(chunkHash)) {
|
||||||
// This is a chunks unload packet
|
// This is a chunks unload packet
|
||||||
param.getLoadedChunks().remove(chunkHash);
|
param.getLoadedChunks().remove(chunkHash);
|
||||||
return new Chunk1_9to1_8(chunkX, chunkZ);
|
return new Chunk1_8(chunkX, chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
int startIndex = input.readerIndex();
|
int startIndex = input.readerIndex();
|
||||||
@ -87,41 +86,27 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
// Read blocks
|
// Read blocks
|
||||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set
|
if (!usedSections.get(i)) continue; // Section not set
|
||||||
ChunkSection1_9to1_8 section = new ChunkSection1_9to1_8();
|
ChunkSection section = Types1_8.CHUNK_SECTION.read(input);
|
||||||
sections[i] = section;
|
sections[i] = section;
|
||||||
|
|
||||||
// Read block data and convert to short buffer
|
if (replacePistons && section.getPalette().contains(36)) {
|
||||||
byte[] blockData = new byte[ChunkSection1_9to1_8.SIZE * 2];
|
section.getPalette().set(section.getPalette().indexOf(36), replacementId);
|
||||||
input.readBytes(blockData);
|
|
||||||
ShortBuffer blockBuf = ByteBuffer.wrap(blockData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
|
|
||||||
|
|
||||||
for (int j = 0; j < ChunkSection1_9to1_8.SIZE; j++) {
|
|
||||||
int mask = blockBuf.get();
|
|
||||||
int type = mask >> 4;
|
|
||||||
int data = mask & 0xF;
|
|
||||||
if (replacePistons && type == 36)
|
|
||||||
type = replacementId;
|
|
||||||
section.setBlock(j, type, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read block light
|
// Read block light
|
||||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set, has no light
|
if (!usedSections.get(i)) continue; // Section not set, has no light
|
||||||
byte[] blockLightArray = new byte[ChunkSection1_9to1_8.LIGHT_LENGTH];
|
sections[i].readBlockLight(input);
|
||||||
input.readBytes(blockLightArray);
|
|
||||||
sections[i].setBlockLight(blockLightArray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read sky light
|
// Read sky light
|
||||||
int bytesLeft = dataLength - (input.readerIndex() - startIndex);
|
int bytesLeft = dataLength - (input.readerIndex() - startIndex);
|
||||||
if (bytesLeft >= ChunkSection1_9to1_8.LIGHT_LENGTH) {
|
if (bytesLeft >= ChunkSection.LIGHT_LENGTH) {
|
||||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||||
if (!usedSections.get(i)) continue; // Section not set, has no light
|
if (!usedSections.get(i)) continue; // Section not set, has no light
|
||||||
byte[] skyLightArray = new byte[ChunkSection1_9to1_8.LIGHT_LENGTH];
|
sections[i].readSkyLight(input);
|
||||||
input.readBytes(skyLightArray);
|
bytesLeft -= ChunkSection.LIGHT_LENGTH;
|
||||||
sections[i].setSkyLight(skyLightArray);
|
|
||||||
bytesLeft -= ChunkSection1_9to1_8.LIGHT_LENGTH;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,26 +123,26 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return chunks
|
// Return chunks
|
||||||
return new Chunk1_9to1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList<CompoundTag>());
|
return new Chunk1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList<CompoundTag>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuf output, ClientChunks param, Chunk input) throws Exception {
|
public void write(ByteBuf output, ClientChunks param, Chunk input) throws Exception {
|
||||||
if (!(input instanceof Chunk1_9to1_8)) throw new Exception("Incompatible chunk, " + input.getClass());
|
if (!(input instanceof Chunk1_8)) throw new Exception("Incompatible chunk, " + input.getClass());
|
||||||
|
|
||||||
Chunk1_9to1_8 chunk = (Chunk1_9to1_8) input;
|
Chunk1_8 chunk = (Chunk1_8) input;
|
||||||
// Write primary info
|
// Write primary info
|
||||||
output.writeInt(chunk.getX());
|
output.writeInt(chunk.getX());
|
||||||
output.writeInt(chunk.getZ());
|
output.writeInt(chunk.getZ());
|
||||||
if (chunk.isUnloadPacket()) return;
|
if (chunk.isUnloadPacket()) return;
|
||||||
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
|
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
|
||||||
Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
|
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||||
|
|
||||||
ByteBuf buf = output.alloc().buffer();
|
ByteBuf buf = output.alloc().buffer();
|
||||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||||
ChunkSection1_9to1_8 section = chunk.getSections()[i];
|
ChunkSection section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
section.writeBlocks(buf);
|
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||||
section.writeBlockLight(buf);
|
section.writeBlockLight(buf);
|
||||||
|
|
||||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren