├── icon.png ├── fCavEX.dol ├── fCavEX.elf ├── fCavex.zip ├── assets ├── anim.png ├── gui_2.png ├── items.png ├── mobs.png ├── controls.png ├── default.png ├── mob │ └── char.png ├── pointer.png ├── terrain.png ├── entity │ ├── pig.png │ ├── sheep.png │ ├── slime.png │ ├── creeper.png │ └── sheep_fur.png ├── gui │ ├── chest.png │ ├── furnace.png │ ├── crafting.png │ ├── inventory.png │ └── iron_chest.png ├── particles.png ├── terrain │ ├── sun.png │ └── moon.png ├── armor │ ├── chain_1.png │ ├── chain_2.png │ ├── cloth_1.png │ ├── cloth_2.png │ ├── gold_1.png │ ├── gold_2.png │ ├── iron_1.png │ ├── iron_2.png │ ├── diamond_1.png │ └── diamond_2.png ├── environment │ └── clouds.png └── README.md ├── docs └── ingame0.png ├── .editorconfig ├── .settings └── org.eclipse.cdt.core.prefs ├── source ├── config.h ├── game │ ├── game_state.c │ ├── gui │ │ ├── screen.c │ │ ├── screen.h │ │ ├── screen_pause.c │ │ └── screen_load_world.c │ ├── camera.h │ └── game_state.h ├── platform │ ├── gfx.c │ ├── displaylist.c │ ├── time.h │ ├── displaylist.h │ ├── thread.h │ ├── input.h │ ├── time.c │ ├── pc │ │ └── texture.c │ └── gfx.h ├── entity │ ├── entity_minecart.h │ ├── monsters_object.h │ └── entity_monster.h ├── chunk_mesher.h ├── daytime.h ├── graphics │ ├── gfx_util.h │ ├── render_item.h │ ├── render_entity.h │ ├── render_model.h │ ├── gui_util.h │ └── gfx_settings.h ├── config.c ├── item │ ├── tool.h │ ├── items │ │ ├── item_fish.c │ │ ├── item_porkchop.c │ │ ├── item_apple.c │ │ ├── item_apple_golden.c │ │ ├── item_fish_cooked.c │ │ ├── item_bread.c │ │ ├── item_porkchop_cooked.c │ │ ├── item_egg_zombie.c │ │ ├── item_mushroom_stew.c │ │ ├── item_sugarcane.c │ │ ├── item_minecart.c │ │ ├── item_redstone.c │ │ ├── item_seeds.c │ │ ├── item_door_iron.c │ │ ├── item_door_wood.c │ │ └── item_flint_steel.c │ ├── recipe.h │ ├── tool.c │ └── window_container.h ├── network │ ├── inventory_logic.h │ ├── complex_block_archive.h │ ├── server_interface.c │ ├── region_archive.h │ ├── server_interface.h │ ├── inventory_logic.c │ ├── server_local.h │ └── client_interface.h ├── stack.h ├── util.h ├── block │ ├── face_occlusion.h │ ├── aabb.h │ ├── block_portal.c │ ├── block_planks.c │ ├── block_sponge.c │ ├── block_bricks.c │ ├── block_netherrack.c │ ├── block_noteblock.c │ ├── block_obsidian.c │ ├── block_bedrock.c │ ├── block_jukebox.c │ ├── block_sandstone.c │ ├── block_spawner.c │ ├── block_ice.c │ ├── block_glass.c │ ├── block_clay.c │ ├── block_stone.c │ ├── block_bookshelf.c │ ├── block_glowstone.c │ ├── block_gravel.c │ ├── block_cobweb.c │ ├── block_fence.c │ ├── block_rose.c │ ├── block_flower.c │ ├── block_log.c │ ├── block_farmland.c │ ├── block_minecart.c │ ├── block_lava.c │ ├── block_double_slab.c │ └── block_dirt.c ├── lighting.h ├── particle.h ├── stack.c ├── chunk.h ├── daytime.c └── util.c ├── .gitignore ├── .project ├── config_pc.json ├── config.json ├── meta.xml ├── resources ├── vertex.shader └── fragment.shader ├── config_wii.json ├── .clang-format ├── controls.md └── .cproject /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/icon.png -------------------------------------------------------------------------------- /fCavEX.dol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/fCavEX.dol -------------------------------------------------------------------------------- /fCavEX.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/fCavEX.elf -------------------------------------------------------------------------------- /fCavex.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/fCavex.zip -------------------------------------------------------------------------------- /assets/anim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/anim.png -------------------------------------------------------------------------------- /assets/gui_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/gui_2.png -------------------------------------------------------------------------------- /assets/items.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/items.png -------------------------------------------------------------------------------- /assets/mobs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/mobs.png -------------------------------------------------------------------------------- /docs/ingame0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/docs/ingame0.png -------------------------------------------------------------------------------- /assets/controls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/controls.png -------------------------------------------------------------------------------- /assets/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/default.png -------------------------------------------------------------------------------- /assets/mob/char.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/mob/char.png -------------------------------------------------------------------------------- /assets/pointer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/pointer.png -------------------------------------------------------------------------------- /assets/terrain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/terrain.png -------------------------------------------------------------------------------- /assets/entity/pig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/entity/pig.png -------------------------------------------------------------------------------- /assets/gui/chest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/gui/chest.png -------------------------------------------------------------------------------- /assets/gui/furnace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/gui/furnace.png -------------------------------------------------------------------------------- /assets/particles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/particles.png -------------------------------------------------------------------------------- /assets/terrain/sun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/terrain/sun.png -------------------------------------------------------------------------------- /assets/armor/chain_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/chain_1.png -------------------------------------------------------------------------------- /assets/armor/chain_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/chain_2.png -------------------------------------------------------------------------------- /assets/armor/cloth_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/cloth_1.png -------------------------------------------------------------------------------- /assets/armor/cloth_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/cloth_2.png -------------------------------------------------------------------------------- /assets/armor/gold_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/gold_1.png -------------------------------------------------------------------------------- /assets/armor/gold_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/gold_2.png -------------------------------------------------------------------------------- /assets/armor/iron_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/iron_1.png -------------------------------------------------------------------------------- /assets/armor/iron_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/iron_2.png -------------------------------------------------------------------------------- /assets/entity/sheep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/entity/sheep.png -------------------------------------------------------------------------------- /assets/entity/slime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/entity/slime.png -------------------------------------------------------------------------------- /assets/gui/crafting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/gui/crafting.png -------------------------------------------------------------------------------- /assets/gui/inventory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/gui/inventory.png -------------------------------------------------------------------------------- /assets/terrain/moon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/terrain/moon.png -------------------------------------------------------------------------------- /assets/armor/diamond_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/diamond_1.png -------------------------------------------------------------------------------- /assets/armor/diamond_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/armor/diamond_2.png -------------------------------------------------------------------------------- /assets/entity/creeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/entity/creeper.png -------------------------------------------------------------------------------- /assets/entity/sheep_fur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/entity/sheep_fur.png -------------------------------------------------------------------------------- /assets/gui/iron_chest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/gui/iron_chest.png -------------------------------------------------------------------------------- /assets/environment/clouds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilleb/fCavEX/HEAD/assets/environment/clouds.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = tab 3 | indent_size = 4 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | doxygen/doxygen_new_line_after_brief=true 2 | doxygen/doxygen_use_brief_tag=false 3 | doxygen/doxygen_use_javadoc_tags=true 4 | doxygen/doxygen_use_pre_tag=false 5 | doxygen/doxygen_use_structural_commands=false 6 | eclipse.preferences.version=1 7 | -------------------------------------------------------------------------------- /source/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #include 5 | 6 | #include "parson/parson.h" 7 | 8 | struct config { 9 | JSON_Value* root; 10 | }; 11 | 12 | bool config_create(struct config* c, const char* filename); 13 | const char* config_read_string(struct config* c, const char* key, 14 | const char* fallback); 15 | bool config_read_int_array(struct config* c, const char* key, int* dest, 16 | size_t* length); 17 | void config_destroy(struct config* c); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /source/cglm/ 2 | /source/cNBT/ 3 | /source/lodepng/ 4 | /source/parson/ 5 | /build/ 6 | *.elf 7 | *.dol 8 | movedol.bat 9 | *.elf 10 | fCavEX.dol 11 | fCavEX.elf 12 | Makefile 13 | Makefile 14 | .project 15 | .cproject 16 | .settings/org.eclipse.cdt.core.prefs 17 | assets/default.png 18 | *.png 19 | *.dol 20 | *.elf 21 | *.zip 22 | fCavEX.elf 23 | Makefile 24 | fCavEX.dol 25 | fCavEX.elf 26 | Makefile 27 | .cproject 28 | .project 29 | .project 30 | fCavEX.dol 31 | fCavEX.elf 32 | Makefile 33 | .cproject 34 | .project 35 | fCavEX.dol 36 | fCavEX.elf 37 | Makefile 38 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fCavex 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.core.cBuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | 16 | org.eclipse.cdt.core.cnature 17 | org.eclipse.cdt.core.ccnature 18 | org.eclipse.cdt.make.core.makeNature 19 | 20 | 21 | -------------------------------------------------------------------------------- /config_pc.json: -------------------------------------------------------------------------------- 1 | { 2 | "paths": { 3 | "texturepack": "assets", 4 | "worlds": "saves" 5 | }, 6 | "input": { 7 | "player_forward": [87], 8 | "player_backward": [83], 9 | "player_left": [65], 10 | "player_right": [68], 11 | "player_jump": [32], 12 | "player_sneak": [340], 13 | "item_action_left": [1000], 14 | "item_action_right": [1001], 15 | "scroll_left": [], 16 | "scroll_right": [], 17 | "inventory": [69], 18 | "open_menu": [257], 19 | "gui_up": [87], 20 | "gui_down": [83], 21 | "gui_left": [65], 22 | "gui_right": [68], 23 | "gui_click": [1000], 24 | "gui_click_alt": [1001], 25 | "screenshot": [291] 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "paths": { 3 | "texturepack": "assets", 4 | "worlds": "saves" 5 | }, 6 | "input": { 7 | "player_forward": [87], 8 | "player_backward": [83], 9 | "player_left": [65], 10 | "player_right": [68], 11 | "player_jump": [32], 12 | "player_sneak": [340], 13 | "item_action_left": [1000], 14 | "item_action_right": [1001], 15 | "scroll_left": [49], 16 | "scroll_right": [50], 17 | "inventory": [69], 18 | "open_menu": [257], 19 | "gui_up": [265], 20 | "gui_down": [264], 21 | "gui_left": [263], 22 | "gui_right": [262], 23 | "gui_click": [1000], 24 | "gui_click_alt": [1001], 25 | "screenshot": [291] 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | fCavEX 4 | Alpha 0.3.0_f1 5 | 20240723000000 6 | ByteBit/xtreme8000 7 | Beta 1.7.3 for the Wii 8 | Your favourite block game on the Nintendo Wii. 9 | Implements Beta 1.7.3. 10 | Works with Wiimote + Nunchuk or a Classic Controller. 11 | 12 | See https://github.com/xtreme8000/CavEX for more information. 13 | Licensed under GPLv3. 14 | Copyright (c) 2022-2023 ByteBit/xtreme8000 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /resources/vertex.shader: -------------------------------------------------------------------------------- 1 | #version 110 2 | 3 | uniform mat4 mv; 4 | uniform mat4 proj; 5 | uniform mat4 texm; 6 | 7 | uniform bool enable_lighting; 8 | uniform float lighting[256]; 9 | 10 | attribute vec3 a_pos; 11 | attribute vec4 a_color; 12 | attribute vec2 a_texcoord; 13 | attribute vec2 a_light; 14 | 15 | varying vec3 v_pos; 16 | varying vec4 v_color; 17 | varying vec2 v_texcoord; 18 | 19 | void main() { 20 | if(enable_lighting) { 21 | v_color = vec4(vec3(lighting[int(a_light.x) + int(a_light.y) * 16]), 1.0); 22 | } else { 23 | v_color = a_color; 24 | } 25 | 26 | v_pos = a_pos; 27 | v_texcoord = (texm * vec4(a_texcoord, 0.0, 1.0)).xy; 28 | gl_Position = proj * mv * vec4(a_pos, 1.0); 29 | } 30 | -------------------------------------------------------------------------------- /config_wii.json: -------------------------------------------------------------------------------- 1 | { 2 | "paths": { 3 | "texturepack": "assets", 4 | "worlds": "saves" 5 | }, 6 | "input": { 7 | "player_forward": [0, 200, 910], 8 | "player_backward": [1, 201, 911], 9 | "player_left": [2, 202, 912], 10 | "player_right": [3, 203, 913], 11 | "player_jump": [5, 210], 12 | "player_sneak": [211], 13 | "item_action_left": [100, 204], 14 | "item_action_right": [101, 205], 15 | "scroll_left": [9, 208, 213], 16 | "scroll_right": [8, 209, 212], 17 | "inventory": [6, 206], 18 | "open_menu": [10, 214], 19 | "gui_up": [0, 200, 900, 910, 920], 20 | "gui_down": [1, 201, 901, 911, 921], 21 | "gui_left": [2, 202, 902, 912, 922], 22 | "gui_right": [3, 203, 903, 913, 923], 23 | "gui_click": [4, 204], 24 | "gui_click_alt": [5, 205], 25 | "screenshot": [7], 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /resources/fragment.shader: -------------------------------------------------------------------------------- 1 | #version 110 2 | 3 | uniform sampler2D tex; 4 | uniform bool enable_texture; 5 | uniform bool enable_alpha; 6 | 7 | uniform bool enable_fog; 8 | uniform vec2 fog_delta; 9 | uniform float fog_distance; 10 | uniform vec3 fog_color; 11 | 12 | varying vec3 v_pos; 13 | varying vec4 v_color; 14 | varying vec2 v_texcoord; 15 | 16 | void main() { 17 | vec4 tex_color = vec4(1.0); 18 | 19 | if(enable_texture) 20 | tex_color = texture2D(tex, v_texcoord); 21 | 22 | float v_fog = 0.0; 23 | 24 | if(enable_fog) 25 | v_fog = clamp((length(fog_delta + v_pos.xz) - (fog_distance - 9.0)) / 8.0, 0.0, 1.0); 26 | 27 | vec4 frag = v_color * tex_color; 28 | gl_FragColor = vec4(mix(frag.rgb, fog_color, v_fog), frag.a); 29 | 30 | if(enable_alpha && gl_FragColor.a < 0.0625) 31 | discard; 32 | } 33 | -------------------------------------------------------------------------------- /source/game/game_state.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "game_state.h" 21 | 22 | struct game_state gstate; 23 | -------------------------------------------------------------------------------- /source/platform/gfx.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifdef PLATFORM_WII 21 | #include "wii/gfx.c" 22 | #endif 23 | 24 | #ifdef PLATFORM_PC 25 | #include "pc/gfx.c" 26 | #endif 27 | -------------------------------------------------------------------------------- /source/platform/displaylist.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifdef PLATFORM_WII 21 | #include "wii/displaylist.c" 22 | #endif 23 | 24 | #ifdef PLATFORM_PC 25 | #include "pc/displaylist.c" 26 | #endif 27 | -------------------------------------------------------------------------------- /source/game/gui/screen.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "../../platform/gfx.h" 23 | #include "../game_state.h" 24 | 25 | void screen_set(struct screen* s) { 26 | assert(s); 27 | gstate.current_screen = s; 28 | if(s->reset) 29 | s->reset(s, gfx_width(), gfx_height()); 30 | } 31 | -------------------------------------------------------------------------------- /source/entity/entity_minecart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | 21 | #ifndef ENTITY_MINECART_H 22 | #define ENTITY_MINECART_H 23 | 24 | #include 25 | #include "../cglm/cglm.h" 26 | #include "entity.h" 27 | 28 | void entity_minecart(uint32_t id, struct entity* e, bool server, void* world); 29 | 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /source/chunk_mesher.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef CHUNK_MESHER_H 21 | #define CHUNK_MESHER_H 22 | 23 | #include 24 | 25 | #define CHUNK_MESHER_QLENGTH 8 26 | 27 | struct chunk; 28 | 29 | void chunk_mesher_init(void); 30 | void chunk_mesher_receive(void); 31 | bool chunk_mesher_send(struct chunk* c); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /source/entity/monsters_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | static struct monster monster_zombie = { 21 | .max_health = 160, 22 | .speed = 1, 23 | .width = 1, 24 | .height = 2, 25 | .frame_init = 1, 26 | .frame_alert = 1, 27 | .frame_hurt = 1, 28 | .frame_melee = 1, 29 | .frame_attack = 1, 30 | .frame_death = 1, 31 | }; 32 | 33 | 34 | -------------------------------------------------------------------------------- /source/entity/entity_monster.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | 21 | #ifndef ENTITY_MONSTER_H 22 | #define ENTITY_MONSTER_H 23 | 24 | #include 25 | #include "../cglm/cglm.h" 26 | #include "entity.h" 27 | 28 | enum { 29 | MONSTER_ZOMBIE = 0, 30 | MONSTER_CREEPER = 1, 31 | MONSTER_COUNT 32 | }; 33 | 34 | void entity_monster(uint32_t id, struct entity* e, bool server, void* world, int monster_id); 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /source/daytime.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef DAYTIME_H 21 | #define DAYTIME_H 22 | 23 | #include "cglm/cglm.h" 24 | 25 | #define DAY_TICK_MS 50 26 | #define DAY_LENGTH_TICKS 24000 27 | 28 | float daytime_brightness(float time); 29 | float daytime_celestial_angle(float time); 30 | void daytime_sky_colors(float time, vec3 top_plane, vec3 bottom_plane, 31 | vec3 atmosphere); 32 | float daytime_get_time(void); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/graphics/gfx_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef GFX_UTIL_H 21 | #define GFX_UTIL_H 22 | 23 | #include "../cglm/cglm.h" 24 | 25 | #include "../world.h" 26 | 27 | void gutil_clouds(mat4 view_matrix, float brightness); 28 | void gutil_sky_box(mat4 view_matrix, float celestial_angle, vec3 color_top, 29 | vec3 color_bottom); 30 | void gutil_block_selection(mat4 view_matrix, struct block_info* this); 31 | void gutil_entity_selection(mat4 view_matrix, const struct entity *e); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/platform/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef TIME_H 21 | #define TIME_H 22 | 23 | #include 24 | 25 | #ifdef PLATFORM_WII 26 | typedef uint64_t ptime_t; 27 | #endif 28 | 29 | #ifdef PLATFORM_PC 30 | #include 31 | typedef struct timespec ptime_t; 32 | #endif 33 | 34 | void time_reset(void); 35 | ptime_t time_get(void); 36 | ptime_t time_add_ms(ptime_t t, unsigned int ms); 37 | int32_t time_diff_ms(ptime_t f, ptime_t s); 38 | float time_diff_s(ptime_t f, ptime_t s); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | AlignAfterOpenBracket: Align 4 | AlignConsecutiveAssignments: 'false' 5 | AlignConsecutiveDeclarations: 'false' 6 | AlignTrailingComments: 'true' 7 | AllowAllParametersOfDeclarationOnNextLine: 'true' 8 | AllowShortBlocksOnASingleLine: 'true' 9 | AllowShortCaseLabelsOnASingleLine: 'true' 10 | AllowShortFunctionsOnASingleLine: Empty 11 | AllowShortIfStatementsOnASingleLine: 'false' 12 | AllowShortLoopsOnASingleLine: 'false' 13 | AlwaysBreakAfterDefinitionReturnType: None 14 | AlwaysBreakAfterReturnType: None 15 | AlwaysBreakBeforeMultilineStrings: 'false' 16 | BreakBeforeBraces: Attach 17 | BreakBeforeTernaryOperators: 'false' 18 | Cpp11BracedListStyle: 'true' 19 | ExperimentalAutoDetectBinPacking: 'false' 20 | IndentCaseLabels: 'true' 21 | KeepEmptyLinesAtTheStartOfBlocks: 'false' 22 | Language: Cpp 23 | PointerAlignment: Left 24 | SortIncludes: 'true' 25 | SpaceAfterCStyleCast: 'false' 26 | SpaceBeforeAssignmentOperators: 'true' 27 | SpaceBeforeParens: Never 28 | SpaceInEmptyParentheses: 'false' 29 | SpacesInCStyleCastParentheses: 'false' 30 | SpacesInParentheses: 'false' 31 | SpacesInSquareBrackets: 'false' 32 | TabWidth: '4' 33 | UseTab: Always 34 | MaxEmptyLinesToKeep: 1 35 | ReflowComments: 'true' 36 | ColumnLimit: '80' 37 | 38 | ... 39 | -------------------------------------------------------------------------------- /source/graphics/render_item.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef RENDER_ITEM_H 21 | #define RENDER_ITEM_H 22 | 23 | #include "../cglm/cglm.h" 24 | 25 | #include "../item/items.h" 26 | 27 | void render_item_init(void); 28 | void render_item_update_light(uint8_t light); 29 | void render_item_flat(struct item* item, struct item_data* stack, mat4 view, 30 | bool fullbright, enum render_item_env env); 31 | void render_item_block(struct item* item, struct item_data* stack, mat4 view, 32 | bool fullbright, enum render_item_env env); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/config.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "config.h" 4 | 5 | bool config_create(struct config* c, const char* filename) { 6 | assert(c && filename); 7 | c->root = json_parse_file(filename); 8 | 9 | if(!c->root) 10 | return false; 11 | 12 | if(json_value_get_type(c->root) != JSONObject) { 13 | config_destroy(c); 14 | return false; 15 | } 16 | 17 | return true; 18 | } 19 | 20 | const char* config_read_string(struct config* c, const char* key, 21 | const char* fallback) { 22 | assert(c && key); 23 | // TODO: only give out copy 24 | const char* res = json_object_dotget_string(json_object(c->root), key); 25 | return res ? res : fallback; 26 | } 27 | 28 | bool config_read_int_array(struct config* c, const char* key, int* dest, 29 | size_t* length) { 30 | assert(c && key && dest); 31 | 32 | JSON_Array* entry = json_object_dotget_array(json_object(c->root), key); 33 | 34 | if(!entry) 35 | return false; 36 | 37 | *length = *length < json_array_get_count(entry) ? 38 | *length : 39 | json_array_get_count(entry); 40 | 41 | for(size_t k = 0; k < *length; k++) 42 | dest[k] = json_array_get_number(entry, k); 43 | 44 | return true; 45 | } 46 | 47 | void config_destroy(struct config* c) { 48 | assert(c && c->root); 49 | json_value_free(c->root); 50 | } 51 | -------------------------------------------------------------------------------- /source/item/tool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef TOOL_H 21 | #define TOOL_H 22 | 23 | enum tool_type { 24 | TOOL_TYPE_ANY, 25 | TOOL_TYPE_PICKAXE, 26 | TOOL_TYPE_SHOVEL, 27 | TOOL_TYPE_AXE, 28 | TOOL_TYPE_SWORD, 29 | TOOL_TYPE_HOE, 30 | }; 31 | 32 | enum tool_tier { 33 | TOOL_TIER_ANY, 34 | TOOL_TIER_WOOD, 35 | TOOL_TIER_GOLD, 36 | TOOL_TIER_STONE, 37 | TOOL_TIER_IRON, 38 | TOOL_TIER_DIAMOND, 39 | TOOL_TIER_MAX, 40 | }; 41 | 42 | struct block; 43 | struct item; 44 | 45 | int tool_tier_divider(enum tool_tier tier); 46 | int tool_dig_delay_ms(struct block* type, struct item* it); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /source/network/inventory_logic.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../item/inventory.h" 21 | 22 | bool inventory_collect(struct inventory* inv, struct item_data* item, 23 | uint8_t* slot_priority, size_t slot_length, 24 | set_inv_slot_t changes); 25 | 26 | extern struct inventory_logic inventory_logic_player; 27 | extern struct inventory_logic inventory_logic_crafting; 28 | extern struct inventory_logic inventory_logic_furnace; 29 | extern struct inventory_logic inventory_logic_chest; 30 | extern struct inventory_logic inventory_logic_iron_chest; 31 | extern struct inventory_logic inventory_logic_sign; 32 | 33 | -------------------------------------------------------------------------------- /source/graphics/render_entity.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef RENDER_MINECART_H 21 | #define RENDER_MINECART_H 22 | 23 | #include "../item/items.h" 24 | #include "../platform/gfx.h" 25 | #include "../cglm/types.h" 26 | 27 | typedef struct { 28 | uint8_t u, v, w, h; 29 | } UVRect; 30 | 31 | void render_entity_minecart_init(void); 32 | void render_entity_minecart(mat4 view); 33 | void render_entity_update_light(uint8_t light); 34 | void render_entity_init(void); 35 | void render_entity_creeper(mat4 view, float headYawDeg, float bodyYawDeg, int frame); 36 | void render_entity_pig(mat4 view, float headYawDeg); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /source/graphics/render_model.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef RENDER_MODEL_H 21 | #define RENDER_MODEL_H 22 | 23 | #include "../item/items.h" 24 | #include "../platform/gfx.h" 25 | 26 | void render_model_box(mat4 view, vec3 position, vec3 pivot, vec3 rotation, 27 | ivec2 origin, ivec3 box, float padding, bool mirror, 28 | float brightness); 29 | void render_model_player(mat4 mv, float head_pitch, float head_yaw, 30 | float foot_angle, float arm_angle, 31 | struct item_data* held_item, struct item_data* helmet, 32 | struct item_data* chestplate, 33 | struct item_data* leggings, struct item_data* boots); 34 | 35 | #endif -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | ## Texture licenses 2 | 3 | Please note that the general license of this repository does not apply to the files listed below, which are contained in this directory only. 4 | 5 | #### default.png 6 | 7 | 8x8px tiled bitmap font by xtreme8000. 8 | 9 | License: [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/) 10 | 11 | #### controls.png 12 | 13 | All input icons are from the [WiiBrew wiki](https://wiibrew.org/wiki/Category:Controller_Buttons), and either created by users [Clorox](https://wiibrew.org/wiki/User:Clorox), [Flark](https://wiibrew.org/wiki/User:Flark), [Hiker13526](https://wiibrew.org/wiki/User:Hiker13526) or [Crayon](https://wiibrew.org/wiki/User:Crayon). License seems to be [unknown](https://wiibrew.org/wiki/Category_talk:Controller_Buttons#License). 14 | 15 | #### pointer.png 16 | 17 | Taken from [Homebrew channel](https://github.com/fail0verflow/hbc/tree/master/channel/channelapp/data), licensed GNU GPL v2, according to [wiki](http://wiibrew.org/wiki/Homebrew_Channel) 18 | 19 | #### everything else 20 | 21 | Unless noted otherwise, all remaining textures are from the [Isabella II](http://www.minecraftforum.net/topic/242175-Isabella/) texture pack by Bonemouse, extracted from the "1.2.5 Beta 1" release (`Isabella 2 1.2vb1.zip`). 22 | 23 | License: [Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/) -------------------------------------------------------------------------------- /controls.md: -------------------------------------------------------------------------------- 1 | ## Wii input config mapping 2 | 3 | | Wiimote | config id | 4 | | --- | :-: | 5 | | dpad up | `0` | 6 | | dpad down | `1` | 7 | | dpad left | `2` | 8 | | dpad right | `3` | 9 | | A | `4` | 10 | | B | `5` | 11 | | 1 | `6` | 12 | | 2 | `7` | 13 | | plus | `8` | 14 | | minus | `9` | 15 | | home | `10` | 16 | 17 | | Nunchuk | config id | 18 | | --- | :-: | 19 | | Z | `100` | 20 | | C | `101` | 21 | | joystick up | `900` | 22 | | joystick down | `901` | 23 | | joystick left | `902` | 24 | | joystick right | `903` | 25 | 26 | | Classic controller | config id | 27 | | --- | :-: | 28 | | dpad up | `200` | 29 | | dpad down | `201` | 30 | | dpad left | `202` | 31 | | dpad right | `203` | 32 | | A | `204` | 33 | | B | `205` | 34 | | X | `206` | 35 | | Y | `207` | 36 | | Z left | `208` | 37 | | Z right | `209` | 38 | | L full | `210` | 39 | | R full | `211` | 40 | | plus | `212` | 41 | | minus | `213` | 42 | | home | `214` | 43 | | L joystick up | `910` | 44 | | L joystick down | `911` | 45 | | L joystick left | `912` | 46 | | L joystick right | `913` | 47 | | R joystick up | `920` | 48 | | R joystick down | `921` | 49 | | R joystick left | `922` | 50 | | R joystick right | `923` | 51 | 52 | | Guitar Hero 3 | config id | 53 | | --- | :-: | 54 | | yellow | `300` | 55 | | green | `301` | 56 | | blue | `302` | 57 | | red | `303` | 58 | | orange | `304` | 59 | | plus | `305` | 60 | | minus | `306` | 61 | | strum up | `307` | 62 | | strum down | `308` | 63 | -------------------------------------------------------------------------------- /source/stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef STACK_H 21 | #define STACK_H 22 | 23 | #include 24 | #include 25 | 26 | struct stack { 27 | size_t length; 28 | size_t index; 29 | size_t element_size; 30 | void* data; 31 | }; 32 | 33 | void stack_create(struct stack* stk, size_t inital_size, size_t element_size); 34 | 35 | void stack_push(struct stack* stk, void* obj); 36 | 37 | bool stack_empty(struct stack* stk); 38 | 39 | size_t stack_size(struct stack* stk); 40 | 41 | void stack_at(struct stack* stk, void* obj, size_t index); 42 | 43 | bool stack_pop(struct stack* stk, void* obj); 44 | 45 | void stack_clear(struct stack* stk); 46 | 47 | void stack_destroy(struct stack* stk); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /source/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef HASH_H 21 | #define HASH_H 22 | 23 | #include 24 | #include 25 | 26 | #include "platform/time.h" 27 | 28 | struct random_gen { 29 | uint32_t seed; 30 | }; 31 | 32 | void rand_gen_seed(struct random_gen* g); 33 | uint32_t rand_gen(struct random_gen* g); 34 | int rand_gen_range(struct random_gen* g, int min, int max); 35 | float rand_gen_flt(struct random_gen* g); 36 | int rand_gen_int(struct random_gen* g, int max); 37 | 38 | 39 | void* file_read(const char* name); 40 | 41 | uint32_t hash_u32(uint32_t x); 42 | 43 | void hsv2rgb(float* h, float* s, float* v); 44 | 45 | uint8_t nibble_read(uint8_t* base, size_t idx); 46 | void nibble_write(uint8_t* base, size_t idx, uint8_t data); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /source/item/items/item_fish.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | server_local_set_player_health(s, s->player.health-16); 28 | return true; 29 | } 30 | 31 | struct item item_fish = { 32 | .name = "Raw Fish", 33 | .has_damage = false, 34 | .max_stack = 1, 35 | .fuel = 0, 36 | .renderItem = render_item_flat, 37 | .onItemPlace = onItemPlace, 38 | .armor.is_armor = false, 39 | .tool.type = TOOL_TYPE_ANY, 40 | .render_data = { 41 | .item = { 42 | .texture_x = 9, 43 | .texture_y = 5, 44 | }, 45 | }, 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /source/block/face_occlusion.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef FACE_OCCLUSION_H 21 | #define FACE_OCCLUSION_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #define FACE_OCCLUSION_SIZE (16 * 16) 28 | #define FACE_OCCLUSION_ARR_LENGTH \ 29 | ((FACE_OCCLUSION_SIZE + (sizeof(uint32_t) * 8) - 1) \ 30 | / (sizeof(uint32_t) * 8)) 31 | 32 | struct face_occlusion { 33 | uint32_t mask[FACE_OCCLUSION_ARR_LENGTH]; 34 | }; 35 | 36 | struct face_occlusion* face_occlusion_full(); 37 | struct face_occlusion* face_occlusion_empty(); 38 | struct face_occlusion* face_occlusion_rect(int size); 39 | 40 | bool face_occlusion_test(struct face_occlusion* a, struct face_occlusion* b); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /source/item/items/item_porkchop.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | server_local_set_player_health(s, s->player.health-16); 28 | return true; 29 | } 30 | 31 | struct item item_porkchop = { 32 | .name = "Raw Porkchop", 33 | .has_damage = false, 34 | .max_stack = 64, 35 | .fuel = 0, 36 | .renderItem = render_item_flat, 37 | .onItemPlace = onItemPlace, 38 | .armor.is_armor = false, 39 | .tool.type = TOOL_TYPE_ANY, 40 | .render_data = { 41 | .item = { 42 | .texture_x = 7, 43 | .texture_y = 5, 44 | }, 45 | }, 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /source/item/recipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef RECIPE_H 21 | #define RECIPE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "items.h" 29 | 30 | struct recipe { 31 | struct item_data result; 32 | size_t width, height; 33 | struct recipe_ingredients { 34 | struct item_data item; 35 | bool match_durability; 36 | } shape[9]; 37 | }; 38 | 39 | ARRAY_DEF(array_recipe, struct recipe, M_POD_OPLIST) 40 | 41 | extern array_recipe_t recipes_crafting; 42 | 43 | void recipe_init(void); 44 | void recipe_add(array_recipe_t recipes, struct item_data result, size_t width, 45 | size_t height, uint8_t* shape, ...); 46 | bool recipe_match(array_recipe_t recipes, struct item_data slots[9], 47 | bool slot_empty[9], struct item_data* result); 48 | 49 | #endif -------------------------------------------------------------------------------- /source/network/complex_block_archive.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef COMPLEX_BLOCK_ARCHIVE_H 21 | #define COMPLEX_BLOCK_ARCHIVE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "../cNBT/nbt.h" 30 | #include "../cglm/cglm.h" 31 | 32 | #include "../item/inventory.h" 33 | #include "../item/items.h" 34 | #include "../world.h" 35 | #include "server_local.h" 36 | 37 | void chest_archive_read(struct complex_block_pos* pos, struct item_data* items, string_t path); 38 | void chest_archive_write(struct complex_block_pos* pos, struct item_data* items, string_t path); 39 | void sign_archive_read(struct complex_block_pos* pos, char* texts, string_t path); 40 | void sign_archive_write(struct complex_block_pos* pos, char* texts, string_t path); 41 | #endif 42 | -------------------------------------------------------------------------------- /.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /source/lighting.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef LIGHTING_H 21 | #define LIGHTING_H 22 | 23 | #include "world.h" 24 | 25 | struct world_modification_entry { 26 | w_coord_t x, y, z; 27 | struct block_data blk; 28 | }; 29 | 30 | void lighting_heightmap_update(uint8_t* heightmap, c_coord_t x, w_coord_t y, 31 | c_coord_t z, uint8_t type, 32 | bool (*get_block)(void* user, c_coord_t x, 33 | w_coord_t y, c_coord_t z, 34 | struct block_data* blk), 35 | void* user); 36 | 37 | void lighting_update_at_block( 38 | struct world_modification_entry source, bool ignore_sky_light, 39 | bool (*get_block)(void* user, w_coord_t x, w_coord_t y, w_coord_t z, 40 | struct block_data* blk, uint8_t* height), 41 | void (*set_light)(void* user, w_coord_t x, w_coord_t y, w_coord_t z, 42 | uint8_t light), 43 | void* user); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /source/item/items/item_apple.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | if (s->player.health >= MAX_PLAYER_HEALTH) return false; 28 | 29 | server_local_set_player_health(s, s->player.health+2*HEALTH_PER_HEART); 30 | return true; 31 | } 32 | 33 | struct item item_apple = { 34 | .name = "Apple", 35 | .has_damage = false, 36 | .max_stack = 1, 37 | .fuel = 0, 38 | .renderItem = render_item_flat, 39 | .onItemPlace = onItemPlace, 40 | .armor.is_armor = false, 41 | .tool.type = TOOL_TYPE_ANY, 42 | .render_data = { 43 | .item = { 44 | .texture_x = 10, 45 | .texture_y = 0, 46 | }, 47 | }, 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /source/item/items/item_apple_golden.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | if (s->player.health >= MAX_PLAYER_HEALTH) return false; 28 | 29 | server_local_set_player_health(s, MAX_PLAYER_HEALTH); 30 | return true; 31 | } 32 | 33 | struct item item_apple_golden = { 34 | .name = "Golden Apple", 35 | .has_damage = false, 36 | .max_stack = 1, 37 | .fuel = 0, 38 | .renderItem = render_item_flat, 39 | .onItemPlace = onItemPlace, 40 | .armor.is_armor = false, 41 | .tool.type = TOOL_TYPE_ANY, 42 | .render_data = { 43 | .item = { 44 | .texture_x = 11, 45 | .texture_y = 0, 46 | }, 47 | }, 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /source/item/items/item_fish_cooked.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | if (s->player.health >= MAX_PLAYER_HEALTH) return false; 28 | 29 | server_local_set_player_health(s, s->player.health+3*HEALTH_PER_HEART); 30 | return true; 31 | } 32 | 33 | struct item item_fish_cooked = { 34 | .name = "Cooked Fish", 35 | .has_damage = false, 36 | .max_stack = 1, 37 | .fuel = 0, 38 | .renderItem = render_item_flat, 39 | .onItemPlace = onItemPlace, 40 | .armor.is_armor = false, 41 | .tool.type = TOOL_TYPE_ANY, 42 | .render_data = { 43 | .item = { 44 | .texture_x = 10, 45 | .texture_y = 5, 46 | }, 47 | }, 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /source/item/items/item_bread.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | if (s->player.health >= MAX_PLAYER_HEALTH) return false; 28 | 29 | server_local_set_player_health(s, s->player.health+2*HEALTH_PER_HEART+(HEALTH_PER_HEART/2)); 30 | return true; 31 | } 32 | 33 | struct item item_bread = { 34 | .name = "Bread", 35 | .has_damage = false, 36 | .max_stack = 64, 37 | .fuel = 0, 38 | .renderItem = render_item_flat, 39 | .onItemPlace = onItemPlace, 40 | .armor.is_armor = false, 41 | .tool.type = TOOL_TYPE_ANY, 42 | .render_data = { 43 | .item = { 44 | .texture_x = 9, 45 | .texture_y = 2, 46 | }, 47 | }, 48 | }; 49 | 50 | 51 | -------------------------------------------------------------------------------- /source/item/items/item_porkchop_cooked.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | if (s->player.health >= MAX_PLAYER_HEALTH) return false; 28 | 29 | server_local_set_player_health(s, s->player.health+4*HEALTH_PER_HEART); 30 | return true; 31 | } 32 | 33 | struct item item_porkchop_cooked = { 34 | .name = "Cooked Porkchop", 35 | .has_damage = false, 36 | .max_stack = 64, 37 | .fuel = 0, 38 | .renderItem = render_item_flat, 39 | .onItemPlace = onItemPlace, 40 | .armor.is_armor = false, 41 | .tool.type = TOOL_TYPE_ANY, 42 | .render_data = { 43 | .item = { 44 | .texture_x = 7, 45 | .texture_y = 5, 46 | }, 47 | }, 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /source/item/items/item_egg_zombie.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | #include "../../entity/entity_monster.h" 24 | 25 | 26 | static bool onItemPlace(struct server_local* s, struct item_data* it, 27 | struct block_info* where, struct block_info* on, 28 | enum side on_side) { 29 | server_local_spawn_monster((vec3) {where->x, where->y, where->z}, MONSTER_CREEPER, s); 30 | return false; // spawn eggs have infinite uses 31 | } 32 | 33 | struct item item_egg_zombie = { 34 | .name = "Zombie Egg", 35 | .has_damage = false, 36 | .max_stack = 64, 37 | .fuel = 0, 38 | .renderItem = render_item_flat, 39 | .onItemPlace = onItemPlace, 40 | .armor.is_armor = false, 41 | .tool.type = TOOL_TYPE_ANY, 42 | .render_data = { 43 | .item = { 44 | .texture_x = 8, 45 | .texture_y = 4, 46 | }, 47 | }, 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /source/block/aabb.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef AABB_H 21 | #define AABB_H 22 | 23 | #include 24 | 25 | struct AABB { 26 | float x1, y1, z1; 27 | float x2, y2, z2; 28 | }; 29 | 30 | struct ray { 31 | float x, y, z; 32 | float dx, dy, dz; 33 | }; 34 | 35 | #include "blocks_data.h" 36 | 37 | void aabb_setsize(struct AABB* a, float sx, float sy, float sz); 38 | void aabb_setsize_centered(struct AABB* a, float sx, float sy, float sz); 39 | void aabb_translate(struct AABB* a, float x, float y, float z); 40 | bool aabb_intersection_ray(struct AABB* a, struct ray* r, enum side* s); 41 | bool aabb_intersection(struct AABB* a, struct AABB* b); 42 | bool aabb_intersection_point(struct AABB* a, float x, float y, float z); 43 | void aabb_setsize_centered_offset(struct AABB* a, 44 | float sx, float sy, float sz, 45 | float ox, float oy, float oz); 46 | #endif 47 | -------------------------------------------------------------------------------- /source/platform/displaylist.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef DISPLAYLIST_H 21 | #define DISPLAYLIST_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | struct displaylist { 28 | void* data; 29 | size_t length; 30 | size_t index; 31 | bool finished; 32 | #ifdef PLATFORM_PC 33 | int vbo; 34 | #endif 35 | }; 36 | 37 | void displaylist_init(struct displaylist* l, size_t vertices, 38 | size_t vertex_size); 39 | void displaylist_destroy(struct displaylist* l); 40 | void displaylist_reset(struct displaylist* l); 41 | void displaylist_finalize(struct displaylist* l, uint16_t vtxcnt); 42 | void displaylist_render(struct displaylist* l); 43 | void displaylist_render_immediate(struct displaylist* l, uint16_t vtxcnt); 44 | 45 | void displaylist_pos(struct displaylist* l, int16_t x, int16_t y, int16_t z); 46 | void displaylist_color(struct displaylist* l, uint8_t index); 47 | void displaylist_texcoord(struct displaylist* l, uint8_t s, uint8_t t); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /source/game/camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef CAMERA_H 21 | #define CAMERA_H 22 | 23 | #include 24 | 25 | #include "../cglm/cglm.h" 26 | #include "../entity/entity.h" 27 | 28 | struct camera { 29 | float x, y, z; 30 | float rx, ry; 31 | mat4 view, projection; 32 | vec4 frustum_planes[6]; 33 | struct camera_controller { 34 | float vx, vy, vz; 35 | } controller; 36 | }; 37 | 38 | 39 | struct camera_ray_result { 40 | bool hit; 41 | w_coord_t x, y, z; 42 | enum side side; 43 | bool entity_hit; 44 | uint32_t entity_id; 45 | }; 46 | 47 | void camera_ray_pick(struct world* w, float gx0, float gy0, float gz0, 48 | float gx1, float gy1, float gz1, 49 | struct camera_ray_result* res); 50 | void camera_physics(struct camera* c, float dt); 51 | void camera_update(struct camera* c, bool in_water); 52 | void camera_attach(struct camera* c, struct entity* e, float tick_delta, 53 | float dt); 54 | void camera_get_ray(const struct camera *c, vec3 origin, vec3 dir); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /source/item/items/item_mushroom_stew.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) { 27 | if (s->player.health >= MAX_PLAYER_HEALTH) return false; 28 | 29 | server_local_set_player_health(s, s->player.health+5*HEALTH_PER_HEART); 30 | server_local_spawn_item((vec3) {where->x, where->y, where->z}, 31 | &(struct item_data) { 32 | .id = ITEM_BOWL, 33 | .durability = 0, 34 | .count = 1 35 | }, false, s); 36 | return true; 37 | } 38 | 39 | struct item item_mushroom_stew = { 40 | .name = "Mushroom Stew", 41 | .has_damage = false, 42 | .max_stack = 1, 43 | .fuel = 0, 44 | .renderItem = render_item_flat, 45 | .onItemPlace = onItemPlace, 46 | .armor.is_armor = false, 47 | .tool.type = TOOL_TYPE_ANY, 48 | .render_data = { 49 | .item = { 50 | .texture_x = 8, 51 | .texture_y = 4, 52 | }, 53 | }, 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /source/platform/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef THREAD_H 21 | #define THREAD_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef PLATFORM_PC 28 | #include 29 | 30 | struct thread { 31 | pthread_t native; 32 | }; 33 | 34 | struct thread_channel { 35 | pthread_mutex_t lock; 36 | pthread_cond_t signal; 37 | void** data; 38 | size_t count; 39 | size_t length; 40 | }; 41 | 42 | #endif 43 | 44 | #ifdef PLATFORM_WII 45 | #include 46 | 47 | struct thread { 48 | lwp_t native; 49 | }; 50 | 51 | struct thread_channel { 52 | mqbox_t native; 53 | }; 54 | #endif 55 | 56 | void thread_create(struct thread* t, void* (*entry)(void* arg), void* arg, 57 | uint8_t priority); 58 | void thread_join(struct thread* t); 59 | void thread_msleep(size_t ms); 60 | 61 | void tchannel_init(struct thread_channel* c, size_t count); 62 | void tchannel_close(struct thread_channel* c); 63 | bool tchannel_receive(struct thread_channel* c, void** msg, bool block); 64 | bool tchannel_send(struct thread_channel* c, void* msg, bool block); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /source/item/items/item_sugarcane.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | 22 | static bool onItemPlace(struct server_local* s, struct item_data* it, 23 | struct block_info* where, struct block_info* on, 24 | enum side on_side) { 25 | struct block_data blk; 26 | if(!server_world_get_block(&s->world, where->x, where->y - 1, where->z, 27 | &blk)) 28 | return false; 29 | 30 | if(blk.type != BLOCK_DIRT && blk.type != BLOCK_GRASS 31 | && blk.type != BLOCK_REED) 32 | return false; 33 | 34 | return block_place_default(s, 35 | &(struct item_data) { 36 | .id = BLOCK_REED, 37 | .durability = 0, 38 | }, 39 | where, on, on_side); 40 | } 41 | 42 | struct item item_sugarcane = { 43 | .name = "Sugarcane", 44 | .has_damage = false, 45 | .max_stack = 64, 46 | .fuel = 0, 47 | .renderItem = render_item_flat, 48 | .onItemPlace = onItemPlace, 49 | .armor.is_armor = false, 50 | .tool.type = TOOL_TYPE_ANY, 51 | .render_data = { 52 | .item = { 53 | .texture_x = 11, 54 | .texture_y = 1, 55 | }, 56 | }, 57 | }; 58 | -------------------------------------------------------------------------------- /source/graphics/gui_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef GUI_UTIL_H 21 | #define GUI_UTIL_H 22 | 23 | #include 24 | #include 25 | 26 | #include "../item/items.h" 27 | #include "../platform/input.h" 28 | #include "../platform/texture.h" 29 | 30 | int gutil_control_icon(int x, enum input_button b, const char* str); 31 | void gutil_texquad_col(int x, int y, int tx, int ty, int sx, int sy, int width, 32 | int height, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 33 | void gutil_texquad(int x, int y, int tx, int ty, int sx, int sy, int width, 34 | int height); 35 | void gutil_texquad_rt(int x, int y, int tx, int ty, int sx, int sy, int width, 36 | int height); 37 | void gutil_texquad_rt_any(int x, int y, float angle, int tx, int ty, int sx, 38 | int sy, float width, float height); 39 | void gutil_bg(void); 40 | void gutil_reset_font(struct tex_gfx* tex); 41 | int gutil_font_width(const char* str, int scale); 42 | void gutil_text(int x, int y, const char* str, int scale, bool shadow); 43 | void gutil_draw_item(struct item_data* item, int x, int y, int layer); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /source/platform/input.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef INPUT_H 21 | #define INPUT_H 22 | 23 | #include 24 | 25 | enum input_button { 26 | IB_FORWARD, 27 | IB_BACKWARD, 28 | IB_LEFT, 29 | IB_RIGHT, 30 | IB_ACTION1, 31 | IB_ACTION2, 32 | IB_JUMP, 33 | IB_SNEAK, 34 | IB_INVENTORY, 35 | IB_HOME, 36 | IB_SCROLL_LEFT, 37 | IB_SCROLL_RIGHT, 38 | IB_GUI_UP, 39 | IB_GUI_DOWN, 40 | IB_GUI_LEFT, 41 | IB_GUI_RIGHT, 42 | IB_GUI_CLICK, 43 | IB_GUI_CLICK_ALT, 44 | IB_SCREENSHOT, 45 | }; 46 | 47 | enum input_category { 48 | INPUT_CAT_WIIMOTE, 49 | INPUT_CAT_NUNCHUK, 50 | INPUT_CAT_CLASSIC_CONTROLLER, 51 | INPUT_CAT_NONE, 52 | }; 53 | 54 | void input_init(void); 55 | void input_poll(void); 56 | 57 | bool input_symbol(enum input_button b, int* symbol, int* symbol_help, 58 | enum input_category* category); 59 | bool input_pressed(enum input_button b); 60 | bool input_released(enum input_button b); 61 | bool input_held(enum input_button b); 62 | bool input_joystick(float dt, float* x, float* y); 63 | void input_pointer_enable(bool enable); 64 | bool input_pointer(float* x, float* y, float* angle); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /source/network/server_interface.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "../platform/thread.h" 23 | #include "server_interface.h" 24 | 25 | #define RPC_INBOX_SIZE 16 26 | static struct server_rpc rpc_msg[RPC_INBOX_SIZE]; 27 | static struct thread_channel svin_inbox; 28 | static struct thread_channel svin_empty_msg; 29 | 30 | void svin_init() { 31 | tchannel_init(&svin_inbox, RPC_INBOX_SIZE); 32 | tchannel_init(&svin_empty_msg, RPC_INBOX_SIZE); 33 | 34 | for(int k = 0; k < RPC_INBOX_SIZE; k++) 35 | tchannel_send(&svin_empty_msg, rpc_msg + k, true); 36 | } 37 | 38 | void svin_process_messages(void (*process)(struct server_rpc*, void*), 39 | void* user, bool block) { 40 | assert(process); 41 | 42 | void* call; 43 | while(tchannel_receive(&svin_inbox, &call, block)) { 44 | process(call, user); 45 | tchannel_send(&svin_empty_msg, call, true); 46 | } 47 | } 48 | 49 | void svin_rpc_send(struct server_rpc* call) { 50 | assert(call); 51 | 52 | struct server_rpc* empty; 53 | tchannel_receive(&svin_empty_msg, (void**)&empty, true); 54 | *empty = *call; 55 | tchannel_send(&svin_inbox, empty, true); 56 | } 57 | -------------------------------------------------------------------------------- /source/game/gui/screen.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef SCREEN_H 21 | #define SCREEN_H 22 | 23 | #include 24 | 25 | #include "../../cglm/cglm.h" 26 | 27 | struct screen { 28 | void (*reset)(struct screen* s, int width, int height); 29 | void (*update)(struct screen* s, float dt); 30 | void (*render2D)(struct screen* s, int width, int height); 31 | void (*render3D)(struct screen* s, mat4 view); 32 | bool render_world; 33 | }; 34 | 35 | extern struct screen screen_ingame; 36 | extern struct screen screen_load_world; 37 | extern struct screen screen_select_world; 38 | extern struct screen screen_inventory; 39 | extern struct screen screen_crafting; 40 | extern struct screen screen_furnace; 41 | extern struct screen screen_chest; 42 | extern struct screen screen_iron_chest; 43 | extern struct screen screen_sign; 44 | extern struct screen screen_pause; 45 | 46 | void screen_set(struct screen* s); 47 | 48 | void screen_crafting_set_windowc(uint8_t container); 49 | void screen_furnace_set_windowc(uint8_t container); 50 | void screen_chest_set_windowc(uint8_t container); 51 | void screen_iron_chest_set_windowc(uint8_t container); 52 | void screen_sign_set_windowc(uint8_t container); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /source/item/tool.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "../block/blocks.h" 23 | 24 | int tool_tier_divider(enum tool_tier tier) { 25 | switch(tier) { 26 | case TOOL_TIER_WOOD: return 2; 27 | case TOOL_TIER_STONE: return 4; 28 | case TOOL_TIER_IRON: return 6; 29 | case TOOL_TIER_DIAMOND: return 8; 30 | case TOOL_TIER_GOLD: return 12; 31 | default: return 1; 32 | } 33 | } 34 | 35 | int tool_dig_delay_ms(struct block* type, struct item* it) { 36 | assert(type); 37 | 38 | if(type->digging.hardness <= 0) 39 | return -1; 40 | 41 | enum tool_type item_type = it ? it->tool.type : TOOL_TYPE_ANY; 42 | enum tool_tier item_tier 43 | = (it && item_type != TOOL_TYPE_ANY) ? it->tool.tier : TOOL_TIER_ANY; 44 | 45 | int delay = type->digging.hardness; 46 | 47 | if(type->digging.tool == item_type && item_tier >= type->digging.min) { 48 | delay /= tool_tier_divider( 49 | item_tier > type->digging.best ? type->digging.best : item_tier); 50 | } else if(item_type == TOOL_TYPE_SWORD) { 51 | delay = delay * 2 / 3; 52 | } else if(type->digging.min != TOOL_TIER_ANY) { 53 | delay = delay * 10 / 3; 54 | } 55 | 56 | return (delay + 49) / 50 * 50; // round up to next tick 57 | } 58 | -------------------------------------------------------------------------------- /source/item/items/item_minecart.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | 24 | static bool onItemPlace(struct server_local* s, struct item_data* it, 25 | struct block_info* where, struct block_info* on, 26 | enum side on_side) 27 | { 28 | // only place on rails 29 | if (!on || on->block->type != BLOCK_RAIL) return false; 30 | 31 | // compute spawn position: center of rail 32 | vec3 pos = { 33 | on->x + 0.5f, 34 | on->y + 0.1f, 35 | on->z + 0.5f 36 | }; 37 | 38 | // server side: spawn a minecart entity 39 | server_local_spawn_minecart(pos, s); 40 | 41 | return true; 42 | } 43 | 44 | struct item item_minecart = { 45 | .name = "Minecart", 46 | .has_damage = false, 47 | .max_stack = 64, // should be 1 48 | .fuel = 0, 49 | .renderItem = render_item_flat, 50 | .onItemPlace = onItemPlace, 51 | .armor.is_armor = false, 52 | .tool.type = TOOL_TYPE_ANY, 53 | .render_data = { 54 | .item = { 55 | .texture_x = 7, 56 | .texture_y = 8, 57 | }, 58 | }, 59 | }; 60 | -------------------------------------------------------------------------------- /source/platform/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "time.h" 21 | 22 | #ifdef PLATFORM_PC 23 | 24 | #include 25 | 26 | void time_reset() { } 27 | 28 | ptime_t time_get() { 29 | struct timespec t; 30 | clock_gettime(CLOCK_MONOTONIC_RAW, &t); 31 | return t; 32 | } 33 | 34 | ptime_t time_add_ms(ptime_t t, unsigned int ms) { 35 | uint64_t ns = t.tv_nsec + ms * 1000000LL; 36 | t.tv_sec += ns / 1000000000LL; 37 | t.tv_nsec = ns % 1000000000LL; 38 | return t; 39 | } 40 | 41 | int32_t time_diff_ms(ptime_t f, ptime_t s) { 42 | return (s.tv_sec - f.tv_sec) * 1000 + (s.tv_nsec - f.tv_nsec) / 1000000; 43 | } 44 | 45 | float time_diff_s(ptime_t f, ptime_t s) { 46 | return (float)(s.tv_sec - f.tv_sec) 47 | + (float)(s.tv_nsec - f.tv_nsec) / 1000000000.0F; 48 | } 49 | 50 | #endif 51 | 52 | #ifdef PLATFORM_WII 53 | 54 | #include 55 | 56 | void time_reset() { 57 | settime(0); 58 | } 59 | 60 | ptime_t time_get() { 61 | return gettime(); 62 | } 63 | 64 | ptime_t time_add_ms(ptime_t t, unsigned int ms) { 65 | return t + TB_TIMER_CLOCK * ms; 66 | } 67 | 68 | int32_t time_diff_ms(ptime_t f, ptime_t s) { 69 | return (s - f) / TB_TIMER_CLOCK; 70 | } 71 | 72 | float time_diff_s(ptime_t f, ptime_t s) { 73 | return (float)(s - f) / (float)(1000UL * TB_TIMER_CLOCK); 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /source/item/items/item_redstone.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | 22 | static bool onItemPlace(struct server_local* s, struct item_data* it, 23 | struct block_info* where, struct block_info* on, 24 | enum side on_side) { 25 | if (!on || !on->block) return false; 26 | if (on_side != SIDE_TOP) return false; 27 | 28 | int tx = on->x; 29 | int ty = on->y + 1; 30 | int tz = on->z; 31 | 32 | /* struct block_data below; 33 | if (!server_world_get_block(&s->world, where->x, where->y - 1, where->z, &below)) 34 | return false; 35 | if (!blocks[below.type] || blocks[below.type]->can_see_through) 36 | return false; 37 | */ 38 | server_world_set_block(s, tx, ty, tz, (struct block_data) { 39 | .type = BLOCK_REDSTONE_WIRE, 40 | .metadata = 0, 41 | .sky_light = 0, 42 | .torch_light = 0, 43 | }); 44 | 45 | return true; 46 | } 47 | 48 | struct item item_redstone = { 49 | .name = "Redstone", 50 | .has_damage = false, 51 | .max_stack = 64, 52 | .fuel = 0, 53 | .renderItem = render_item_flat, 54 | .onItemPlace = onItemPlace, 55 | .armor.is_armor = false, 56 | .tool.type = TOOL_TYPE_ANY, 57 | .render_data = { 58 | .item = { 59 | .texture_x = 8, 60 | .texture_y = 3, 61 | }, 62 | }, 63 | }; 64 | -------------------------------------------------------------------------------- /source/graphics/gfx_settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | 21 | #ifndef GFX_SETTINGS_H 22 | #define GFX_SETTINGS_H 23 | 24 | /* 25 | This file is used to set video settings at compile time. 26 | To disable a setting, comment its line out and recompile. 27 | To enable a setting, uncomment its line and recompile. 28 | Some settings cannot be disabled or enabled, as they are a number (like resolution or GUI scale). 29 | */ 30 | 31 | //Render clouds 32 | #define GFX_CLOUDS 33 | 34 | //Render double-sided faces (tall grass, sugar cane and similar blocks) 35 | #define GFX_DOUBLESIDED 36 | 37 | //Transparent and animated liquids (can heavily impact FPS on low-end GPUs) 38 | #define GFX_FANCY_LIQUIDS 39 | 40 | //fancy 3d elements 41 | #define GFX_3D_ELEMENTS 42 | 43 | //Scale HUD and GUIs (the higher the number, the bigger the GUI). 44 | //For 640x480, setting this to 2 is recommended. 45 | //For 320x240, setting this to 1 is recommended. 46 | //Do not set this to anything less to 1. 47 | #define GFX_GUI_SCALE 2 48 | 49 | //PC only: default window width and height (rendering resolution) 50 | #define GFX_PC_WINDOW_WIDTH 640 51 | #define GFX_PC_WINDOW_HEIGHT 400 52 | 53 | // TODO: 240p on Wii? 54 | 55 | //PC only: render polygons as wireframes (will break text and texture rendering, for testing purposes only) 56 | //#define GFX_WIREFRAME 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /source/item/window_container.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef WINDOW_CONTAINER_H 21 | #define WINDOW_CONTAINER_H 22 | 23 | #include 24 | #include 25 | 26 | #include "inventory.h" 27 | 28 | #define WINDOWC_INVENTORY 0 29 | 30 | // local server use only 31 | #define WINDOWC_CHEST 0 32 | #define WINDOWC_CRAFTING 1 33 | #define WINDOWC_FURNACE 2 34 | #define WINDOWC_IRON_CHEST 4 35 | #define WINDOWC_SIGN 5 36 | 37 | enum window_type { 38 | WINDOW_TYPE_CHEST = 0, 39 | WINDOW_TYPE_WORKBENCH = 1, 40 | WINDOW_TYPE_FURNACE = 2, 41 | WINDOW_TYPE_DISPENSER = 3, 42 | WINDOW_TYPE_IRON_CHEST = 4, 43 | WINDOW_TYPE_SIGN = 5, 44 | WINDOW_TYPE_INVENTORY = 255, 45 | }; 46 | 47 | struct window_container { 48 | enum window_type type; 49 | size_t slot_count; 50 | uint16_t next_action_id; 51 | ilist_inventory_t invs; 52 | }; 53 | 54 | bool windowc_create(struct window_container* wc, enum window_type type, 55 | size_t slot_count); 56 | void windowc_destroy(struct window_container* wc); 57 | 58 | struct inventory* windowc_get_latest(struct window_container* wc); 59 | bool windowc_new_action(struct window_container* wc, uint16_t* action_id, 60 | bool action_type, size_t action_slot); 61 | void windowc_action_apply_result(struct window_container* wc, 62 | uint16_t action_id, bool accept); 63 | void windowc_slot_change(struct window_container* wc, size_t slot, 64 | struct item_data item); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /source/network/region_archive.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef REGION_ARCHIVE_H 21 | #define REGION_ARCHIVE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../world.h" 29 | 30 | struct server_chunk; 31 | 32 | struct region_archive { 33 | w_coord_t x, z; 34 | uint32_t* offsets; 35 | uint32_t* occupied_sorted; 36 | size_t occupied_index; 37 | string_t file_name; 38 | ILIST_INTERFACE(ilist_regions, struct region_archive); 39 | }; 40 | 41 | ILIST_DEF(ilist_regions, struct region_archive, M_POD_OPLIST) 42 | 43 | #define REGION_SIZE 32 44 | #define REGION_SIZE_BITS 5 45 | #define REGION_SECTOR_SIZE 4096 46 | 47 | #define CHUNK_REGION_COORD(x) ((w_coord_t)floor(x / (float)REGION_SIZE)) 48 | 49 | bool region_archive_create_new(struct region_archive* ra, string_t world_name, 50 | w_coord_t x, w_coord_t z, 51 | enum world_dim dimension); 52 | bool region_archive_create(struct region_archive* ra, string_t world_name, 53 | w_coord_t x, w_coord_t z, enum world_dim dimension); 54 | void region_archive_destroy(struct region_archive* ra); 55 | bool region_archive_contains(struct region_archive* ra, w_coord_t x, 56 | w_coord_t z, bool* chunk_exists); 57 | bool region_archive_get_blocks(struct region_archive* ra, w_coord_t x, 58 | w_coord_t z, struct server_chunk* sc); 59 | bool region_archive_set_blocks(struct region_archive* ra, w_coord_t x, 60 | w_coord_t z, struct server_chunk* sc); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /source/network/server_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef SERVER_INTERFACE_H 21 | #define SERVER_INTERFACE_H 22 | 23 | #include "../world.h" 24 | #include 25 | #include 26 | 27 | #define MAX_PLAYER_HEALTH 160 28 | #define HEALTH_PER_HEART 16 29 | 30 | enum server_rpc_type { 31 | SRPC_PLAYER_POS, 32 | SRPC_LOAD_WORLD, 33 | SRPC_ENTITY_ATTACK, 34 | SRPC_UNLOAD_WORLD, 35 | SRPC_HOTBAR_SLOT, 36 | SRPC_BLOCK_PLACE, 37 | SRPC_BLOCK_DIG, 38 | SRPC_WINDOW_CLICK, 39 | SRPC_WINDOW_CLOSE, 40 | SRPC_TOGGLE_PAUSE, 41 | }; 42 | 43 | struct server_rpc { 44 | enum server_rpc_type type; 45 | union { 46 | struct { 47 | double x, y, z; 48 | float rx, ry; 49 | float vel_y; 50 | } player_pos; 51 | struct { 52 | string_t name; 53 | } load_world; 54 | struct { 55 | w_coord_t x, y, z; 56 | enum side side; 57 | } block_place; 58 | struct { 59 | bool finished; 60 | w_coord_t x, y, z; 61 | enum side side; 62 | } block_dig; 63 | struct { 64 | size_t slot; 65 | } hotbar_slot; 66 | struct { 67 | uint8_t window; 68 | uint8_t slot; 69 | bool right_click; 70 | uint16_t action_id; 71 | } window_click; 72 | struct { 73 | uint8_t window; 74 | } window_close; 75 | struct { 76 | uint32_t entity_id; 77 | } entity_attack; 78 | } payload; 79 | }; 80 | 81 | void svin_init(void); 82 | void svin_process_messages(void (*process)(struct server_rpc*, void*), 83 | void* user, bool block); 84 | void svin_rpc_send(struct server_rpc* call); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /source/item/items/item_seeds.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | #include "../../block/blocks.h" 24 | 25 | static bool onItemPlace(struct server_local* s, struct item_data* it, 26 | struct block_info* where, struct block_info* on, 27 | enum side on_side) { 28 | if (!on || !on->block) return false; 29 | 30 | // only sow on farmland on top soil 31 | if (on->block->type != BLOCK_FARMLAND || on_side != SIDE_TOP) 32 | return false; 33 | 34 | int tx = on->x; 35 | int ty = on->y + 1; 36 | int tz = on->z; 37 | 38 | // check if there's air above the crop 39 | struct block_data blk; 40 | if (!server_world_get_block(&s->world, tx, ty, tz, &blk)) 41 | return false; 42 | 43 | if (blk.type != BLOCK_AIR) 44 | return false; 45 | 46 | // Plant the crop 47 | server_world_set_block(s, tx, ty, tz, (struct block_data) { 48 | .type = BLOCK_CROPS, 49 | .metadata = 0, 50 | .sky_light = 0, 51 | .torch_light = 0, 52 | }); 53 | 54 | return true; 55 | } 56 | 57 | struct item item_seeds = { 58 | .name = "Seeds", 59 | .has_damage = false, 60 | .max_stack = 64, 61 | .fuel = 0, 62 | .renderItem = render_item_flat, 63 | .onItemPlace = onItemPlace, 64 | .armor.is_armor = false, 65 | .tool.type = TOOL_TYPE_ANY, 66 | .render_data = { 67 | .item = { 68 | .texture_x = 9, 69 | .texture_y = 0, 70 | }, 71 | }, 72 | }; 73 | -------------------------------------------------------------------------------- /source/block/block_portal.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | return 0; 29 | } 30 | 31 | static struct face_occlusion* 32 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 33 | return face_occlusion_empty(); 34 | } 35 | 36 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 37 | return TEXTURE_INDEX(0, 0); 38 | } 39 | 40 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 41 | struct random_gen* g, struct server_local* s) { 42 | return 0; 43 | } 44 | 45 | struct block block_portal = { 46 | .name = "Portal", 47 | .getSideMask = getSideMask, 48 | .getBoundingBox = getBoundingBox, 49 | .getMaterial = getMaterial, 50 | .getTextureIndex = getTextureIndex, 51 | .getDroppedItem = getDroppedItem, 52 | .onRandomTick = NULL, 53 | .onRightClick = NULL, 54 | .transparent = true, 55 | .renderBlock = render_block_portal, 56 | .renderBlockAlways = NULL, 57 | .luminance = 11, 58 | .double_sided = false, 59 | .can_see_through = true, 60 | .opacity = 1, 61 | .ignore_lighting = false, 62 | .flammable = false, 63 | .place_ignore = false, 64 | .digging.hardness = -1, 65 | .block_item = { 66 | .has_damage = false, 67 | .max_stack = 64, 68 | .renderItem = render_item_flat, 69 | .onItemPlace = block_place_default, 70 | .fuel = 0, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/block/block_planks.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_PLANKS); 40 | } 41 | 42 | struct block block_planks = { 43 | .name = "Planks", 44 | .getSideMask = getSideMask, 45 | .getBoundingBox = getBoundingBox, 46 | .getMaterial = getMaterial, 47 | .getTextureIndex = getTextureIndex, 48 | .getDroppedItem = block_drop_default, 49 | .onRandomTick = NULL, 50 | .onRightClick = NULL, 51 | .transparent = false, 52 | .renderBlock = render_block_full, 53 | .renderBlockAlways = NULL, 54 | .luminance = 0, 55 | .double_sided = false, 56 | .can_see_through = false, 57 | .ignore_lighting = false, 58 | .flammable = true, 59 | .place_ignore = false, 60 | .digging.hardness = 3000, 61 | .digging.tool = TOOL_TYPE_AXE, 62 | .digging.min = TOOL_TIER_ANY, 63 | .digging.best = TOOL_TIER_MAX, 64 | .block_item = { 65 | .has_damage = false, 66 | .max_stack = 64, 67 | .renderItem = render_item_block, 68 | .onItemPlace = block_place_default, 69 | .fuel = 1, 70 | .render_data.block.has_default = false, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/game/game_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef GAME_STATE_H 21 | #define GAME_STATE_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "../config.h" 28 | #include "../entity/entity.h" 29 | #include "../item/window_container.h" 30 | #include "../platform/time.h" 31 | #include "../world.h" 32 | #include "camera.h" 33 | #include "gui/screen.h" 34 | 35 | #define GAME_NAME "fCavEX" 36 | #define VERSION_MAJOR 0 37 | #define VERSION_MINOR 3 38 | #define VERSION_PATCH 0 39 | #define VERSION_FORK 2 40 | 41 | struct game_state { 42 | sig_atomic_t quit; 43 | struct random_gen rand_src; 44 | struct config config_user; 45 | struct { 46 | float dt, fps; 47 | float dt_gpu, dt_vsync; 48 | size_t chunks_rendered; 49 | } stats; 50 | struct { 51 | float fov; 52 | float render_distance; 53 | float fog_distance; 54 | } config; 55 | struct screen* current_screen; 56 | struct camera camera; 57 | struct camera_ray_result camera_hit; 58 | struct world world; 59 | struct entity* local_player; 60 | dict_entity_t entities; 61 | uint64_t world_time; 62 | ptime_t world_time_start; 63 | struct window_container* windows[256]; 64 | struct digging { 65 | bool active; 66 | ptime_t start; 67 | ptime_t cooldown; 68 | w_coord_t x, y, z; 69 | } digging; 70 | struct held_anim { 71 | struct { 72 | ptime_t start; 73 | bool place; 74 | } punch; 75 | struct { 76 | ptime_t start; 77 | size_t old_slot; 78 | } switch_item; 79 | } held_item_animation; 80 | bool world_loaded; 81 | bool in_water; 82 | bool paused; 83 | int oxygen; 84 | }; 85 | 86 | extern struct game_state gstate; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /source/block/block_sponge.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_ORGANIC; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_SPONGE); 40 | } 41 | 42 | struct block block_sponge = { 43 | .name = "Sponge", 44 | .getSideMask = getSideMask, 45 | .getBoundingBox = getBoundingBox, 46 | .getMaterial = getMaterial, 47 | .getTextureIndex = getTextureIndex, 48 | .getDroppedItem = block_drop_default, 49 | .onRandomTick = NULL, 50 | .onRightClick = NULL, 51 | .transparent = false, 52 | .renderBlock = render_block_full, 53 | .renderBlockAlways = NULL, 54 | .luminance = 0, 55 | .double_sided = false, 56 | .can_see_through = false, 57 | .ignore_lighting = false, 58 | .flammable = false, 59 | .place_ignore = false, 60 | .digging.hardness = 900, 61 | .digging.tool = TOOL_TYPE_ANY, 62 | .digging.min = TOOL_TIER_ANY, 63 | .digging.best = TOOL_TIER_ANY, 64 | .block_item = { 65 | .has_damage = false, 66 | .max_stack = 64, 67 | .renderItem = render_item_block, 68 | .onItemPlace = block_place_default, 69 | .fuel = 0, 70 | .render_data.block.has_default = false, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/block/block_bricks.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_BRICKS); 40 | } 41 | 42 | struct block block_bricks = { 43 | .name = "Bricks", 44 | .getSideMask = getSideMask, 45 | .getBoundingBox = getBoundingBox, 46 | .getMaterial = getMaterial, 47 | .getTextureIndex = getTextureIndex, 48 | .getDroppedItem = block_drop_default, 49 | .onRandomTick = NULL, 50 | .onRightClick = NULL, 51 | .transparent = false, 52 | .renderBlock = render_block_full, 53 | .renderBlockAlways = NULL, 54 | .luminance = 0, 55 | .double_sided = false, 56 | .can_see_through = false, 57 | .ignore_lighting = false, 58 | .flammable = false, 59 | .place_ignore = false, 60 | .digging.hardness = 3000, 61 | .digging.tool = TOOL_TYPE_PICKAXE, 62 | .digging.min = TOOL_TIER_WOOD, 63 | .digging.best = TOOL_TIER_WOOD, 64 | .block_item = { 65 | .has_damage = false, 66 | .max_stack = 64, 67 | .renderItem = render_item_block, 68 | .onItemPlace = block_place_default, 69 | .fuel = 0, 70 | .render_data.block.has_default = false, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/block/block_netherrack.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_NETHERRACK); 40 | } 41 | 42 | struct block block_netherrack = { 43 | .name = "Netherrack", 44 | .getSideMask = getSideMask, 45 | .getBoundingBox = getBoundingBox, 46 | .getMaterial = getMaterial, 47 | .getTextureIndex = getTextureIndex, 48 | .getDroppedItem = block_drop_default, 49 | .onRandomTick = NULL, 50 | .onRightClick = NULL, 51 | .transparent = false, 52 | .renderBlock = render_block_full, 53 | .renderBlockAlways = NULL, 54 | .luminance = 0, 55 | .double_sided = false, 56 | .can_see_through = false, 57 | .ignore_lighting = false, 58 | .flammable = false, 59 | .place_ignore = false, 60 | .digging.hardness = 600, 61 | .digging.tool = TOOL_TYPE_PICKAXE, 62 | .digging.min = TOOL_TIER_WOOD, 63 | .digging.best = TOOL_TIER_MAX, 64 | .block_item = { 65 | .has_damage = false, 66 | .max_stack = 64, 67 | .renderItem = render_item_block, 68 | .onItemPlace = block_place_default, 69 | .fuel = 0, 70 | .render_data.block.has_default = false, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/block/block_noteblock.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_JUKBEBOX_SIDE); 40 | } 41 | 42 | struct block block_noteblock = { 43 | .name = "Note Block", 44 | .getSideMask = getSideMask, 45 | .getBoundingBox = getBoundingBox, 46 | .getMaterial = getMaterial, 47 | .getTextureIndex = getTextureIndex, 48 | .getDroppedItem = block_drop_default, 49 | .onRandomTick = NULL, 50 | .onRightClick = NULL, 51 | .transparent = false, 52 | .renderBlock = render_block_full, 53 | .renderBlockAlways = NULL, 54 | .luminance = 0, 55 | .double_sided = false, 56 | .can_see_through = false, 57 | .ignore_lighting = false, 58 | .flammable = false, 59 | .place_ignore = false, 60 | .digging.hardness = 1200, 61 | .digging.tool = TOOL_TYPE_ANY, 62 | .digging.min = TOOL_TIER_ANY, 63 | .digging.best = TOOL_TIER_ANY, 64 | .block_item = { 65 | .has_damage = false, 66 | .max_stack = 64, 67 | .renderItem = render_item_block, 68 | .onItemPlace = block_place_default, 69 | .fuel = 0, 70 | .render_data.block.has_default = false, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/block/block_obsidian.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_OBSIDIAN); 40 | } 41 | 42 | struct block block_obsidian = { 43 | .name = "Obsidian", 44 | .getSideMask = getSideMask, 45 | .getBoundingBox = getBoundingBox, 46 | .getMaterial = getMaterial, 47 | .getTextureIndex = getTextureIndex, 48 | .getDroppedItem = block_drop_default, 49 | .onRandomTick = NULL, 50 | .onRightClick = NULL, 51 | .transparent = false, 52 | .renderBlock = render_block_full, 53 | .renderBlockAlways = NULL, 54 | .luminance = 0, 55 | .double_sided = false, 56 | .can_see_through = false, 57 | .ignore_lighting = false, 58 | .flammable = false, 59 | .place_ignore = false, 60 | .digging.hardness = 10000, 61 | .digging.tool = TOOL_TYPE_PICKAXE, 62 | .digging.min = TOOL_TIER_DIAMOND, 63 | .digging.best = TOOL_TIER_MAX, 64 | .block_item = { 65 | .has_damage = false, 66 | .max_stack = 64, 67 | .renderItem = render_item_block, 68 | .onItemPlace = block_place_default, 69 | .fuel = 0, 70 | .render_data.block.has_default = false, 71 | .armor.is_armor = false, 72 | .tool.type = TOOL_TYPE_ANY, 73 | }, 74 | }; 75 | -------------------------------------------------------------------------------- /source/network/inventory_logic.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "inventory_logic.h" 21 | 22 | #define min(a, b) ((a) < (b) ? (a) : (b)) 23 | 24 | bool inventory_collect(struct inventory* inv, struct item_data* item, 25 | uint8_t* slot_priority, size_t slot_length, 26 | set_inv_slot_t changes) { 27 | assert(inv && item && item->id != 0 && changes); 28 | 29 | struct item* it = item_get(item); 30 | 31 | if(!it) 32 | return false; 33 | 34 | while(item->count > 0) { 35 | bool has_canidate_equal = false; 36 | size_t candidate_equal = 0; 37 | bool has_canidate_empty = false; 38 | size_t candidate_empty = 0; 39 | 40 | for(size_t k = 0; k < slot_length; k++) { 41 | uint8_t slot = slot_priority[k]; 42 | 43 | if(inv->items[slot].id == item->id 44 | && inv->items[slot].durability == item->durability 45 | && inv->items[slot].count < it->max_stack) { 46 | has_canidate_equal = true; 47 | candidate_equal = slot; 48 | break; 49 | } 50 | 51 | if(!has_canidate_empty && inv->items[slot].id == 0) { 52 | has_canidate_empty = true; 53 | candidate_empty = slot; 54 | } 55 | } 56 | 57 | if(has_canidate_equal || has_canidate_empty) { 58 | size_t candidate 59 | = has_canidate_equal ? candidate_equal : candidate_empty; 60 | size_t additional 61 | = min(it->max_stack - inv->items[candidate].count, item->count); 62 | inv->items[candidate].id = item->id; 63 | inv->items[candidate].durability = item->durability; 64 | inv->items[candidate].count += additional; 65 | item->count -= additional; 66 | set_inv_slot_push(changes, candidate); 67 | } else { 68 | return false; 69 | } 70 | } 71 | 72 | return true; 73 | } -------------------------------------------------------------------------------- /source/block/block_bedrock.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_BEDROCK); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | return 0; 45 | } 46 | 47 | struct block block_bedrock = { 48 | .name = "Bedrock", 49 | .getSideMask = getSideMask, 50 | .getBoundingBox = getBoundingBox, 51 | .getMaterial = getMaterial, 52 | .getTextureIndex = getTextureIndex, 53 | .getDroppedItem = getDroppedItem, 54 | .onRandomTick = NULL, 55 | .onRightClick = NULL, 56 | .transparent = false, 57 | .renderBlock = render_block_full, 58 | .renderBlockAlways = NULL, 59 | .luminance = 0, 60 | .double_sided = false, 61 | .can_see_through = false, 62 | .ignore_lighting = false, 63 | .flammable = false, 64 | .place_ignore = false, 65 | .digging.hardness = -1, 66 | .block_item = { 67 | .has_damage = false, 68 | .max_stack = 64, 69 | .renderItem = render_item_block, 70 | .onItemPlace = block_place_default, 71 | .fuel = 0, 72 | .render_data.block.has_default = false, 73 | .armor.is_armor = false, 74 | .tool.type = TOOL_TYPE_ANY, 75 | }, 76 | }; 77 | -------------------------------------------------------------------------------- /source/block/block_jukebox.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | switch(side) { 40 | case SIDE_TOP: return tex_atlas_lookup(TEXAT_JUKBEBOX_TOP); 41 | default: return tex_atlas_lookup(TEXAT_JUKBEBOX_SIDE); 42 | } 43 | } 44 | 45 | struct block block_jukebox = { 46 | .name = "Jukebox", 47 | .getSideMask = getSideMask, 48 | .getBoundingBox = getBoundingBox, 49 | .getMaterial = getMaterial, 50 | .getTextureIndex = getTextureIndex, 51 | .getDroppedItem = block_drop_default, 52 | .onRandomTick = NULL, 53 | .onRightClick = NULL, 54 | .transparent = false, 55 | .renderBlock = render_block_full, 56 | .renderBlockAlways = NULL, 57 | .luminance = 0, 58 | .double_sided = false, 59 | .can_see_through = false, 60 | .ignore_lighting = false, 61 | .flammable = false, 62 | .place_ignore = false, 63 | .digging.hardness = 3000, 64 | .digging.tool = TOOL_TYPE_ANY, 65 | .digging.min = TOOL_TIER_ANY, 66 | .digging.best = TOOL_TIER_ANY, 67 | .block_item = { 68 | .has_damage = false, 69 | .max_stack = 64, 70 | .renderItem = render_item_block, 71 | .onItemPlace = block_place_default, 72 | .fuel = 0, 73 | .render_data.block.has_default = false, 74 | .armor.is_armor = false, 75 | .tool.type = TOOL_TYPE_ANY, 76 | }, 77 | }; 78 | -------------------------------------------------------------------------------- /source/platform/pc/texture.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "../texture.h" 24 | 25 | void tex_init_pre() { } 26 | 27 | void tex_gfx_load(struct tex_gfx* tex, void* img, size_t width, size_t height, 28 | enum tex_format type, bool linear) { 29 | assert(tex && img && width > 0 && height > 0); 30 | 31 | tex->fmt = type; 32 | tex->data = img; 33 | tex->width = width; 34 | tex->height = height; 35 | 36 | glGenTextures(1, &tex->id); 37 | 38 | glBindTexture(GL_TEXTURE_2D, tex->id); 39 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, 40 | GL_UNSIGNED_BYTE, img); 41 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 42 | linear ? GL_LINEAR : GL_NEAREST); 43 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 44 | linear ? GL_LINEAR : GL_NEAREST); 45 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 46 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 47 | glBindTexture(GL_TEXTURE_2D, 0); 48 | } 49 | 50 | void tex_gfx_wrap_mode(struct tex_gfx* tex, bool repeat) { 51 | assert(tex); 52 | 53 | glBindTexture(GL_TEXTURE_2D, tex->id); 54 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 55 | repeat ? GL_REPEAT : GL_CLAMP); 56 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 57 | repeat ? GL_REPEAT : GL_CLAMP); 58 | glBindTexture(GL_TEXTURE_2D, 0); 59 | } 60 | 61 | void tex_gfx_bind(struct tex_gfx* tex, int slot) { 62 | assert(tex); 63 | glBindTexture(GL_TEXTURE_2D, tex->id); 64 | } 65 | 66 | void tex_gfx_lookup(struct tex_gfx* tex, int x, int y, uint8_t* color) { 67 | assert(tex && color); 68 | 69 | memcpy(color, 70 | tex->data 71 | + (((unsigned int)x % tex->width) 72 | + ((unsigned int)y % tex->height) * tex->width) 73 | * 4, 74 | 4); 75 | } -------------------------------------------------------------------------------- /source/block/block_sandstone.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | switch(side) { 40 | case SIDE_TOP: return tex_atlas_lookup(TEXAT_SANDSTONE_TOP); 41 | case SIDE_BOTTOM: return tex_atlas_lookup(TEXAT_SANDSTONE_BOTTOM); 42 | default: return tex_atlas_lookup(TEXAT_SANDSTONE_SIDE); 43 | } 44 | } 45 | 46 | struct block block_sandstone = { 47 | .name = "Sandstone", 48 | .getSideMask = getSideMask, 49 | .getBoundingBox = getBoundingBox, 50 | .getMaterial = getMaterial, 51 | .getTextureIndex = getTextureIndex, 52 | .getDroppedItem = block_drop_default, 53 | .onRandomTick = NULL, 54 | .onRightClick = NULL, 55 | .transparent = false, 56 | .renderBlock = render_block_full, 57 | .renderBlockAlways = NULL, 58 | .luminance = 0, 59 | .double_sided = false, 60 | .can_see_through = false, 61 | .ignore_lighting = false, 62 | .flammable = false, 63 | .place_ignore = false, 64 | .digging.hardness = 1200, 65 | .digging.tool = TOOL_TYPE_PICKAXE, 66 | .digging.min = TOOL_TIER_WOOD, 67 | .digging.best = TOOL_TIER_MAX, 68 | .block_item = { 69 | .has_damage = false, 70 | .max_stack = 64, 71 | .renderItem = render_item_block, 72 | .onItemPlace = block_place_default, 73 | .fuel = 0, 74 | .render_data.block.has_default = false, 75 | .armor.is_armor = false, 76 | .tool.type = TOOL_TYPE_ANY, 77 | }, 78 | }; 79 | -------------------------------------------------------------------------------- /source/block/block_spawner.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_empty(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_SPAWNER); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | return 0; 45 | } 46 | 47 | struct block block_spawner = { 48 | .name = "Monster Spawner", 49 | .getSideMask = getSideMask, 50 | .getBoundingBox = getBoundingBox, 51 | .getMaterial = getMaterial, 52 | .getTextureIndex = getTextureIndex, 53 | .getDroppedItem = getDroppedItem, 54 | .onRandomTick = NULL, 55 | .onRightClick = NULL, 56 | .transparent = false, 57 | .renderBlock = render_block_full, 58 | .renderBlockAlways = NULL, 59 | .luminance = 0, 60 | .double_sided = false, 61 | .can_see_through = true, 62 | .opacity = 1, 63 | .ignore_lighting = false, 64 | .flammable = false, 65 | .place_ignore = false, 66 | .digging.hardness = 7500, 67 | .digging.tool = TOOL_TYPE_PICKAXE, 68 | .digging.min = TOOL_TIER_WOOD, 69 | .digging.best = TOOL_TIER_WOOD, 70 | .block_item = { 71 | .has_damage = false, 72 | .max_stack = 64, 73 | .renderItem = render_item_block, 74 | .onItemPlace = block_place_default, 75 | .fuel = 0, 76 | .render_data.block.has_default = false, 77 | .armor.is_armor = false, 78 | .tool.type = TOOL_TYPE_ANY, 79 | }, 80 | }; 81 | -------------------------------------------------------------------------------- /source/item/items/item_door_iron.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | 22 | static bool onItemPlace(struct server_local* s, struct item_data* it, 23 | struct block_info* where, struct block_info* on, 24 | enum side on_side) { 25 | struct block_data blk; 26 | if(!server_world_get_block(&s->world, where->x, where->y - 1, where->z, &blk)) 27 | return false; 28 | if(!server_world_get_block(&s->world, where->x, where->y + 1, where->z, &blk)) 29 | return false; 30 | if(blk.type != 0) return false; 31 | if(!blocks[on->block->type]) return false; 32 | 33 | int metadata = 6; 34 | switch(on_side) { 35 | case SIDE_LEFT: metadata = 2; break; 36 | case SIDE_RIGHT: metadata = 0; break; 37 | case SIDE_BACK: metadata = 4; break; 38 | default: break; 39 | } 40 | 41 | struct block_data blk2 = (struct block_data) { 42 | .type = BLOCK_DOOR_IRON, 43 | .metadata = metadata, 44 | .sky_light = 0, 45 | .torch_light = 0, 46 | }; 47 | 48 | struct block_info blk2_info = *where; 49 | blk2_info.block = &blk2; 50 | 51 | if(entity_local_player_block_collide( 52 | (vec3) {s->player.x, s->player.y, s->player.z}, &blk2_info)) 53 | return false; 54 | 55 | if(entity_local_player_block_collide( 56 | (vec3) {s->player.x, s->player.y + 1, s->player.z}, &blk2_info)) 57 | return false; 58 | 59 | server_world_set_block(s, where->x, where->y, where->z, blk2); 60 | 61 | blk2.metadata |= 8; 62 | server_world_set_block(s, where->x, where->y + 1, where->z, blk2); 63 | return true; 64 | } 65 | 66 | struct item item_door_iron = { 67 | .name = "Iron Door", 68 | .has_damage = false, 69 | .max_stack = 1, 70 | .fuel = 0, 71 | .renderItem = render_item_flat, 72 | .onItemPlace = onItemPlace, 73 | .armor.is_armor = false, 74 | .tool.type = TOOL_TYPE_ANY, 75 | .render_data = { 76 | .item = { 77 | .texture_x = 12, 78 | .texture_y = 2, 79 | }, 80 | }, 81 | }; 82 | -------------------------------------------------------------------------------- /source/block/block_ice.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return (it->block->type == this->block->type) ? face_occlusion_full() : 36 | face_occlusion_empty(); 37 | } 38 | 39 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 40 | return TEXTURE_INDEX(4, 0); 41 | } 42 | 43 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 44 | struct random_gen* g, struct server_local* s) { 45 | return 0; 46 | } 47 | 48 | struct block block_ice = { 49 | .name = "Ice", 50 | .getSideMask = getSideMask, 51 | .getBoundingBox = getBoundingBox, 52 | .getMaterial = getMaterial, 53 | .getTextureIndex = getTextureIndex, 54 | .getDroppedItem = getDroppedItem, 55 | .onRandomTick = NULL, 56 | .onRightClick = NULL, 57 | .transparent = true, 58 | .renderBlock = render_block_full, 59 | .renderBlockAlways = NULL, 60 | .luminance = 0, 61 | .double_sided = false, 62 | .can_see_through = true, 63 | .opacity = 1, 64 | .ignore_lighting = false, 65 | .flammable = false, 66 | .place_ignore = false, 67 | .digging.hardness = 750, 68 | .digging.tool = TOOL_TYPE_PICKAXE, 69 | .digging.min = TOOL_TIER_WOOD, 70 | .digging.best = TOOL_TIER_MAX, 71 | .block_item = { 72 | .has_damage = false, 73 | .max_stack = 64, 74 | .renderItem = render_item_block, 75 | .onItemPlace = block_place_default, 76 | .fuel = 0, 77 | .render_data.block.has_default = false, 78 | .armor.is_armor = false, 79 | .tool.type = TOOL_TYPE_ANY, 80 | }, 81 | }; 82 | -------------------------------------------------------------------------------- /source/item/items/item_door_wood.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | 22 | static bool onItemPlace(struct server_local* s, struct item_data* it, 23 | struct block_info* where, struct block_info* on, 24 | enum side on_side) { 25 | struct block_data blk; 26 | if(!server_world_get_block(&s->world, where->x, where->y - 1, where->z, &blk)) 27 | return false; 28 | if(!server_world_get_block(&s->world, where->x, where->y + 1, where->z, &blk)) 29 | return false; 30 | if(blk.type != 0) return false; 31 | if(!blocks[on->block->type]) return false; 32 | 33 | int metadata = 6; 34 | switch(on_side) { 35 | case SIDE_LEFT: metadata = 2; break; 36 | case SIDE_RIGHT: metadata = 0; break; 37 | case SIDE_BACK: metadata = 4; break; 38 | default: break; 39 | } 40 | 41 | struct block_data blk2 = (struct block_data) { 42 | .type = BLOCK_DOOR_WOOD, 43 | .metadata = metadata, 44 | .sky_light = 0, 45 | .torch_light = 0, 46 | }; 47 | 48 | struct block_info blk2_info = *where; 49 | blk2_info.block = &blk2; 50 | 51 | if(entity_local_player_block_collide( 52 | (vec3) {s->player.x, s->player.y, s->player.z}, &blk2_info)) 53 | return false; 54 | 55 | if(entity_local_player_block_collide( 56 | (vec3) {s->player.x, s->player.y + 1, s->player.z}, &blk2_info)) 57 | return false; 58 | 59 | server_world_set_block(s, where->x, where->y, where->z, blk2); 60 | 61 | blk2.metadata |= 8; 62 | server_world_set_block(s, where->x, where->y + 1, where->z, blk2); 63 | return true; 64 | } 65 | 66 | struct item item_door_wood = { 67 | .name = "Wooden Door", 68 | .has_damage = false, 69 | .max_stack = 1, 70 | .fuel = 2, 71 | .renderItem = render_item_flat, 72 | .onItemPlace = onItemPlace, 73 | .armor.is_armor = false, 74 | .tool.type = TOOL_TYPE_ANY, 75 | .render_data = { 76 | .item = { 77 | .texture_x = 11, 78 | .texture_y = 2, 79 | }, 80 | }, 81 | }; 82 | -------------------------------------------------------------------------------- /source/block/block_glass.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_GLASS; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return (it->block->type == this->block->type) ? face_occlusion_full() : 36 | face_occlusion_empty(); 37 | } 38 | 39 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 40 | return tex_atlas_lookup(TEXAT_GLASS); 41 | } 42 | 43 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 44 | struct random_gen* g, struct server_local* s) { 45 | return 0; 46 | } 47 | 48 | struct block block_glass = { 49 | .name = "Glass", 50 | .getSideMask = getSideMask, 51 | .getBoundingBox = getBoundingBox, 52 | .getMaterial = getMaterial, 53 | .getTextureIndex = getTextureIndex, 54 | .getDroppedItem = getDroppedItem, 55 | .onRandomTick = NULL, 56 | .onRightClick = NULL, 57 | .transparent = false, 58 | .renderBlock = render_block_full, 59 | .renderBlockAlways = NULL, 60 | .luminance = 0, 61 | .double_sided = false, 62 | .can_see_through = true, 63 | .opacity = 0, 64 | .ignore_lighting = false, 65 | .flammable = false, 66 | .place_ignore = false, 67 | .digging.hardness = 450, 68 | .digging.tool = TOOL_TYPE_ANY, 69 | .digging.min = TOOL_TIER_ANY, 70 | .digging.best = TOOL_TIER_ANY, 71 | .block_item = { 72 | .has_damage = false, 73 | .max_stack = 64, 74 | .renderItem = render_item_block, 75 | .onItemPlace = block_place_default, 76 | .fuel = 0, 77 | .render_data.block.has_default = false, 78 | .armor.is_armor = false, 79 | .tool.type = TOOL_TYPE_ANY, 80 | }, 81 | }; 82 | -------------------------------------------------------------------------------- /source/block/block_clay.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_SAND; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_CLAY); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | if(it) { 45 | it->id = ITEM_CLAY_BALL; 46 | it->durability = 0; 47 | it->count = 4; 48 | } 49 | 50 | return 1; 51 | } 52 | 53 | struct block block_clay = { 54 | .name = "Clay", 55 | .getSideMask = getSideMask, 56 | .getBoundingBox = getBoundingBox, 57 | .getMaterial = getMaterial, 58 | .getTextureIndex = getTextureIndex, 59 | .getDroppedItem = getDroppedItem, 60 | .onRandomTick = NULL, 61 | .onRightClick = NULL, 62 | .transparent = false, 63 | .renderBlock = render_block_full, 64 | .renderBlockAlways = NULL, 65 | .luminance = 0, 66 | .double_sided = false, 67 | .can_see_through = false, 68 | .ignore_lighting = false, 69 | .flammable = false, 70 | .place_ignore = false, 71 | .digging.hardness = 900, 72 | .digging.tool = TOOL_TYPE_SHOVEL, 73 | .digging.min = TOOL_TIER_ANY, 74 | .digging.best = TOOL_TIER_MAX, 75 | .block_item = { 76 | .has_damage = false, 77 | .max_stack = 64, 78 | .renderItem = render_item_block, 79 | .onItemPlace = block_place_default, 80 | .fuel = 0, 81 | .render_data.block.has_default = false, 82 | .armor.is_armor = false, 83 | .tool.type = TOOL_TYPE_ANY, 84 | }, 85 | }; 86 | -------------------------------------------------------------------------------- /source/block/block_stone.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_STONE); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | if(it) { 45 | it->id = BLOCK_COBBLESTONE; 46 | it->durability = 0; 47 | it->count = 1; 48 | } 49 | 50 | return 1; 51 | } 52 | 53 | struct block block_stone = { 54 | .name = "Stone", 55 | .getSideMask = getSideMask, 56 | .getBoundingBox = getBoundingBox, 57 | .getMaterial = getMaterial, 58 | .getTextureIndex = getTextureIndex, 59 | .getDroppedItem = getDroppedItem, 60 | .onRandomTick = NULL, 61 | .onRightClick = NULL, 62 | .transparent = false, 63 | .renderBlock = render_block_full, 64 | .renderBlockAlways = NULL, 65 | .luminance = 0, 66 | .double_sided = false, 67 | .can_see_through = false, 68 | .ignore_lighting = false, 69 | .flammable = false, 70 | .place_ignore = false, 71 | .digging.hardness = 2250, 72 | .digging.tool = TOOL_TYPE_PICKAXE, 73 | .digging.min = TOOL_TIER_WOOD, 74 | .digging.best = TOOL_TIER_MAX, 75 | .block_item = { 76 | .has_damage = false, 77 | .max_stack = 64, 78 | .renderItem = render_item_block, 79 | .onItemPlace = block_place_default, 80 | .fuel = 0, 81 | .render_data.block.has_default = false, 82 | .armor.is_armor = false, 83 | .tool.type = TOOL_TYPE_ANY, 84 | }, 85 | }; 86 | -------------------------------------------------------------------------------- /source/block/block_bookshelf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | switch(side) { 40 | case SIDE_TOP: 41 | case SIDE_BOTTOM: return tex_atlas_lookup(TEXAT_PLANKS); 42 | default: return tex_atlas_lookup(TEXAT_BOOKSHELF); 43 | } 44 | } 45 | 46 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 47 | struct random_gen* g, struct server_local* s) { 48 | return 0; 49 | } 50 | 51 | struct block block_bookshelf = { 52 | .name = "Bookshelf", 53 | .getSideMask = getSideMask, 54 | .getBoundingBox = getBoundingBox, 55 | .getMaterial = getMaterial, 56 | .getTextureIndex = getTextureIndex, 57 | .getDroppedItem = getDroppedItem, 58 | .onRandomTick = NULL, 59 | .onRightClick = NULL, 60 | .transparent = false, 61 | .renderBlock = render_block_full, 62 | .renderBlockAlways = NULL, 63 | .luminance = 0, 64 | .double_sided = false, 65 | .can_see_through = false, 66 | .ignore_lighting = false, 67 | .flammable = true, 68 | .place_ignore = false, 69 | .digging.hardness = 2250, 70 | .digging.tool = TOOL_TYPE_AXE, 71 | .digging.min = TOOL_TIER_ANY, 72 | .digging.best = TOOL_TIER_MAX, 73 | .block_item = { 74 | .has_damage = false, 75 | .max_stack = 64, 76 | .renderItem = render_item_block, 77 | .onItemPlace = block_place_default, 78 | .fuel = 0, 79 | .render_data.block.has_default = false, 80 | .armor.is_armor = false, 81 | .tool.type = TOOL_TYPE_ANY, 82 | }, 83 | }; 84 | -------------------------------------------------------------------------------- /source/item/items/item_flint_steel.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../network/server_local.h" 21 | #include "../../network/client_interface.h" 22 | #include "../../network/server_interface.h" 23 | #include "../../block/blocks.h" 24 | 25 | static bool onItemPlace(struct server_local* s, struct item_data* it, 26 | struct block_info* where, struct block_info* on, 27 | enum side on_side) { 28 | if (!on || !on->block) return false; 29 | 30 | // Check if the clicked block is flammable 31 | if (!blocks[on->block->type] || !blocks[on->block->type]->flammable) 32 | return false; 33 | 34 | int tx = on->x; 35 | int ty = on->y; 36 | int tz = on->z; 37 | 38 | // Determine the target block based on click side 39 | switch (on_side) { 40 | case SIDE_TOP: ty += 1; break; 41 | case SIDE_BOTTOM: ty -= 1; break; 42 | case SIDE_FRONT: tz += 1; break; 43 | case SIDE_BACK: tz -= 1; break; 44 | case SIDE_LEFT: tx -= 1; break; 45 | case SIDE_RIGHT: tx += 1; break; 46 | default: break; 47 | } 48 | 49 | struct block_data blk; 50 | if (!server_world_get_block(&s->world, tx, ty, tz, &blk)) 51 | return false; 52 | 53 | // Only if the target block is air 54 | if (blk.type != BLOCK_AIR) 55 | return false; 56 | 57 | // Place fire 58 | server_world_set_block(s, tx, ty, tz, (struct block_data) { 59 | .type = BLOCK_FIRE, 60 | .metadata = 0, 61 | .sky_light = 0, 62 | .torch_light = 15, 63 | }); 64 | 65 | return false; 66 | } 67 | 68 | struct item item_flint_steel = { 69 | .name = "Flint and Steel", 70 | .has_damage = false, // Disable damage (it won't be used up anymore) 71 | .max_damage = 0, // Set max_damage to 0, so it doesn't get used up 72 | .max_stack = 1, 73 | .fuel = 0, 74 | .renderItem = render_item_flat, 75 | .onItemPlace = onItemPlace, 76 | .armor.is_armor = false, 77 | .tool.type = TOOL_TYPE_ANY, 78 | .render_data = { 79 | .item = { 80 | .texture_x = 5, 81 | .texture_y = 0, 82 | }, 83 | }, 84 | }; 85 | -------------------------------------------------------------------------------- /source/block/block_glowstone.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_GLASS; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_GLOWSTONE); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | if(it) { 45 | it->id = ITEM_GLOWSTONE_DUST; 46 | it->durability = 0; 47 | it->count = rand_gen_range(g, 2, 4); 48 | } 49 | 50 | return 1; 51 | } 52 | 53 | struct block block_glowstone = { 54 | .name = "Glowstone", 55 | .getSideMask = getSideMask, 56 | .getBoundingBox = getBoundingBox, 57 | .getMaterial = getMaterial, 58 | .getTextureIndex = getTextureIndex, 59 | .getDroppedItem = getDroppedItem, 60 | .onRandomTick = NULL, 61 | .onRightClick = NULL, 62 | .transparent = false, 63 | .renderBlock = render_block_full, 64 | .renderBlockAlways = NULL, 65 | .luminance = 15, 66 | .double_sided = false, 67 | .can_see_through = false, 68 | .ignore_lighting = false, 69 | .flammable = false, 70 | .place_ignore = false, 71 | .digging.hardness = 450, 72 | .digging.tool = TOOL_TYPE_ANY, 73 | .digging.min = TOOL_TIER_ANY, 74 | .digging.best = TOOL_TIER_ANY, 75 | .block_item = { 76 | .has_damage = false, 77 | .max_stack = 64, 78 | .renderItem = render_item_block, 79 | .onItemPlace = block_place_default, 80 | .fuel = 0, 81 | .render_data.block.has_default = false, 82 | .armor.is_armor = false, 83 | .tool.type = TOOL_TYPE_ANY, 84 | }, 85 | }; 86 | -------------------------------------------------------------------------------- /source/block/block_gravel.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_ORGANIC; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_GRAVEL); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | if(it) { 45 | it->id = (rand_gen(g) % 10) == 0 ? ITEM_FLINT : this->block->type; 46 | it->durability = 0; 47 | it->count = 1; 48 | } 49 | 50 | return 1; 51 | } 52 | 53 | struct block block_gravel = { 54 | .name = "Gravel", 55 | .getSideMask = getSideMask, 56 | .getBoundingBox = getBoundingBox, 57 | .getMaterial = getMaterial, 58 | .getTextureIndex = getTextureIndex, 59 | .getDroppedItem = getDroppedItem, 60 | .onRandomTick = NULL, 61 | .onRightClick = NULL, 62 | .transparent = false, 63 | .renderBlock = render_block_full, 64 | .renderBlockAlways = NULL, 65 | .luminance = 0, 66 | .double_sided = false, 67 | .can_see_through = false, 68 | .ignore_lighting = false, 69 | .flammable = false, 70 | .place_ignore = false, 71 | .digging.hardness = 900, 72 | .digging.tool = TOOL_TYPE_SHOVEL, 73 | .digging.min = TOOL_TIER_ANY, 74 | .digging.best = TOOL_TIER_MAX, 75 | .block_item = { 76 | .has_damage = false, 77 | .max_stack = 64, 78 | .renderItem = render_item_block, 79 | .onItemPlace = block_place_default, 80 | .fuel = 0, 81 | .render_data.block.has_default = false, 82 | .armor.is_armor = false, 83 | .tool.type = TOOL_TYPE_ANY, 84 | }, 85 | }; 86 | -------------------------------------------------------------------------------- /source/block/block_cobweb.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return entity ? 0 : 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_empty(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | return tex_atlas_lookup(TEXAT_COBWEB); 40 | } 41 | 42 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 43 | struct random_gen* g, struct server_local* s) { 44 | if(it) { 45 | it->id = ITEM_STRING; 46 | it->durability = 0; 47 | it->count = 1; 48 | } 49 | 50 | return 1; 51 | } 52 | 53 | struct block block_cobweb = { 54 | .name = "Cobweb", 55 | .getSideMask = getSideMask, 56 | .getBoundingBox = getBoundingBox, 57 | .getMaterial = getMaterial, 58 | .getTextureIndex = getTextureIndex, 59 | .getDroppedItem = getDroppedItem, 60 | .onRandomTick = NULL, 61 | .onRightClick = NULL, 62 | .transparent = false, 63 | .renderBlock = render_block_cross, 64 | .renderBlockAlways = NULL, 65 | .luminance = 0, 66 | .double_sided = true, 67 | .can_see_through = true, 68 | .opacity = 1, 69 | .render_block_data.cross_random_displacement = false, 70 | .ignore_lighting = false, 71 | .flammable = false, 72 | .place_ignore = false, 73 | .digging.hardness = 6000, // TODO: might not be correct 74 | .digging.tool = TOOL_TYPE_SWORD, 75 | .digging.min = TOOL_TIER_WOOD, 76 | .digging.best = TOOL_TIER_WOOD, 77 | .block_item = { 78 | .has_damage = false, 79 | .max_stack = 64, 80 | .renderItem = render_item_flat, 81 | .onItemPlace = block_place_default, 82 | .fuel = 0, 83 | .armor.is_armor = false, 84 | .tool.type = TOOL_TYPE_ANY, 85 | }, 86 | }; 87 | -------------------------------------------------------------------------------- /source/block/block_fence.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, entity ? 1.5F : 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion side_top_bottom = { 34 | .mask = {0x00000000, 0x00000000, 0x00000000, 0x03C003C0, 0x03C003C0, 35 | 0x00000000, 0x00000000, 0x00000000}, 36 | }; 37 | 38 | static struct face_occlusion* 39 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 40 | switch(side) { 41 | case SIDE_TOP: 42 | case SIDE_BOTTOM: return &side_top_bottom; 43 | default: return face_occlusion_empty(); 44 | } 45 | } 46 | 47 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 48 | return tex_atlas_lookup(TEXAT_PLANKS); 49 | } 50 | 51 | struct block block_fence = { 52 | .name = "Fence", 53 | .getSideMask = getSideMask, 54 | .getBoundingBox = getBoundingBox, 55 | .getMaterial = getMaterial, 56 | .getTextureIndex = getTextureIndex, 57 | .getDroppedItem = block_drop_default, 58 | .onRandomTick = NULL, 59 | .onRightClick = NULL, 60 | .transparent = false, 61 | .renderBlock = render_block_fence, 62 | .renderBlockAlways = render_block_fence_always, 63 | .luminance = 0, 64 | .double_sided = false, 65 | .can_see_through = true, 66 | .opacity = 0, 67 | .ignore_lighting = false, 68 | .flammable = true, 69 | .place_ignore = false, 70 | .digging.hardness = 3000, 71 | .digging.tool = TOOL_TYPE_ANY, 72 | .digging.min = TOOL_TIER_ANY, 73 | .digging.best = TOOL_TIER_ANY, 74 | .block_item = { 75 | .has_damage = false, 76 | .max_stack = 64, 77 | .renderItem = render_item_block, 78 | .onItemPlace = block_place_default, 79 | .fuel = 0, 80 | .render_data.block.has_default = false, 81 | .armor.is_armor = false, 82 | .tool.type = TOOL_TYPE_ANY, 83 | }, 84 | }; 85 | -------------------------------------------------------------------------------- /source/particle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef PARTICLE_H 21 | #define PARTICLE_H 22 | 23 | #include "cglm/cglm.h" 24 | #include "platform/time.h" 25 | #include "world.h" 26 | 27 | 28 | typedef enum { 29 | TEXTURE_ATLAS_TERRAIN, 30 | TEXTURE_ATLAS_PARTICLES 31 | } particle_atlas_t; 32 | 33 | 34 | struct particle { 35 | vec3 pos; // current position 36 | vec3 pos_old; // previous position for interpolation 37 | vec3 vel; // velocity 38 | vec2 tex_uv; // only for terrain‐atlas random offset 39 | float size; // half‐quad size 40 | int age; // remaining life in ticks 41 | int lifetime; // initial life in ticks, for animating smoke 42 | uint8_t tex; // base tile index 43 | bool gravity; // apply gravity? 44 | uint8_t r, g, b; // rgb colorisation of a particle 45 | bool ignore_light; // apply gravity? 46 | particle_atlas_t atlas; // which atlas to sample 47 | }; 48 | 49 | 50 | void particle_add(vec3 pos, 51 | vec3 vel, 52 | uint8_t tex, 53 | float size, 54 | float lifetime, 55 | bool gravity, 56 | uint8_t r, 57 | uint8_t g, 58 | uint8_t b, 59 | bool ignore_light, 60 | particle_atlas_t atlas); 61 | 62 | void particle_init(void); 63 | void particle_set_camera(vec3 p); 64 | void particle_generate_block(struct block_info* info); 65 | void particle_generate_side(struct block_info* info, enum side s); 66 | void particle_update(void); 67 | void particle_render(mat4 view, vec3 camera, float delta); 68 | void particle_generate_explosion_flash(vec3 center, float intensity); 69 | void particle_generate_explosion_smoke(vec3 center, float intensity); 70 | void particle_generate_smoke(vec3 center, float intensity); 71 | void particle_generate_torch(vec3 pos); 72 | void particle_generate_redstone_torch(vec3 center); 73 | void particle_generate_redstone_wire(vec3 center, uint8_t power); 74 | #endif 75 | -------------------------------------------------------------------------------- /source/platform/gfx.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef GFX_H 21 | #define GFX_H 22 | 23 | #include 24 | #include 25 | 26 | #include "../cglm/cglm.h" 27 | #include "texture.h" 28 | 29 | enum gfx_blend { 30 | MODE_BLEND, 31 | MODE_BLEND2, 32 | MODE_BLEND3, 33 | MODE_INVERT, 34 | MODE_OFF, 35 | }; 36 | 37 | enum depth_func { 38 | MODE_LEQUAL, 39 | MODE_EQUAL, 40 | }; 41 | 42 | enum cull_func { 43 | MODE_NONE, 44 | MODE_BACK, 45 | MODE_FRONT, 46 | }; 47 | 48 | void gfx_setup(void); 49 | void gfx_update_light(float daytime, const float* light_lookup); 50 | float gfx_lookup_light(uint8_t light); 51 | void gfx_finish(bool vsync); 52 | void gfx_flip_buffers(float* gpu_wait, float* vsync_wait); 53 | void gfx_bind_texture(struct tex_gfx* tex); 54 | void gfx_clear_buffers(uint8_t r, uint8_t g, uint8_t b); 55 | int gfx_width(void); 56 | int gfx_height(void); 57 | 58 | void gfx_copy_framebuffer(uint8_t* dest, size_t* width, size_t* height); 59 | 60 | void gfx_matrix_projection(mat4 proj, bool is_perspective); 61 | void gfx_matrix_modelview(mat4 mv); 62 | void gfx_matrix_texture(bool enable, mat4 tex); 63 | 64 | void gfx_mode_world(void); 65 | void gfx_mode_gui(void); 66 | void gfx_fog_color(uint8_t r, uint8_t g, uint8_t b); 67 | void gfx_fog_pos(float dx, float dz, float distance); 68 | void gfx_fog(bool enable); 69 | void gfx_blending(enum gfx_blend mode); 70 | void gfx_alpha_test(bool enable); 71 | void gfx_write_buffers(bool color, bool depth, bool depth_test); 72 | void gfx_depth_range(float near, float far); 73 | void gfx_depth_func(enum depth_func func); 74 | void gfx_texture(bool enable); 75 | void gfx_lighting(bool enable); 76 | void gfx_cull_func(enum cull_func func); 77 | void gfx_scissor(bool enable, uint32_t x, uint32_t y, uint32_t width, 78 | uint32_t height); 79 | void gfx_draw_lines(size_t vertex_count, const int16_t* vertices, 80 | const uint8_t* colors); 81 | void gfx_draw_quads(size_t vertex_count, const int16_t* vertices, 82 | const uint8_t* colors, const uint16_t* texcoords); 83 | void gfx_draw_quads_flt(size_t vertex_count, const float* vertices, 84 | const uint8_t* colors, const float* texcoords); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /source/stack.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "stack.h" 26 | 27 | void stack_create(struct stack* stk, size_t inital_size, size_t element_size) { 28 | assert(stk != NULL && inital_size > 0 && element_size > 0); 29 | 30 | stk->element_size = element_size; 31 | stk->index = 0; 32 | stk->length = inital_size; 33 | stk->data = malloc(stk->length * stk->element_size); 34 | assert(stk->data); 35 | } 36 | 37 | void stack_push(struct stack* stk, void* obj) { 38 | assert(stk != NULL && obj != NULL); 39 | 40 | if(stk->index >= stk->length) { 41 | stk->length *= 2; 42 | stk->data = realloc(stk->data, stk->length * stk->element_size); 43 | assert(stk->data); 44 | } 45 | 46 | memcpy((uint8_t*)stk->data + (stk->index++) * stk->element_size, obj, 47 | stk->element_size); 48 | } 49 | 50 | bool stack_empty(struct stack* stk) { 51 | assert(stk != NULL); 52 | 53 | return stk->index == 0; 54 | } 55 | 56 | size_t stack_size(struct stack* stk) { 57 | assert(stk != NULL); 58 | 59 | return stk->index; 60 | } 61 | 62 | void stack_at(struct stack* stk, void* obj, size_t index) { 63 | assert(stk != NULL && obj != NULL); 64 | 65 | if(index < stk->index) 66 | memcpy(obj, (uint8_t*)stk->data + index * stk->element_size, 67 | stk->element_size); 68 | } 69 | 70 | bool stack_pop(struct stack* stk, void* obj) { 71 | assert(stk != NULL && obj != NULL); 72 | 73 | if(stack_empty(stk)) 74 | return false; 75 | 76 | memcpy(obj, (uint8_t*)stk->data + (--stk->index) * stk->element_size, 77 | stk->element_size); 78 | 79 | /*if(stk->index * 4 <= stk->length) { 80 | stk->length /= 2; 81 | stk->data = realloc(stk->data, stk->length * stk->element_size); 82 | assert(stk->data); 83 | }*/ 84 | 85 | return true; 86 | } 87 | 88 | void stack_clear(struct stack* stk) { 89 | assert(stk != NULL); 90 | 91 | stk->index = 0; 92 | } 93 | 94 | void stack_destroy(struct stack* stk) { 95 | assert(stk != NULL); 96 | 97 | if(stk->data) 98 | free(stk->data); 99 | } 100 | -------------------------------------------------------------------------------- /source/game/gui/screen_pause.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../graphics/gfx_util.h" 21 | #include "../../graphics/gfx_settings.h" 22 | #include "../../graphics/gui_util.h" 23 | #include "../../graphics/render_model.h" 24 | #include "../../network/server_interface.h" 25 | #include "../../platform/gfx.h" 26 | #include "../../platform/input.h" 27 | #include "../../platform/time.h" 28 | #include "../game_state.h" 29 | #include "screen.h" 30 | 31 | #define GUI_WIDTH 176 32 | #define GUI_HEIGHT 167 33 | 34 | static bool pointer_has_item; 35 | static bool pointer_available; 36 | static float pointer_x, pointer_y, pointer_angle; 37 | 38 | static void screen_pause_reset(struct screen* s, int width, int height) { 39 | if(gstate.local_player) 40 | gstate.local_player->data.local_player.capture_input = false; 41 | 42 | s->render3D = screen_ingame.render3D; 43 | } 44 | 45 | static void screen_pause_update(struct screen* s, float dt) { 46 | if(input_pressed(IB_HOME)) { 47 | svin_rpc_send(&(struct server_rpc) { 48 | .type = SRPC_TOGGLE_PAUSE, 49 | }); 50 | gstate.paused = false; 51 | 52 | screen_set(&screen_ingame); 53 | } 54 | 55 | if(input_pressed(IB_INVENTORY)) { 56 | svin_rpc_send(&(struct server_rpc) { 57 | .type = SRPC_TOGGLE_PAUSE, 58 | }); 59 | gstate.paused = false; 60 | 61 | screen_set(&screen_select_world); 62 | svin_rpc_send(&(struct server_rpc) { 63 | .type = SRPC_UNLOAD_WORLD, 64 | }); 65 | } 66 | } 67 | 68 | static void screen_pause_render2D(struct screen* s, int width, int height) { 69 | // darken background 70 | gfx_texture(false); 71 | gutil_texquad_col(0, 0, 0, 0, 0, 0, width, height, 0, 0, 0, 180); 72 | gfx_texture(true); 73 | 74 | gutil_text(4, 4 + (GFX_GUI_SCALE * 8 + 1) * 0, "PAUSED", GFX_GUI_SCALE * 8, true); 75 | 76 | int icon_offset = GFX_GUI_SCALE * 16; 77 | icon_offset += gutil_control_icon(icon_offset, IB_HOME, "Back to game"); 78 | icon_offset += gutil_control_icon(icon_offset, IB_INVENTORY, "Save & quit"); 79 | } 80 | 81 | struct screen screen_pause = { 82 | .reset = screen_pause_reset, 83 | .update = screen_pause_update, 84 | .render2D = screen_pause_render2D, 85 | .render3D = NULL, 86 | .render_world = false, 87 | }; 88 | -------------------------------------------------------------------------------- /source/game/gui/screen_load_world.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2023 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../../graphics/gui_util.h" 21 | #include "../../graphics/gfx_settings.h" 22 | #include "../../network/server_local.h" 23 | #include "../../platform/gfx.h" 24 | #include "../../platform/input.h" 25 | #include "../game_state.h" 26 | 27 | static void screen_lworld_reset(struct screen* s, int width, int height) { 28 | input_pointer_enable(false); 29 | 30 | if(gstate.local_player) 31 | gstate.local_player->data.local_player.capture_input = false; 32 | } 33 | 34 | static void screen_lworld_update(struct screen* s, float dt) { 35 | if(gstate.world_loaded) 36 | screen_set(&screen_ingame); 37 | } 38 | 39 | static void screen_lworld_render2D(struct screen* s, int width, int height) { 40 | gutil_bg(); 41 | 42 | gutil_text((width - gutil_font_width("Generating level", 8 * GFX_GUI_SCALE)) / 2, 43 | height / 2 - 20 * GFX_GUI_SCALE, "Generating level", 8 * GFX_GUI_SCALE, true); 44 | 45 | gutil_text((width - gutil_font_width("Building terrain", 8 * GFX_GUI_SCALE)) / 2, 46 | height / 2 + 4 * GFX_GUI_SCALE, "Building terrain", 8 * GFX_GUI_SCALE, true); 47 | 48 | gutil_text(2 * GFX_GUI_SCALE, height - 2 * GFX_GUI_SCALE - (9 * GFX_GUI_SCALE) * 2, "Licensed under GPLv3", 8 * GFX_GUI_SCALE, true); 49 | gutil_text(2 * GFX_GUI_SCALE, height - 2 * GFX_GUI_SCALE - (9 * GFX_GUI_SCALE) * 1, "Copyright (c) 2023 ByteBit/xtreme8000", 50 | 8 * GFX_GUI_SCALE, true); 51 | 52 | // just a rough estimate 53 | float progress 54 | = fminf((float)world_loaded_chunks(&gstate.world) / MAX_CHUNKS, 1.0F); 55 | 56 | gfx_texture(false); 57 | gutil_texquad_col((width - 100 * GFX_GUI_SCALE) / 2, height / 2 + 16 * GFX_GUI_SCALE, 0, 0, 0, 0, 100 * GFX_GUI_SCALE, 2 * GFX_GUI_SCALE, 58 | 128, 128, 128, 255); 59 | gutil_texquad_col((width - 100 * GFX_GUI_SCALE) / 2, height / 2 + 16 * GFX_GUI_SCALE, 0, 0, 0, 0, 60 | 100 * GFX_GUI_SCALE * progress, 2 * GFX_GUI_SCALE, 128, 255, 128, 255); 61 | gfx_texture(true); 62 | } 63 | 64 | struct screen screen_load_world = { 65 | .reset = screen_lworld_reset, 66 | .update = screen_lworld_update, 67 | .render2D = screen_lworld_render2D, 68 | .render3D = NULL, 69 | .render_world = false, 70 | }; 71 | -------------------------------------------------------------------------------- /source/block/block_rose.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../network/server_local.h" 21 | #include "blocks.h" 22 | 23 | static enum block_material getMaterial(struct block_info* this) { 24 | return MATERIAL_ORGANIC; 25 | } 26 | 27 | static size_t getBoundingBox(struct block_info* this, bool entity, 28 | struct AABB* x) { 29 | if(x) 30 | aabb_setsize(x, 0.375F, 0.625F, 0.375F); 31 | return entity ? 0 : 1; 32 | } 33 | 34 | static struct face_occlusion* 35 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 36 | return face_occlusion_empty(); 37 | } 38 | 39 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 40 | return tex_atlas_lookup(TEXAT_ROSE); 41 | } 42 | 43 | static bool onItemPlace(struct server_local* s, struct item_data* it, 44 | struct block_info* where, struct block_info* on, 45 | enum side on_side) { 46 | struct block_data blk; 47 | if(!server_world_get_block(&s->world, where->x, where->y - 1, where->z, 48 | &blk)) 49 | return false; 50 | 51 | if(blk.type != BLOCK_DIRT && blk.type != BLOCK_GRASS) 52 | return false; 53 | 54 | return block_place_default(s, it, where, on, on_side); 55 | } 56 | 57 | struct block block_rose = { 58 | .name = "Rose", 59 | .getSideMask = getSideMask, 60 | .getBoundingBox = getBoundingBox, 61 | .getMaterial = getMaterial, 62 | .getTextureIndex = getTextureIndex, 63 | .getDroppedItem = block_drop_default, 64 | .onRandomTick = NULL, 65 | .onRightClick = NULL, 66 | .transparent = false, 67 | .renderBlock = render_block_cross, 68 | .renderBlockAlways = NULL, 69 | .luminance = 0, 70 | .double_sided = true, 71 | .can_see_through = true, 72 | .opacity = 0, 73 | .render_block_data.cross_random_displacement = false, 74 | .ignore_lighting = false, 75 | .flammable = false, 76 | .place_ignore = false, 77 | .digging.hardness = 50, 78 | .digging.tool = TOOL_TYPE_ANY, 79 | .digging.min = TOOL_TIER_ANY, 80 | .digging.best = TOOL_TIER_ANY, 81 | .block_item = { 82 | .has_damage = false, 83 | .max_stack = 64, 84 | .renderItem = render_item_flat, 85 | .onItemPlace = onItemPlace, 86 | .fuel = 0, 87 | .armor.is_armor = false, 88 | .tool.type = TOOL_TYPE_ANY, 89 | }, 90 | }; 91 | -------------------------------------------------------------------------------- /source/block/block_flower.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "../network/server_local.h" 21 | #include "blocks.h" 22 | 23 | static enum block_material getMaterial(struct block_info* this) { 24 | return MATERIAL_ORGANIC; 25 | } 26 | 27 | static size_t getBoundingBox(struct block_info* this, bool entity, 28 | struct AABB* x) { 29 | if(x) 30 | aabb_setsize(x, 0.375F, 0.625F, 0.375F); 31 | return entity ? 0 : 1; 32 | } 33 | 34 | static struct face_occlusion* 35 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 36 | return face_occlusion_empty(); 37 | } 38 | 39 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 40 | return tex_atlas_lookup(TEXAT_DANDELION); 41 | } 42 | 43 | static bool onItemPlace(struct server_local* s, struct item_data* it, 44 | struct block_info* where, struct block_info* on, 45 | enum side on_side) { 46 | struct block_data blk; 47 | if(!server_world_get_block(&s->world, where->x, where->y - 1, where->z, 48 | &blk)) 49 | return false; 50 | 51 | if(blk.type != BLOCK_DIRT && blk.type != BLOCK_GRASS) 52 | return false; 53 | 54 | return block_place_default(s, it, where, on, on_side); 55 | } 56 | 57 | struct block block_flower = { 58 | .name = "Flower", 59 | .getSideMask = getSideMask, 60 | .getBoundingBox = getBoundingBox, 61 | .getMaterial = getMaterial, 62 | .getTextureIndex = getTextureIndex, 63 | .getDroppedItem = block_drop_default, 64 | .onRandomTick = NULL, 65 | .onRightClick = NULL, 66 | .transparent = false, 67 | .renderBlock = render_block_cross, 68 | .renderBlockAlways = NULL, 69 | .luminance = 0, 70 | .double_sided = true, 71 | .can_see_through = true, 72 | .opacity = 0, 73 | .render_block_data.cross_random_displacement = false, 74 | .ignore_lighting = false, 75 | .flammable = false, 76 | .place_ignore = false, 77 | .digging.hardness = 50, 78 | .digging.tool = TOOL_TYPE_ANY, 79 | .digging.min = TOOL_TIER_ANY, 80 | .digging.best = TOOL_TIER_ANY, 81 | .block_item = { 82 | .has_damage = false, 83 | .max_stack = 64, 84 | .renderItem = render_item_flat, 85 | .onItemPlace = onItemPlace, 86 | .fuel = 0, 87 | .armor.is_armor = false, 88 | .tool.type = TOOL_TYPE_ANY, 89 | }, 90 | }; 91 | -------------------------------------------------------------------------------- /source/block/block_log.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | if(side == SIDE_TOP || side == SIDE_BOTTOM) 40 | return tex_atlas_lookup(TEXAT_LOG_OAK_TOP); 41 | 42 | switch(this->block->metadata) { 43 | default: 44 | case 0: return tex_atlas_lookup(TEXAT_LOG_OAK_SIDE); 45 | case 1: return tex_atlas_lookup(TEXAT_LOG_SPRUCE_SIDE); 46 | case 2: return tex_atlas_lookup(TEXAT_LOG_BIRCH_SIDE); 47 | } 48 | } 49 | 50 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 51 | struct random_gen* g, struct server_local* s) { 52 | if(it) { 53 | it->id = this->block->type; 54 | it->durability = this->block->metadata; 55 | it->count = 1; 56 | } 57 | 58 | return 1; 59 | } 60 | 61 | struct block block_log = { 62 | .name = "Log", 63 | .getSideMask = getSideMask, 64 | .getBoundingBox = getBoundingBox, 65 | .getMaterial = getMaterial, 66 | .getTextureIndex = getTextureIndex, 67 | .getDroppedItem = getDroppedItem, 68 | .onRandomTick = NULL, 69 | .onRightClick = NULL, 70 | .transparent = false, 71 | .renderBlock = render_block_full, 72 | .renderBlockAlways = NULL, 73 | .luminance = 0, 74 | .double_sided = false, 75 | .can_see_through = false, 76 | .ignore_lighting = false, 77 | .flammable = true, 78 | .place_ignore = false, 79 | .digging.hardness = 3000, 80 | .digging.tool = TOOL_TYPE_AXE, 81 | .digging.min = TOOL_TIER_ANY, 82 | .digging.best = TOOL_TIER_MAX, 83 | .block_item = { 84 | .has_damage = false, 85 | .max_stack = 64, 86 | .renderItem = render_item_block, 87 | .onItemPlace = block_place_default, 88 | .fuel = 1, 89 | .render_data.block.has_default = false, 90 | .armor.is_armor = false, 91 | .tool.type = TOOL_TYPE_ANY, 92 | }, 93 | }; 94 | -------------------------------------------------------------------------------- /source/block/block_farmland.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_ORGANIC; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 0.9375F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | switch(side) { 36 | case SIDE_TOP: return face_occlusion_empty(); 37 | case SIDE_BOTTOM: return face_occlusion_full(); 38 | default: return face_occlusion_rect(15); 39 | } 40 | } 41 | 42 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 43 | switch(side) { 44 | case SIDE_TOP: 45 | return (this->block->metadata < 7) ? 46 | tex_atlas_lookup(TEXAT_FARMLAND_DRY) : 47 | tex_atlas_lookup(TEXAT_FARMLAND_WET); 48 | default: return tex_atlas_lookup(TEXAT_DIRT); 49 | } 50 | } 51 | 52 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 53 | struct random_gen* g, struct server_local* s) { 54 | if(it) { 55 | it->id = BLOCK_DIRT; 56 | it->durability = 0; 57 | it->count = 1; 58 | } 59 | 60 | return 1; 61 | } 62 | 63 | struct block block_farmland = { 64 | .name = "Farmland", 65 | .getSideMask = getSideMask, 66 | .getBoundingBox = getBoundingBox, 67 | .getMaterial = getMaterial, 68 | .getTextureIndex = getTextureIndex, 69 | .getDroppedItem = getDroppedItem, 70 | .onRandomTick = NULL, 71 | .onRightClick = NULL, 72 | .transparent = false, 73 | .renderBlock = render_block_farmland, 74 | .renderBlockAlways = NULL, 75 | .luminance = 0, 76 | .double_sided = false, 77 | .can_see_through = true, 78 | .opacity = 15, 79 | .ignore_lighting = true, 80 | .flammable = false, 81 | .place_ignore = false, 82 | .digging.hardness = 900, 83 | .digging.tool = TOOL_TYPE_ANY, 84 | .digging.min = TOOL_TIER_ANY, 85 | .digging.best = TOOL_TIER_ANY, 86 | .block_item = { 87 | .has_damage = false, 88 | .max_stack = 64, 89 | .renderItem = render_item_block, 90 | .onItemPlace = block_place_default, 91 | .fuel = 0, 92 | .render_data.block.has_default = false, 93 | .armor.is_armor = false, 94 | .tool.type = TOOL_TYPE_ANY, 95 | }, 96 | }; 97 | -------------------------------------------------------------------------------- /source/chunk.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef CHUNK_H 21 | #define CHUNK_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "cglm/cglm.h" 28 | #include 29 | 30 | #include "block/blocks.h" 31 | #include "chunk_mesher.h" 32 | #include "platform/displaylist.h" 33 | #include "world.h" 34 | 35 | #define CHUNK_SIZE_BITS 0xF 36 | #define CHUNK_SIZE 16 37 | 38 | #define WCOORD_CHUNK_OFFSET(x) \ 39 | ((x) < 0 ? (((x) + 1) / CHUNK_SIZE - 1) : (x) / CHUNK_SIZE) 40 | #define CHUNK_TO_ID(x, y, z) \ 41 | ((((int64_t)(z)&0x3FFFFFFF) << 34) | (((int64_t)(x)&0x3FFFFFFF) << 4) \ 42 | | ((int64_t)(y)&0xF)) 43 | #define W2C_COORD(x) ((x)&CHUNK_SIZE_BITS) 44 | 45 | typedef uint32_t c_coord_t; 46 | 47 | struct chunk { 48 | mat4 model_view; 49 | w_coord_t x, y, z; 50 | uint8_t* blocks; 51 | struct displaylist mesh[13]; 52 | bool has_displist[13]; 53 | bool rebuild_displist; 54 | struct world* world; 55 | uint8_t reachable[6]; 56 | size_t reference_count; 57 | bool has_fog; 58 | struct chunk_step { 59 | bool visited; 60 | enum side from; 61 | uint8_t used_exit_sides; 62 | int steps; 63 | } tmp_data; 64 | ILIST_INTERFACE(ilist_chunks, struct chunk); 65 | ILIST_INTERFACE(ilist_chunks2, struct chunk); 66 | }; 67 | 68 | ILIST_DEF(ilist_chunks, struct chunk, M_POD_OPLIST) 69 | ILIST_DEF(ilist_chunks2, struct chunk, M_POD_OPLIST) 70 | 71 | void chunk_init(struct chunk* c, struct world* world, w_coord_t x, w_coord_t y, 72 | w_coord_t z); 73 | void chunk_ref(struct chunk* c); 74 | void chunk_unref(struct chunk* c); 75 | struct block_data chunk_get_block(struct chunk* c, c_coord_t x, c_coord_t y, 76 | c_coord_t z); 77 | struct block_data chunk_lookup_block(struct chunk* c, w_coord_t x, w_coord_t y, 78 | w_coord_t z); 79 | void chunk_set_block(struct chunk* c, c_coord_t x, c_coord_t y, c_coord_t z, 80 | struct block_data blk); 81 | bool chunk_check_built(struct chunk* c); 82 | void chunk_set_light(struct chunk* c, c_coord_t x, c_coord_t y, c_coord_t z, 83 | uint8_t light); 84 | void chunk_render(struct chunk* c, bool pass, float x, float y, float z); 85 | void chunk_pre_render(struct chunk* c, mat4 view, bool has_fog); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /source/daytime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "daytime.h" 23 | #include "game/game_state.h" 24 | #include "util.h" 25 | 26 | float daytime_brightness(float time) { 27 | return (gstate.world.dimension == WORLD_DIM_OVERWORLD) ? glm_clamp( 28 | cos(daytime_celestial_angle(time) * 2.0F * GLM_PI) * 2.0F + 0.5F, 29 | 0.0F, 1.0F) : 30 | 0.0F; 31 | } 32 | 33 | float daytime_celestial_angle(float time) { 34 | float X = time - 0.25F; 35 | 36 | if(X < 0) 37 | X += 1; 38 | 39 | return X + ((1.0F - (cos(X * GLM_PI) + 1.0F) / 2.0F) - X) / 3.0F; 40 | } 41 | 42 | float daytime_get_time(void) { 43 | return gstate.world_time 44 | + time_diff_s(gstate.world_time_start, time_get()) * 1000.0f / DAY_TICK_MS; 45 | } 46 | 47 | void daytime_sky_colors(float time, vec3 top_plane, vec3 bottom_plane, 48 | vec3 atmosphere) { 49 | assert(top_plane && bottom_plane && atmosphere); 50 | 51 | if(gstate.world.dimension == WORLD_DIM_OVERWORLD) { 52 | float brightness_mul = daytime_brightness(time); 53 | 54 | vec3 world_sky_color = { 55 | 0.6222222F - (0.7F / 3.0F) * 0.05F, 56 | 0.5F + (0.7F / 3.0F) * 0.1F, 57 | 1.0F, 58 | }; 59 | 60 | hsv2rgb(world_sky_color + 0, world_sky_color + 1, world_sky_color + 2); 61 | glm_vec3_scale(world_sky_color, brightness_mul, world_sky_color); 62 | 63 | vec3 fog_color = { 64 | 0.7529412F * brightness_mul * 0.94F + 0.06F, 65 | 0.8470588F * brightness_mul * 0.94F + 0.06F, 66 | 1.0F * brightness_mul * 0.91F + 0.09F, 67 | }; 68 | 69 | vec3 atmosphere_color; 70 | glm_vec3_lerp(fog_color, world_sky_color, 0.29F, atmosphere_color); 71 | glm_vec3_scale(atmosphere_color, 72 | powf(0.8F, (1.0F - brightness_mul) * 11.0F), 73 | atmosphere_color); 74 | 75 | vec3 bottom_plane_color = {0.04F, 0.04F, 0.1F}; 76 | glm_vec3_muladd(world_sky_color, (vec3) {0.2F, 0.2F, 0.6F}, 77 | bottom_plane_color); 78 | 79 | glm_vec3_scale(atmosphere_color, 255.0F, atmosphere); 80 | glm_vec3_scale(world_sky_color, 255.0F, top_plane); 81 | glm_vec3_scale(bottom_plane_color, 255.0F, bottom_plane); 82 | } else { 83 | vec3 const_color = {0.2F, 0.03F, 0.03F}; 84 | glm_vec3_scale(const_color, 255.0F, atmosphere); 85 | glm_vec3_scale(const_color, 255.0F, top_plane); 86 | glm_vec3_scale(const_color, 255.0F, bottom_plane); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /source/network/server_local.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef SERVER_LOCAL 21 | #define SERVER_LOCAL 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "../item/inventory.h" 28 | #include "../world.h" 29 | #include "level_archive.h" 30 | #include "server_world.h" 31 | #include "../entity/entity.h" 32 | 33 | #define MAX_REGIONS 4 34 | #define MAX_VIEW_DISTANCE 5 // in chunks 35 | #define MAX_HIGH_DETAIL_VIEW_DISTANCE 2 36 | #define MAX_CHUNKS ((MAX_VIEW_DISTANCE * 2 + 2) * (MAX_VIEW_DISTANCE * 2 + 2)) 37 | #define MAX_HIGH_DETAIL_CHUNKS ((MAX_HIGH_DETAIL_VIEW_DISTANCE * 2 + 2) * (MAX_HIGH_DETAIL_VIEW_DISTANCE * 2 + 2)) 38 | #define MAX_CHESTS 256 39 | #define MAX_CHEST_SLOTS 54 40 | #define MAX_SIGNS 256 41 | 42 | #define MAX_OXYGEN 351 43 | #define OXYGEN_THRESHOLD 0 44 | 45 | struct complex_block_pos { 46 | int x, y, z; 47 | }; 48 | 49 | struct server_local { 50 | struct random_gen rand_src; 51 | struct { 52 | double x, y, z; 53 | float rx, ry; 54 | enum world_dim dimension; 55 | bool has_pos; 56 | bool finished_loading; 57 | struct inventory inventory; 58 | struct inventory* active_inventory; 59 | short health; 60 | int oxygen; 61 | int spawn_x, spawn_y, spawn_z; 62 | float vel_y, old_vel_y; 63 | int fall_y; 64 | } player; 65 | struct server_world world; 66 | dict_entity_t entities; 67 | struct complex_block_pos chest_pos[MAX_CHESTS]; 68 | struct item_data chest_items[MAX_CHESTS][MAX_CHEST_SLOTS]; 69 | struct complex_block_pos sign_pos[MAX_SIGNS]; 70 | char sign_texts[MAX_SIGNS][SIGN_SIZE]; 71 | uint64_t world_time; 72 | string_t level_name; 73 | struct level_archive level; 74 | bool paused; 75 | ptime_t last_tick; 76 | }; 77 | 78 | void server_local_create(struct server_local* s); 79 | struct entity* server_local_spawn_minecart(vec3 pos, struct server_local* s); 80 | struct entity* server_local_spawn_item(vec3 pos, struct item_data* it, 81 | bool throw, struct server_local* s); 82 | struct entity* server_local_spawn_monster(vec3 pos, int monster_id, 83 | struct server_local* s); 84 | void server_local_spawn_block_drops(struct server_local* s, 85 | struct block_info* blk_info); 86 | void server_local_send_inv_changes(set_inv_slot_t changes, 87 | struct inventory* inv, uint8_t window); 88 | void server_local_set_player_health(struct server_local* s, short new_health); 89 | #endif 90 | -------------------------------------------------------------------------------- /source/block/block_minecart.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_WOOD; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | uint8_t tex[SIDE_MAX] = { 40 | [SIDE_TOP] = tex_atlas_lookup(TEXAT_CHEST_TOP), 41 | [SIDE_BOTTOM] = tex_atlas_lookup(TEXAT_CHEST_TOP), 42 | [SIDE_BACK] = tex_atlas_lookup(TEXAT_CHEST_SIDE), 43 | [SIDE_FRONT] = tex_atlas_lookup(TEXAT_CHEST_SIDE), 44 | [SIDE_LEFT] = tex_atlas_lookup(TEXAT_CHEST_SIDE), 45 | [SIDE_RIGHT] = tex_atlas_lookup(TEXAT_CHEST_SIDE), 46 | }; 47 | 48 | switch(this->block->metadata) { 49 | case 0: tex[SIDE_FRONT] = tex_atlas_lookup(TEXAT_CHEST_FRONT_SINGLE); break; 50 | case 1: tex[SIDE_RIGHT] = tex_atlas_lookup(TEXAT_CHEST_FRONT_SINGLE); break; 51 | case 2: tex[SIDE_BACK] = tex_atlas_lookup(TEXAT_CHEST_FRONT_SINGLE); break; 52 | case 3: tex[SIDE_LEFT] = tex_atlas_lookup(TEXAT_CHEST_FRONT_SINGLE); break; 53 | } 54 | 55 | return tex[side]; 56 | } 57 | 58 | 59 | 60 | struct block block_minecart = { 61 | .name = "Sand", 62 | .getSideMask = getSideMask, 63 | .getBoundingBox = getBoundingBox, 64 | .getMaterial = getMaterial, 65 | .getTextureIndex = getTextureIndex, 66 | .getDroppedItem = block_drop_default, 67 | .onRandomTick = NULL, 68 | .onRightClick = NULL, 69 | .transparent = false, 70 | .renderBlock = render_block_full, 71 | .renderBlockAlways = NULL, 72 | .luminance = 0, 73 | .double_sided = false, 74 | .can_see_through = false, 75 | .ignore_lighting = false, 76 | .flammable = false, 77 | .place_ignore = false, 78 | .digging.hardness = 750, 79 | .digging.tool = TOOL_TYPE_SHOVEL, 80 | .digging.min = TOOL_TIER_ANY, 81 | .digging.best = TOOL_TIER_MAX, 82 | .block_item = { 83 | .has_damage = false, 84 | .max_stack = 64, 85 | .renderItem = render_item_block, 86 | .onItemPlace = block_place_default, 87 | .fuel = 0, 88 | .render_data.block.has_default = false, 89 | .armor.is_armor = false, 90 | .tool.type = TOOL_TYPE_ANY, 91 | }, 92 | }; 93 | 94 | -------------------------------------------------------------------------------- /source/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "util.h" 27 | 28 | void rand_gen_seed(struct random_gen* g) { 29 | assert(g); 30 | g->seed = time(NULL); 31 | } 32 | 33 | uint32_t rand_gen(struct random_gen* g) { 34 | g->seed ^= g->seed << 13; 35 | g->seed ^= g->seed >> 17; 36 | g->seed ^= g->seed << 5; 37 | return g->seed; 38 | } 39 | 40 | int rand_gen_range(struct random_gen* g, int min, int max) { 41 | assert(g); 42 | return rand_gen(g) % (max - min) + min; 43 | } 44 | 45 | float rand_gen_flt(struct random_gen* g) { 46 | assert(g); 47 | return (float)rand_gen(g) / UINT32_MAX; 48 | } 49 | 50 | int rand_gen_int(struct random_gen* g, int max) { 51 | assert(g); 52 | if (max <= 0) return 0; 53 | return (int)(rand_gen_flt(g) * max); 54 | } 55 | 56 | void* file_read(const char* name) { 57 | FILE* f = fopen(name, "rb"); 58 | 59 | if(!f) 60 | return NULL; 61 | 62 | fseek(f, 0, SEEK_END); 63 | size_t length = ftell(f); 64 | fseek(f, 0, SEEK_SET); 65 | char* res = malloc(length + 1); 66 | res[length] = 0; 67 | (void)!fread(res, length, 1, f); 68 | fclose(f); 69 | 70 | return res; 71 | } 72 | 73 | uint32_t hash_u32(uint32_t x) { 74 | x = ((x >> 16) ^ x) * 0x45D9F3B; 75 | x = ((x >> 16) ^ x) * 0x45D9F3B; 76 | x = (x >> 16) ^ x; 77 | return x; 78 | } 79 | 80 | void hsv2rgb(float* h, float* s, float* v) { 81 | assert(h && s && v); 82 | 83 | int i = floor((*h) * 6.0F); 84 | float f = (*h) * 6.0F - i; 85 | float p = (*v) * (1.0F - *s); 86 | float q = (*v) * (1.0F - f * (*s)); 87 | float t = (*v) * (1.0F - (1.0F - f) * (*s)); 88 | 89 | float r, g, b; 90 | switch(i % 6) { 91 | case 0: r = *v, g = t, b = p; break; 92 | case 1: r = q, g = *v, b = p; break; 93 | case 2: r = p, g = *v, b = t; break; 94 | case 3: r = p, g = q, b = *v; break; 95 | case 4: r = t, g = p, b = *v; break; 96 | case 5: r = *v, g = p, b = q; break; 97 | } 98 | 99 | *h = r; 100 | *s = g; 101 | *v = b; 102 | } 103 | 104 | inline uint8_t nibble_read(uint8_t* base, size_t idx) { 105 | return (base[idx / 2] >> ((idx % 2) * 4)) & 0xF; 106 | } 107 | 108 | inline void nibble_write(uint8_t* base, size_t idx, uint8_t data) { 109 | base[idx / 2] = (base[idx / 2] & ~(0x0F << ((idx % 2) * 4))) 110 | | (data << ((idx % 2) * 4)); 111 | } 112 | -------------------------------------------------------------------------------- /source/block/block_lava.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | #include "../graphics/gfx_settings.h" 22 | 23 | static enum block_material getMaterial(struct block_info* this) { 24 | return MATERIAL_STONE; 25 | } 26 | 27 | static size_t getBoundingBox(struct block_info* this, bool entity, 28 | struct AABB* x) { 29 | return 0; 30 | } 31 | 32 | static struct face_occlusion* 33 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 34 | #ifdef GFX_FANCY_LIQUIDS 35 | int block_height = (this->block->metadata & 0x8) ? 36 | 16 : 37 | (8 - this->block->metadata) * 2 * 7 / 8; 38 | switch(side) { 39 | case SIDE_TOP: 40 | return (it->block->type == this->block->type) ? 41 | face_occlusion_full() : 42 | face_occlusion_empty(); 43 | case SIDE_BOTTOM: return face_occlusion_full(); 44 | default: return face_occlusion_rect(block_height); 45 | } 46 | #else 47 | return face_occlusion_full(); 48 | #endif 49 | } 50 | 51 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 52 | #ifdef GFX_FANCY_LIQUIDS 53 | return TEXTURE_INDEX(2, 0); 54 | #else 55 | return tex_atlas_lookup(TEXAT_LAVA_STATIC); 56 | #endif 57 | } 58 | 59 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 60 | struct random_gen* g, struct server_local* s) { 61 | return 0; 62 | } 63 | 64 | struct block block_lava = { 65 | .name = "Lava", 66 | .getSideMask = getSideMask, 67 | .getBoundingBox = getBoundingBox, 68 | .getMaterial = getMaterial, 69 | .getTextureIndex = getTextureIndex, 70 | .getDroppedItem = getDroppedItem, 71 | .onRandomTick = NULL, 72 | .onRightClick = NULL, 73 | #ifdef GFX_FANCY_LIQUIDS 74 | .transparent = true, 75 | .renderBlock = render_block_fluid, 76 | #else 77 | .transparent = false, 78 | .renderBlock = render_block_full, 79 | #endif 80 | .renderBlockAlways = NULL, 81 | .luminance = 15, 82 | .double_sided = false, 83 | .can_see_through = true, 84 | .opacity = 15, 85 | .ignore_lighting = false, 86 | .flammable = false, 87 | .place_ignore = true, 88 | .digging.hardness = 150000, 89 | .digging.tool = TOOL_TYPE_ANY, 90 | .digging.min = TOOL_TIER_ANY, 91 | .digging.best = TOOL_TIER_ANY, 92 | .block_item = { 93 | .has_damage = false, 94 | .max_stack = 64, 95 | .renderItem = render_item_flat, 96 | .onItemPlace = block_place_default, 97 | .fuel = 0, 98 | .armor.is_armor = false, 99 | .tool.type = TOOL_TYPE_ANY, 100 | }, 101 | }; 102 | -------------------------------------------------------------------------------- /source/block/block_double_slab.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | 22 | static enum block_material getMaterial(struct block_info* this) { 23 | return MATERIAL_STONE; 24 | } 25 | 26 | static size_t getBoundingBox(struct block_info* this, bool entity, 27 | struct AABB* x) { 28 | if(x) 29 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 30 | return 1; 31 | } 32 | 33 | static struct face_occlusion* 34 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 35 | return face_occlusion_full(); 36 | } 37 | 38 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 39 | switch(this->block->metadata) { 40 | default: 41 | case 0: 42 | return (side == SIDE_TOP || side == SIDE_BOTTOM) ? 43 | tex_atlas_lookup(TEXAT_SLAB_STONE_TOP) : 44 | tex_atlas_lookup(TEXAT_SLAB_STONE_SIDE); 45 | case 1: 46 | return (side == SIDE_TOP) ? 47 | tex_atlas_lookup(TEXAT_SANDSTONE_TOP) : 48 | ((side == SIDE_BOTTOM) ? 49 | tex_atlas_lookup(TEXAT_SANDSTONE_BOTTOM) : 50 | tex_atlas_lookup(TEXAT_SANDSTONE_SIDE)); 51 | case 2: return tex_atlas_lookup(TEXAT_PLANKS); 52 | case 3: return tex_atlas_lookup(TEXAT_COBBLESTONE); 53 | } 54 | } 55 | 56 | static size_t getDroppedItem(struct block_info* this, struct item_data* it, 57 | struct random_gen* g, struct server_local* s) { 58 | if(it) { 59 | it->id = BLOCK_SLAB; 60 | it->durability = this->block->metadata; 61 | it->count = 2; 62 | } 63 | 64 | return 1; 65 | } 66 | 67 | struct block block_double_slab = { 68 | .name = "Double Slab", 69 | .getSideMask = getSideMask, 70 | .getBoundingBox = getBoundingBox, 71 | .getMaterial = getMaterial, 72 | .getTextureIndex = getTextureIndex, 73 | .getDroppedItem = getDroppedItem, 74 | .onRandomTick = NULL, 75 | .onRightClick = NULL, 76 | .transparent = false, 77 | .renderBlock = render_block_full, 78 | .renderBlockAlways = NULL, 79 | .luminance = 0, 80 | .double_sided = false, 81 | .can_see_through = false, 82 | .ignore_lighting = false, 83 | .flammable = false, 84 | .place_ignore = false, 85 | .digging.hardness = 3000, 86 | .digging.tool = TOOL_TYPE_PICKAXE, 87 | .digging.min = TOOL_TIER_WOOD, 88 | .digging.best = TOOL_TIER_MAX, 89 | .block_item = { 90 | .has_damage = false, 91 | .max_stack = 64, 92 | .renderItem = render_item_block, 93 | .onItemPlace = block_place_default, 94 | .fuel = 0, 95 | .render_data.block.has_default = false, 96 | .armor.is_armor = false, 97 | .tool.type = TOOL_TYPE_ANY, 98 | }, 99 | }; 100 | -------------------------------------------------------------------------------- /source/network/client_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #ifndef CLIENT_INTERFACE_H 21 | #define CLIENT_INTERFACE_H 22 | 23 | #include "../entity/entity.h" 24 | #include "../item/items.h" 25 | #include "../item/window_container.h" 26 | #include "../world.h" 27 | 28 | #include "../cglm/cglm.h" 29 | 30 | enum client_rpc_type { 31 | CRPC_CHUNK, 32 | CRPC_UNLOAD_CHUNK, 33 | CRPC_INVENTORY_SLOT, 34 | CRPC_PLAYER_POS, 35 | CRPC_TIME_SET, 36 | CRPC_WORLD_RESET, 37 | CRPC_SET_BLOCK, 38 | CRPC_WINDOW_TRANSACTION, 39 | CRPC_SPAWN_ITEM, 40 | CRPC_PICKUP_ITEM, 41 | CRPC_ENTITY_DESTROY, 42 | CRPC_ENTITY_MOVE, 43 | CRPC_OPEN_WINDOW, 44 | CRPC_PLAYER_SET_HEALTH, 45 | CRPC_SPAWN_MONSTER, 46 | CRPC_SPAWN_MINECART, 47 | }; 48 | 49 | struct client_rpc { 50 | enum client_rpc_type type; 51 | union { 52 | struct { 53 | w_coord_t x, y, z; 54 | w_coord_t sx, sy, sz; 55 | uint8_t* ids; 56 | uint8_t* metadata; 57 | uint8_t* lighting_sky; 58 | uint8_t* lighting_torch; 59 | } chunk; 60 | struct { 61 | w_coord_t x, z; 62 | } unload_chunk; 63 | struct { 64 | uint8_t window; 65 | uint8_t slot; 66 | struct item_data item; 67 | } inventory_slot; 68 | struct { 69 | vec3 position; 70 | vec2 rotation; 71 | } player_pos; 72 | uint64_t time_set; 73 | struct { 74 | enum world_dim dimension; 75 | uint32_t local_entity; 76 | } world_reset; 77 | struct { 78 | w_coord_t x, y, z; 79 | struct block_data block; 80 | } set_block; 81 | struct { 82 | uint8_t window; 83 | uint16_t action_id; 84 | bool accepted; 85 | } window_transaction; 86 | struct { 87 | uint8_t window; 88 | enum window_type type; 89 | uint8_t slot_count; 90 | } window_open; 91 | struct { 92 | uint32_t entity_id; 93 | struct item_data item; 94 | vec3 pos; 95 | vec3 vel; 96 | } spawn_item; 97 | struct { 98 | uint32_t entity_id; 99 | int monster_id; 100 | vec3 pos; 101 | } spawn_monster; 102 | struct { 103 | uint32_t entity_id; 104 | vec3 pos; 105 | } spawn_minecart; 106 | struct { 107 | uint32_t entity_id; 108 | uint32_t collector_id; 109 | } pickup_item; 110 | struct { 111 | uint32_t entity_id; 112 | } entity_destroy; 113 | struct { 114 | uint32_t entity_id; 115 | vec3 pos; 116 | } entity_move; 117 | struct { 118 | int16_t health; 119 | } player_set_health; 120 | } payload; 121 | }; 122 | 123 | void clin_init(void); 124 | void clin_update(void); 125 | void clin_rpc_send(struct client_rpc* call); 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /source/block/block_dirt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 ByteBit/xtreme8000 3 | 4 | This file is part of CavEX. 5 | 6 | CavEX is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | CavEX is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with CavEX. If not, see . 18 | */ 19 | 20 | #include "blocks.h" 21 | #include "../network/server_local.h" 22 | 23 | static enum block_material getMaterial(struct block_info* this) { 24 | return MATERIAL_ORGANIC; 25 | } 26 | 27 | static size_t getBoundingBox(struct block_info* this, bool entity, 28 | struct AABB* x) { 29 | if(x) 30 | aabb_setsize(x, 1.0F, 1.0F, 1.0F); 31 | return 1; 32 | } 33 | 34 | static struct face_occlusion* 35 | getSideMask(struct block_info* this, enum side side, struct block_info* it) { 36 | return face_occlusion_full(); 37 | } 38 | 39 | static uint8_t getTextureIndex(struct block_info* this, enum side side) { 40 | return tex_atlas_lookup(TEXAT_DIRT); 41 | } 42 | 43 | static void onRightClick(struct server_local* s, struct item_data* it, 44 | struct block_info* where, struct block_info* on, 45 | enum side on_side) { 46 | if (it && items[it->id] && items[it->id]->tool.type == TOOL_TYPE_HOE) { 47 | struct block_data above; 48 | if (server_world_get_block(&s->world, on->x, on->y + 1, on->z, &above) && 49 | above.type == BLOCK_AIR) { 50 | server_world_set_block(s, on->x, on->y, on->z, (struct block_data){ 51 | .type = BLOCK_FARMLAND, 52 | .metadata = 0 53 | }); 54 | return; 55 | } 56 | } 57 | 58 | // Fallback: if it's not a hoe.. just place what you wanted to place 59 | if (it && items[it->id] && items[it->id]->onItemPlace) { 60 | items[it->id]->onItemPlace(s, it, where, on, on_side); 61 | } 62 | } 63 | 64 | 65 | struct block block_dirt = { 66 | .name = "Dirt", 67 | .getSideMask = getSideMask, 68 | .getBoundingBox = getBoundingBox, 69 | .getMaterial = getMaterial, 70 | .getTextureIndex = getTextureIndex, 71 | .getDroppedItem = block_drop_default, 72 | .onRandomTick = NULL, 73 | .onRightClick = onRightClick, 74 | .transparent = false, 75 | .renderBlock = render_block_full, 76 | .renderBlockAlways = NULL, 77 | .luminance = 0, 78 | .double_sided = false, 79 | .can_see_through = false, 80 | .ignore_lighting = false, 81 | .flammable = false, 82 | .place_ignore = false, 83 | .digging.hardness = 750, 84 | .digging.tool = TOOL_TYPE_SHOVEL, 85 | .digging.min = TOOL_TIER_ANY, 86 | .digging.best = TOOL_TIER_MAX, 87 | .block_item = { 88 | .has_damage = false, 89 | .max_stack = 64, 90 | .renderItem = render_item_block, 91 | .onItemPlace = block_place_default, 92 | .fuel = 0, 93 | .render_data.block.has_default = false, 94 | .armor.is_armor = false, 95 | .tool.type = TOOL_TYPE_ANY, 96 | }, 97 | }; 98 | --------------------------------------------------------------------------------