Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic surface lighting #155

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions pumpkin-protocol/src/client/play/c_chunk_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,40 @@ impl<'a> ClientPacket for CChunkData<'a> {
// TODO: block entities
buf.put_var_int(&VarInt(0));

// TODO
// Sky Light Mask
// All of the chunks, this is not optimal and uses way more data than needed but will be
// overhauled with full lighting system.
buf.put_bit_set(&BitSet(VarInt(1), &[0b01111111111111111111111110]));
// Block Light Mask
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
// Empty Sky Light Mask
buf.put_bit_set(&BitSet(VarInt(1), &[0b0]));
// Empty Block Light Mask
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));

buf.put_var_int(&VarInt(0));
let mut lighting_subchunks = Vec::new();

self.0.blocks.iter_subchunks().for_each(|chunk| {
let mut chunk_light = [0u8; 2048];
for (i, block) in chunk.iter().enumerate() {
if !block.is_air() {
continue;
}
let index = i / 2;
let mask = if i % 2 == 1 { 0xF0 } else { 0x0F };
chunk_light[index] |= mask;
}

lighting_subchunks.push(chunk_light);
});

buf.put_var_int(&lighting_subchunks.len().into());
for subchunk in lighting_subchunks {
buf.put_var_int(&VarInt(subchunk.len() as i32));
buf.put_slice(&subchunk);
}

// Block Lighting
buf.put_var_int(&VarInt(0));
}
}