Skip to content

Commit 867faa4

Browse files
authored
Merge pull request #155 from EamonHeffernan/surface-lighting
Basic surface lighting
2 parents 524fecf + f942a65 commit 867faa4

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

pumpkin-protocol/src/client/play/c_chunk_data.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,40 @@ impl<'a> ClientPacket for CChunkData<'a> {
110110
// TODO: block entities
111111
buf.put_var_int(&VarInt(0));
112112

113-
// TODO
113+
// Sky Light Mask
114+
// All of the chunks, this is not optimal and uses way more data than needed but will be
115+
// overhauled with full lighting system.
116+
buf.put_bit_set(&BitSet(VarInt(1), &[0b01111111111111111111111110]));
117+
// Block Light Mask
114118
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
119+
// Empty Sky Light Mask
120+
buf.put_bit_set(&BitSet(VarInt(1), &[0b0]));
121+
// Empty Block Light Mask
115122
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
116-
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
117-
buf.put_bit_set(&BitSet(VarInt(1), &[0]));
118-
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
119-
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
120-
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
121-
// buf.put_bit_set(&BitSet(VarInt(0), vec![]));
122123

123-
buf.put_var_int(&VarInt(0));
124+
let mut lighting_subchunks = Vec::new();
125+
126+
self.0.blocks.iter_subchunks().for_each(|chunk| {
127+
let mut chunk_light = [0u8; 2048];
128+
for (i, block) in chunk.iter().enumerate() {
129+
if !block.is_air() {
130+
continue;
131+
}
132+
let index = i / 2;
133+
let mask = if i % 2 == 1 { 0xF0 } else { 0x0F };
134+
chunk_light[index] |= mask;
135+
}
136+
137+
lighting_subchunks.push(chunk_light);
138+
});
139+
140+
buf.put_var_int(&lighting_subchunks.len().into());
141+
for subchunk in lighting_subchunks {
142+
buf.put_var_int(&VarInt(subchunk.len() as i32));
143+
buf.put_slice(&subchunk);
144+
}
145+
146+
// Block Lighting
124147
buf.put_var_int(&VarInt(0));
125148
}
126149
}

0 commit comments

Comments
 (0)