Random tick: cacti growth

This commit is contained in:
xtreme8000 2023-11-20 19:01:14 +01:00
parent 00f409871f
commit 2c3c59703a

View file

@ -67,6 +67,51 @@ static bool onItemPlace(struct server_local* s, struct item_data* it,
return block_place_default(s, it, where, on, on_side); return block_place_default(s, it, where, on, on_side);
} }
static void onRandomTick(struct server_local* s, struct block_info* this) {
bool has_support = false;
int height = 1;
for(int k = 0; k < 2; k++) {
struct block_data below;
if(!server_world_get_block(&s->world, this->x, this->y - k - 1, this->z,
&below))
below.type = BLOCK_AIR;
if(below.type == BLOCK_CACTUS) {
height++;
has_support = true;
} else {
if(below.type == BLOCK_SAND)
has_support = true;
break;
}
}
if(!has_support) {
server_world_set_block(&s->world, this->x, this->y, this->z,
(struct block_data) {
.type = BLOCK_AIR,
.metadata = 0,
});
server_local_spawn_block_drops(s, this);
} else if(height < 3) {
if(this->block->metadata == 0xF) {
struct block_data above;
if(!server_world_get_block(&s->world, this->x, this->y + 1, this->z,
&above)
|| above.type == BLOCK_AIR)
server_world_set_block(&s->world, this->x, this->y + 1, this->z,
(struct block_data) {
.type = BLOCK_CACTUS,
.metadata = 0,
});
}
this->block->metadata++;
server_world_set_block(&s->world, this->x, this->y, this->z,
*this->block);
}
}
struct block block_cactus = { struct block block_cactus = {
.name = "Cactus", .name = "Cactus",
.getSideMask = getSideMask, .getSideMask = getSideMask,
@ -74,7 +119,7 @@ struct block block_cactus = {
.getMaterial = getMaterial, .getMaterial = getMaterial,
.getTextureIndex = getTextureIndex, .getTextureIndex = getTextureIndex,
.getDroppedItem = block_drop_default, .getDroppedItem = block_drop_default,
.onRandomTick = NULL, .onRandomTick = onRandomTick,
.transparent = false, .transparent = false,
.renderBlock = render_block_cactus, .renderBlock = render_block_cactus,
.renderBlockAlways = NULL, .renderBlockAlways = NULL,