File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ pub struct BlockVertexData {
145
145
}
146
146
147
147
impl Block {
148
+ // Takes in relative position
148
149
pub fn new ( position : Vec3 , chunk : ( i32 , i32 ) , block_type : BlockType ) -> Block {
149
150
let absolute_position = glam:: vec3 (
150
151
( chunk. 0 * CHUNK_SIZE as i32 + position. x as i32 ) as f32 ,
Original file line number Diff line number Diff line change @@ -253,6 +253,39 @@ impl Chunk {
253
253
254
254
blocks
255
255
}
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
+ }
256
289
257
290
pub fn new (
258
291
x : i32 ,
@@ -293,6 +326,7 @@ impl Chunk {
293
326
chunk_position_buffer,
294
327
indices : 0 ,
295
328
} ;
329
+ chunk. place_trees ( ) ;
296
330
chunk. build_mesh ( other_chunks) ;
297
331
298
332
return chunk;
You can’t perform that action at this time.
0 commit comments