2019-08-30 21:47:33 +00:00
|
|
|
package org.geysermc.connector.utils;
|
|
|
|
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage;
|
|
|
|
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;
|
|
|
|
import org.geysermc.connector.network.translators.item.BedrockItem;
|
|
|
|
import org.geysermc.connector.world.chunk.ChunkSection;
|
2019-09-13 09:08:48 +00:00
|
|
|
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
|
2019-08-30 21:47:33 +00:00
|
|
|
|
|
|
|
public class ChunkUtils {
|
|
|
|
|
|
|
|
public static ChunkData translateToBedrock(Column column) {
|
|
|
|
ChunkData chunkData = new ChunkData();
|
|
|
|
chunkData.sections = new ChunkSection[16];
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
chunkData.sections[i] = new ChunkSection();
|
|
|
|
}
|
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
/*
|
2019-08-30 21:47:33 +00:00
|
|
|
for (int y = 0; y < 256; y++) {
|
|
|
|
int chunkY = y >> 4;
|
|
|
|
|
|
|
|
Chunk chunk = null;
|
|
|
|
try {
|
|
|
|
chunk = column.getChunks()[chunkY];
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chunk == null || chunk.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BlockStorage storage = chunk.getBlocks();
|
|
|
|
for (int x = 0; x < 16; x++) {
|
|
|
|
for (int z = 0; z < 16; z++) {
|
2019-09-08 20:46:10 +00:00
|
|
|
BlockState block = storage.get(x, chunkY, z);
|
|
|
|
if (block == null)
|
|
|
|
block = new BlockState(0);
|
|
|
|
|
2019-08-30 21:47:33 +00:00
|
|
|
BedrockItem bedrockBlock = TranslatorsInit.getItemTranslator().getBedrockBlock(block);
|
|
|
|
|
|
|
|
ChunkSection section = chunkData.sections[chunkY];
|
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
//org.geysermc.connector.world.chunk.BlockStorage blockStorage = new org.geysermc.connector.world.chunk.BlockStorage();
|
|
|
|
int runtimeId = GlobalBlockPalette.getOrCreateRuntimeId(bedrockBlock.getId(), bedrockBlock.getData());
|
|
|
|
section.setFullBlock(x, y >> 4, z, 0, runtimeId << 2 | bedrockBlock.getData());
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
//section.getBlockStorageArray()[0] = blockStorage;
|
|
|
|
//section.getBlockStorageArray()[1] = blockStorage;
|
2019-08-30 21:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
*/
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
for (int chunkY = 0; chunkY < 16; chunkY++) {
|
|
|
|
Chunk chunk = null;
|
|
|
|
try {
|
|
|
|
chunk = column.getChunks()[chunkY];
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
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
|
|
|
BlockStorage storage = chunk.getBlocks();
|
|
|
|
ChunkSection section = chunkData.sections[chunkY];
|
2019-08-30 21:47:33 +00:00
|
|
|
|
2019-09-08 20:46:10 +00:00
|
|
|
section.getBlockStorageArray()[0] = new org.geysermc.connector.world.chunk.BlockStorage();
|
2019-09-13 09:08:48 +00:00
|
|
|
section.getBlockStorageArray()[1] = new org.geysermc.connector.world.chunk.BlockStorage(BitArrayVersion.V1);
|
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++) {
|
|
|
|
BlockState block = storage.get(x, y, z);
|
|
|
|
BedrockItem bedrockBlock = TranslatorsInit.getItemTranslator().getBedrockBlock(block);
|
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),
|
|
|
|
bedrockBlock.getId() << 4 | bedrockBlock.getData());
|
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
|
|
|
}
|
|
|
|
}
|