Various chunk tweaks.

This commit is contained in:
SupremeMortal 2019-09-13 10:08:48 +01:00
parent 72589fabcd
commit 7a6d3f4604
No known key found for this signature in database
GPG Key ID: DDBB25F8EE4FA29A
3 changed files with 12 additions and 12 deletions

View File

@ -21,17 +21,15 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
try { try {
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn()); ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn());
ByteBuf byteBuf = Unpooled.buffer(32); ByteBuf byteBuf = Unpooled.buffer(32);
int count = 0;
ChunkSection[] sections = chunkData.sections; ChunkSection[] sections = chunkData.sections;
for (int i = sections.length - 1; i >= 0; i--) {
if (sections[i].isEmpty())
continue;
count = i + 1; int sectionCount = 16;
break; while (sections[sectionCount].isEmpty()) {
sectionCount--;
} }
sectionCount++;
for (int i = 0; i < count; i++) { for (int i = 0; i < sectionCount; i++) {
ChunkSection section = chunkData.sections[i]; ChunkSection section = chunkData.sections[i];
section.writeToNetwork(byteBuf); section.writeToNetwork(byteBuf);
} }
@ -44,7 +42,7 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
byteBuf.readBytes(payload); byteBuf.readBytes(payload);
LevelChunkPacket levelChunkPacket = new LevelChunkPacket(); LevelChunkPacket levelChunkPacket = new LevelChunkPacket();
levelChunkPacket.setSubChunksLength(count); levelChunkPacket.setSubChunksLength(sectionCount);
levelChunkPacket.setCachingEnabled(false); levelChunkPacket.setCachingEnabled(false);
levelChunkPacket.setChunkX(packet.getColumn().getX()); levelChunkPacket.setChunkX(packet.getColumn().getX());
levelChunkPacket.setChunkZ(packet.getColumn().getZ()); levelChunkPacket.setChunkZ(packet.getColumn().getZ());

View File

@ -7,6 +7,7 @@ import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.item.BedrockItem; import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.world.chunk.ChunkSection; import org.geysermc.connector.world.chunk.ChunkSection;
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
public class ChunkUtils { public class ChunkUtils {
@ -69,7 +70,7 @@ public class ChunkUtils {
ChunkSection section = chunkData.sections[chunkY]; ChunkSection section = chunkData.sections[chunkY];
section.getBlockStorageArray()[0] = new org.geysermc.connector.world.chunk.BlockStorage(); section.getBlockStorageArray()[0] = new org.geysermc.connector.world.chunk.BlockStorage();
section.getBlockStorageArray()[1] = new org.geysermc.connector.world.chunk.BlockStorage(); section.getBlockStorageArray()[1] = new org.geysermc.connector.world.chunk.BlockStorage(BitArrayVersion.V1);
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++) {
@ -77,7 +78,8 @@ public class ChunkUtils {
BlockState block = storage.get(x, y, z); BlockState block = storage.get(x, y, z);
BedrockItem bedrockBlock = TranslatorsInit.getItemTranslator().getBedrockBlock(block); BedrockItem bedrockBlock = TranslatorsInit.getItemTranslator().getBedrockBlock(block);
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), bedrockBlock.getId() << 4 | bedrockBlock.getData()); section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
bedrockBlock.getId() << 4 | bedrockBlock.getData());
} }
} }
} }

View File

@ -56,9 +56,9 @@ public class BlockStorage {
buffer.writeIntLE(word); buffer.writeIntLE(word);
} }
VarInts.writeUnsignedInt(buffer, palette.size()); VarInts.writeInt(buffer, palette.size());
palette.forEach(id -> { palette.forEach(id -> {
VarInts.writeUnsignedInt(buffer, id); VarInts.writeInt(buffer, id);
return true; return true;
}); });
} }