Archived
0

refactory world and clean classes

This commit is contained in:
2018-08-16 00:08:26 +03:00
parent 333150dd30
commit dc9e3512e7
24 changed files with 175 additions and 450 deletions

View File

@@ -12,6 +12,8 @@ import mc.core.network.NetOutputStream;
import mc.core.network.SCPacket;
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
import mc.core.world.block.Block;
import mc.core.world.block.BlockType;
import mc.core.world.chunk.Chunk;
import mc.core.world.chunk.ChunkSection;
import java.util.ArrayList;
@@ -75,11 +77,11 @@ public class ChunkDataPacket implements SCPacket {
private int z;
@Setter
private boolean initChunk = true; // "Ground-Up Continuous"
@Getter
private List<ChunkSection> chunks = new ArrayList<>();
@Setter
private Chunk chunk;
private int serializeBlockState(int id, int meta) {
return (id << 4) | meta;
private int serializeBlockState(BlockType blockType) {
return (blockType.getId() << 4) | blockType.getMeta();
}
@Override
@@ -91,9 +93,14 @@ public class ChunkDataPacket implements SCPacket {
final ByteArrayOutputNetStream data = new ByteArrayOutputNetStream();
int dataItems = 0;
final int airBlockPalette = serializeBlockState(0, 0);
final int airBlockPalette = serializeBlockState(BlockType.AIR);
for (int h = 0; h < 1/*потому что у нас пока только единичная сейция*/; h++) {
ChunkSection chunkSection = chunk.getChunkSection(h);
if (chunkSection == null) {
continue;
}
for (ChunkSection chunk : chunks) {
final List<Integer> palette = new ArrayList<>();
palette.add(airBlockPalette);
final ByteArrayOutputNetStream dataArray = new ByteArrayOutputNetStream();
@@ -112,8 +119,8 @@ public class ChunkDataPacket implements SCPacket {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
Block block = chunk.getBlock(x, y, z);
int blockState = serializeBlockState(block.getId(), block.getMeta());
Block block = chunkSection.getBlock(x, y, z);
int blockState = serializeBlockState(block.getBlockType());
int currentIndexPaletteBlock;
if (!palette.contains(blockState)) {
@@ -138,12 +145,12 @@ public class ChunkDataPacket implements SCPacket {
if (idxHalfByte == 0) {
blockLightCompacted = block.getLight();
skyLightCompacted = chunk.getSkyLight(x, y, z);
skyLightCompacted = chunkSection.getSkyLight(x, y, z);
idxHalfByte++;
} else {
blockLightCompacted = (blockLightCompacted << 4) | block.getLight();
blockLight.writeByte(blockLightCompacted);
skyLightCompacted = (skyLightCompacted << 4) | chunk.getSkyLight(x, y, z);
skyLightCompacted = (skyLightCompacted << 4) | chunkSection.getSkyLight(x, y, z);
skyLight.writeByte(skyLightCompacted);
idxHalfByte = 0;
}