2019-08-30 21:47:33 +00:00
|
|
|
package org.geysermc.connector.utils;
|
|
|
|
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
|
|
|
import org.geysermc.connector.network.translators.TranslatorsInit;
|
2019-10-10 00:11:50 +00:00
|
|
|
import org.geysermc.connector.network.translators.block.BlockEntry;
|
2019-08-30 21:47:33 +00:00
|
|
|
import org.geysermc.connector.world.chunk.ChunkSection;
|
|
|
|
|
|
|
|
public class ChunkUtils {
|
|
|
|
|
|
|
|
public static ChunkData translateToBedrock(Column column) {
|
|
|
|
ChunkData chunkData = new ChunkData();
|
|
|
|
|
2019-09-13 09:39:38 +00:00
|
|
|
Chunk[] chunks = column.getChunks();
|
|
|
|
int chunkSectionCount = chunks.length;
|
|
|
|
chunkData.sections = new ChunkSection[chunkSectionCount];
|
|
|
|
for (int i = 0; i < chunkSectionCount; i++) {
|
|
|
|
chunkData.sections[i] = new ChunkSection();
|
2019-08-30 21:47:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 09:39:38 +00:00
|
|
|
for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) {
|
|
|
|
Chunk chunk = chunks[chunkY];
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
if (chunk == null || chunk.isEmpty())
|
|
|
|
continue;
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
ChunkSection section = chunkData.sections[chunkY];
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
for (int x = 0; x < 16; x++) {
|
|
|
|
for (int y = 0; y < 16; y++) {
|
|
|
|
for (int z = 0; z < 16; z++) {
|
2019-10-13 20:28:03 +00:00
|
|
|
BlockState blockState = chunk.get(x, y, z);
|
2019-10-10 00:11:50 +00:00
|
|
|
BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-13 09:08:48 +00:00
|
|
|
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
2019-10-10 00:11:50 +00:00
|
|
|
block.getBedrockId() << 4 | block.getBedrockData());
|
|
|
|
|
|
|
|
if (block.getJavaIdentifier().contains("waterlogged=true")) {
|
|
|
|
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z),
|
|
|
|
9 << 4); // water id
|
|
|
|
}
|
2019-09-08 20:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-30 21:47:33 +00:00
|
|
|
}
|
2019-09-08 20:46:10 +00:00
|
|
|
return chunkData;
|
2019-08-30 21:47:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
public static final class ChunkData {
|
|
|
|
public ChunkSection[] sections;
|
|
|
|
|
|
|
|
public byte[] biomes = new byte[256];
|
|
|
|
public byte[] blockEntities = new byte[0];
|
2019-08-30 21:47:33 +00:00
|
|
|
}
|
|
|
|
}
|