Skip to content

Commit 30458b4

Browse files
committed
feat: trees init
1 parent ab35df5 commit 30458b4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/blocks/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub struct BlockVertexData {
145145
}
146146

147147
impl Block {
148+
// Takes in relative position
148149
pub fn new(position: Vec3, chunk: (i32, i32), block_type: BlockType) -> Block {
149150
let absolute_position = glam::vec3(
150151
(chunk.0 * CHUNK_SIZE as i32 + position.x as i32) as f32,

src/chunk.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,39 @@ impl Chunk {
253253

254254
blocks
255255
}
256+
pub fn place_trees(&mut self) {
257+
let yblocks = self.blocks.get(&(7 * CHUNK_SIZE as usize) + 7).unwrap();
258+
let highest_block = yblocks
259+
.last()
260+
.as_ref()
261+
.unwrap()
262+
.as_ref()
263+
.unwrap()
264+
.lock()
265+
.unwrap()
266+
.position
267+
.clone();
268+
269+
let base0 = Arc::new(Mutex::new(Block::new(
270+
highest_block + glam::vec3(0.0, 1.0, 0.0),
271+
(self.x, self.y),
272+
BlockType::wood(),
273+
)));
274+
let base1 = Arc::new(Mutex::new(Block::new(
275+
highest_block + glam::vec3(0.0, 2.0, 0.0),
276+
(self.x, self.y),
277+
BlockType::wood(),
278+
)));
279+
let base2 = Arc::new(Mutex::new(Block::new(
280+
highest_block + glam::vec3(0.0, 3.0, 0.0),
281+
(self.x, self.y),
282+
BlockType::wood(),
283+
)));
284+
285+
self.add_block(base0);
286+
self.add_block(base1);
287+
self.add_block(base2);
288+
}
256289

257290
pub fn new(
258291
x: i32,
@@ -293,6 +326,7 @@ impl Chunk {
293326
chunk_position_buffer,
294327
indices: 0,
295328
};
329+
chunk.place_trees();
296330
chunk.build_mesh(other_chunks);
297331

298332
return chunk;

0 commit comments

Comments
 (0)