Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/block_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ int block_connects(block_id block)
return 0;
}
}

int block_can_be_placed_on(block_id ground, block_id block)
{
switch (block)
{
case SAPLING:
return ground == GRASS;
default:
return 1;
}
}
1 change: 1 addition & 0 deletions src/block_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern bounding_box block_box;

int block_is_opaque(block_id block);
int block_is_obstacle(block_id block);
int block_can_be_placed_on(block_id ground, block_id block);
int block_connects(block_id block);

#endif
10 changes: 7 additions & 3 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ void world_tick(world *w)

vec3 position = {w->selected_block_x, w->selected_block_y - 0.5f, w->selected_block_z};
bounding_box_update(&block_box, &position);
block_id ground = world_get_block(w, position.x, position.y, position.z);

if (!is_colliding(&block_box, &w->player.box))
if (!is_colliding(&block_box, &w->player.box) && block_can_be_placed_on(ground, w->selected_block))
{
world_set_block(w, w->selected_block_x, w->selected_block_y, w->selected_block_z, w->selected_block);
w->block_changed = 1;
Expand Down Expand Up @@ -378,9 +379,12 @@ void world_draw(world *w, double delta_time, double time_since_tick)
vec3 player_delta;
multiply_v3f(&player_delta, &w->player.velocity, tick_delta_time);

if (w->noclip_mode) {
if (w->noclip_mode)
{
add_v3(&w->player.position, &w->player.position, &player_delta);
} else {
}
else
{
entity_move(&w->player, w, &player_delta);

w->player.on_ground = 0;
Expand Down