Random tick: reed growth

This commit is contained in:
xtreme8000 2023-11-20 23:58:39 +01:00
parent 2c4c15c20f
commit 473cdb9229
8 changed files with 111 additions and 5 deletions

View file

@ -97,6 +97,7 @@ add_executable(cavex
source/item/inventory.c
source/item/items.c
source/item/tool.c
source/item/items/item_sugarcane.c
source/network/client_interface.c
source/network/level_archive.c

View file

@ -23,7 +23,7 @@ include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source source/block source/entity source/graphics source/network source/game source/game/gui source/platform source/item source/cNBT source/lodepng source/parson
SOURCES := source source/block source/entity source/graphics source/network source/game source/game/gui source/platform source/item source/item/items source/cNBT source/lodepng source/parson
DATA :=
TEXTURES := textures
INCLUDES :=

View file

@ -17,6 +17,7 @@
along with CavEX. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../network/server_local.h"
#include "blocks.h"
static enum block_material getMaterial(struct block_info* this) {
@ -50,6 +51,52 @@ static size_t getDroppedItem(struct block_info* this, struct item_data* it,
return 1;
}
static void onRandomTick(struct server_local* s, struct block_info* this) {
// TODO: check for water
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_REED) {
height++;
has_support = true;
} else {
if(below.type == BLOCK_DIRT || below.type == BLOCK_GRASS)
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_REED,
.metadata = 0,
});
}
this->block->metadata++;
server_world_set_block(&s->world, this->x, this->y, this->z,
*this->block);
}
}
struct block block_reed = {
.name = "Reed",
.getSideMask = getSideMask,
@ -57,7 +104,7 @@ struct block block_reed = {
.getMaterial = getMaterial,
.getTextureIndex = getTextureIndex,
.getDroppedItem = getDroppedItem,
.onRandomTick = NULL,
.onRandomTick = onRandomTick,
.transparent = false,
.renderBlock = render_block_cross,
.renderBlockAlways = NULL,

View file

@ -68,6 +68,7 @@ enum block_type {
BLOCK_SNOW = 78,
BLOCK_ICE = 79,
BLOCK_CACTUS = 81,
BLOCK_REED = 83,
BLOCK_PORTAL = 90,
};

View file

@ -142,8 +142,7 @@ static void screen_ingame_update(struct screen* s, float dt) {
&& !gstate.digging.active) {
struct item_data item;
if(inventory_get_hotbar_item(
windowc_get_latest(gstate.windows[WINDOWC_INVENTORY]), &item)
&& item_is_block(&item)) {
windowc_get_latest(gstate.windows[WINDOWC_INVENTORY]), &item)) {
svin_rpc_send(&(struct server_rpc) {
.type = SRPC_BLOCK_PLACE,
.payload.block_place.x = gstate.camera_hit.x,

View file

@ -122,7 +122,7 @@ void items_init() {
// milk bucket
// brick
// clay
// sugarcane
items[338] = &item_sugarcane;
// paper
// book
// slimeball

View file

@ -0,0 +1,56 @@
/*
Copyright (c) 2023 ByteBit/xtreme8000
This file is part of CavEX.
CavEX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CavEX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CavEX. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../network/server_local.h"
static bool onItemPlace(struct server_local* s, struct item_data* it,
struct block_info* where, struct block_info* on,
enum side on_side) {
struct block_data blk;
if(!server_world_get_block(&s->world, where->x, where->y - 1, where->z,
&blk))
return false;
if(blk.type != BLOCK_DIRT && blk.type != BLOCK_GRASS
&& blk.type != BLOCK_REED)
return false;
return block_place_default(s,
&(struct item_data) {
.id = BLOCK_REED,
.durability = 0,
},
where, on, on_side);
}
struct item item_sugarcane = {
.name = "Sugarcane",
.has_damage = false,
.max_stack = 64,
.renderItem = render_item_flat,
.onItemPlace = onItemPlace,
.armor.is_armor = false,
.tool.type = TOOL_TYPE_ANY,
.render_data = {
.item = {
.texture_x = 11,
.texture_y = 1,
},
},
};

View file

@ -677,3 +677,5 @@ static struct item item_porkchop_cooked = {
},
},
};
extern struct item item_sugarcane;