-
Notifications
You must be signed in to change notification settings - Fork 0
/
airlayer.c
50 lines (42 loc) · 1.2 KB
/
airlayer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "level.h"
#include "block.h"
static struct
{
enum blocktype_t air_layer;
} s;
static enum blocktype_t convert_air_layer(struct level_t *level, unsigned index, const struct block_t *block)
{
return AIR;
}
static void physics_air_layer_sub(struct level_t *l, int16_t x, int16_t y, int16_t z, enum blocktype_t type)
{
if (!level_valid_xyz(l, x, y, z)) return;
unsigned index = level_get_index(l, x, y, z);
switch (l->blocks[index].type)
{
case WATER:
case WATERSTILL:
case LAVA:
case LAVASTILL:
level_addupdate(l, index, type, 0);
break;
}
}
static void physics_air_layer(struct level_t *l, unsigned index, const struct block_t *block)
{
int16_t x, y, z;
level_get_xyz(l, index, &x, &y, &z);
physics_air_layer_sub(l, x - 1, y, z, block->type);
physics_air_layer_sub(l, x + 1, y, z, block->type);
physics_air_layer_sub(l, x, y, z - 1, block->type);
physics_air_layer_sub(l, x, y, z + 1, block->type);
level_addupdate(l, index, AIR, 0);
}
void module_init(void **data)
{
s.air_layer = register_blocktype(-1, "air_layer", RANK_ADV_BUILDER, &convert_air_layer, NULL, NULL, &physics_air_layer, true, true, false);
}
void module_deinit(void *data)
{
deregister_blocktype(s.air_layer);
}