From 5569bd711e073d796ac851c392e245cd17c0136b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 13 Jan 2024 14:07:49 +0300 Subject: [PATCH 1/5] added bazalt_breaker + scripting fix --- res/content/base/content.json | 55 +++++++++--------- res/content/base/items/bazalt_breaker.json | 4 ++ res/content/base/scripts/bazalt_breaker.lua | 3 + .../base/textures/items/bazalt_breaker.png | Bin 0 -> 672 bytes src/logic/PlayerController.cpp | 2 +- 5 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 res/content/base/items/bazalt_breaker.json create mode 100644 res/content/base/scripts/bazalt_breaker.lua create mode 100644 res/content/base/textures/items/bazalt_breaker.png diff --git a/res/content/base/content.json b/res/content/base/content.json index 71b5d16d..ef2f084b 100644 --- a/res/content/base/content.json +++ b/res/content/base/content.json @@ -1,27 +1,30 @@ { - "blocks": [ - "dirt", - "grass_block", - "lamp", - "glass", - "planks", - "wood", - "leaves", - "stone", - "water", - "sand", - "bazalt", - "grass", - "flower", - "brick", - "metal", - "rust", - "red_lamp", - "green_lamp", - "blue_lamp", - "pane", - "pipe", - "lightbulb", - "torch" - ] -} + "items": [ + "bazalt_breaker" + ], + "blocks": [ + "dirt", + "grass_block", + "lamp", + "glass", + "planks", + "wood", + "leaves", + "stone", + "water", + "sand", + "bazalt", + "grass", + "flower", + "brick", + "metal", + "rust", + "red_lamp", + "green_lamp", + "blue_lamp", + "pane", + "pipe", + "lightbulb", + "torch" + ] +} \ No newline at end of file diff --git a/res/content/base/items/bazalt_breaker.json b/res/content/base/items/bazalt_breaker.json new file mode 100644 index 00000000..59aeabdb --- /dev/null +++ b/res/content/base/items/bazalt_breaker.json @@ -0,0 +1,4 @@ +{ + "icon-type": "sprite", + "icon": "items:bazalt_breaker" +} diff --git a/res/content/base/scripts/bazalt_breaker.lua b/res/content/base/scripts/bazalt_breaker.lua new file mode 100644 index 00000000..41cba031 --- /dev/null +++ b/res/content/base/scripts/bazalt_breaker.lua @@ -0,0 +1,3 @@ +function on_block_break_by(x, y, z, p) + set_block(x, y, z, 0, 0) +end diff --git a/res/content/base/textures/items/bazalt_breaker.png b/res/content/base/textures/items/bazalt_breaker.png new file mode 100644 index 0000000000000000000000000000000000000000..2e15563ffbcb86a213b8e8c8f7107dc6ea0ca984 GIT binary patch literal 672 zcmV;R0$=@!P)EX>4Tx04R}tkv&MmP!xqvTct%>9IPP4AwzYtAS&XhRVYG*P%E_RVDi#GXws0R zxHt-~1qXi?s}3&Cx;nTDg5VE`vxAeOipV2qvfq`3~Z_S-s`y8haK$d2ez5xyn zfzc9WuY0^Z)IGOy{D4^000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2j~F}3Ofn0Fc4?}000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0001YNklrt.funcsset.on_use_on_block) { + if (!input.shift && item->rt.funcsset.on_block_break_by) { if (scripting::on_item_break_block(player, item, x, y, z)) return; } From f6c26fee6e1c4c5957bbb6830e54bd116cad4acd Mon Sep 17 00:00:00 2001 From: rekvizitt <58174945+rekvizitt@users.noreply.github.com> Date: Sat, 13 Jan 2024 15:17:33 +0300 Subject: [PATCH 2/5] Update be_BY.txt Added translate for Content Error. --- res/texts/be_BY.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/res/texts/be_BY.txt b/res/texts/be_BY.txt index d49259fe..cef3570f 100644 --- a/res/texts/be_BY.txt +++ b/res/texts/be_BY.txt @@ -14,6 +14,7 @@ menu.Quit=Выхад menu.Continue=Працягнуть menu.Save and Quit to Menu=Захаваць і Выйсці ў Меню menu.missing-content=Адсутнічае Кантэнт! +menu.Content Error=Памылка Кантэнту menu.Controls=Кіраванне menu.Back to Main Menu=Вярнуцца ў Меню menu.Settings=Налады @@ -50,4 +51,4 @@ player.attack=Атакаваць / Ламаць player.build=Паставіць Блок player.flight=Палёт camera.zoom=Прыбліжэнне -camera.mode=Змяніць Рэжым Камеры \ No newline at end of file +camera.mode=Змяніць Рэжым Камеры From 3183513e559daa07c7453026a167b409c4ca9b87 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 13 Jan 2024 20:48:24 +0300 Subject: [PATCH 3/5] luaL_openlib replacement fix --- src/logic/scripting/api_lua.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/logic/scripting/api_lua.cpp b/src/logic/scripting/api_lua.cpp index c48e4000..a5f0a7b2 100644 --- a/src/logic/scripting/api_lua.cpp +++ b/src/logic/scripting/api_lua.cpp @@ -14,10 +14,10 @@ #include "../../lighting/Lighting.h" #include "../../logic/BlocksController.h" -#if (LUA_VERSION_NUM < 503 and not defined(LUAJIT_VERSION)) -static void luaL_openlib(lua_State* L, const char* name, const luaL_Reg* libfuncs) { +#if (LUA_VERSION_NUM < 502) +inline void luaL_openlib(lua_State* L, const char* name, const luaL_Reg* libfuncs, int nup) { lua_newtable(L); - luaL_setfuncs(L, libfuncs, 0); + luaL_setfuncs(L, libfuncs, nup); lua_setglobal(L, name); } #endif From 9fd675895db99fa368e970eeaae38a4502bb9c30 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 13 Jan 2024 21:20:25 +0300 Subject: [PATCH 4/5] physics: step height --- src/physics/PhysicsSolver.cpp | 30 ++++++++++++++++++++++++------ src/physics/PhysicsSolver.h | 28 +++++++++++++++++----------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index 2748ffa5..e5a588c9 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -36,7 +36,8 @@ void PhysicsSolver::step( vel += gravity * dt * gravityScale; if (collisions) { - colisionCalc(chunks, hitbox, vel, pos, half); + colisionCalc(chunks, hitbox, vel, pos, half, + (gravityScale > 0.0f) ? 0.5f : 0.0f); } vel.x *= glm::max(0.0f, 1.0f - dt * linear_damping); vel.z *= glm::max(0.0f, 1.0f - dt * linear_damping); @@ -78,7 +79,8 @@ void PhysicsSolver::colisionCalc( Hitbox* hitbox, vec3& vel, vec3& pos, - const vec3 half) + const vec3 half, + float stepHeight) { // step size (smaller - more accurate, but slower) float s = 2.0f/BLOCK_AABB_GRID; @@ -86,7 +88,7 @@ void PhysicsSolver::colisionCalc( const AABB* aabb; if (vel.x < 0.0f){ - for (float y = (pos.y-half.y+E); y <= (pos.y+half.y-E); y+=s){ + for (float y = (pos.y-half.y+E+stepHeight); y <= (pos.y+half.y-E); y+=s){ for (float z = (pos.z-half.z+E); z <= (pos.z+half.z-E); z+=s){ float x = (pos.x-half.x-E); if ((aabb = chunks->isObstacleAt(x,y,z))){ @@ -101,7 +103,7 @@ void PhysicsSolver::colisionCalc( } } if (vel.x > 0.0f){ - for (float y = (pos.y-half.y+E); y <= (pos.y+half.y-E); y+=s){ + for (float y = (pos.y-half.y+E+stepHeight); y <= (pos.y+half.y-E); y+=s){ for (float z = (pos.z-half.z+E); z <= (pos.z+half.z-E); z+=s){ float x = (pos.x+half.x+E); if ((aabb = chunks->isObstacleAt(x,y,z))){ @@ -117,7 +119,7 @@ void PhysicsSolver::colisionCalc( } if (vel.z < 0.0f){ - for (float y = (pos.y-half.y+E); y <= (pos.y+half.y-E); y+=s){ + for (float y = (pos.y-half.y+E+stepHeight); y <= (pos.y+half.y-E); y+=s){ for (float x = (pos.x-half.x+E); x <= (pos.x+half.x-E); x+=s){ float z = (pos.z-half.z-E); if ((aabb = chunks->isObstacleAt(x,y,z))){ @@ -133,7 +135,7 @@ void PhysicsSolver::colisionCalc( } if (vel.z > 0.0f){ - for (float y = (pos.y-half.y+E); y <= (pos.y+half.y-E); y+=s){ + for (float y = (pos.y-half.y+E+stepHeight); y <= (pos.y+half.y-E); y+=s){ for (float x = (pos.x-half.x+E); x <= (pos.x+half.x-E); x+=s){ float z = (pos.z+half.z+E); if ((aabb = chunks->isObstacleAt(x,y,z))){ @@ -164,6 +166,22 @@ void PhysicsSolver::colisionCalc( } } } + if (stepHeight > 0.0 && vel.y <= 0.0f){ + for (float x = (pos.x-half.x+E); x <= (pos.x+half.x-E); x+=s){ + for (float z = (pos.z-half.z+E); z <= (pos.z+half.z-E); z+=s){ + float y = (pos.y-half.y+E); + if ((aabb = chunks->isObstacleAt(x,y,z))){ + vel.y *= 0.0f; + float newy = floor(y) + aabb->max().y + half.y; + if (glm::abs(newy-pos.y) <= MAX_FIX+stepHeight) { + pos.y = newy; + } + hitbox->grounded = true; + break; + } + } + } + } if (vel.y > 0.0f){ for (float x = (pos.x-half.x+E); x <= (pos.x+half.x-E); x+=s){ for (float z = (pos.z-half.z+E); z <= (pos.z+half.z-E); z+=s){ diff --git a/src/physics/PhysicsSolver.h b/src/physics/PhysicsSolver.h index 6784b417..08bccfca 100644 --- a/src/physics/PhysicsSolver.h +++ b/src/physics/PhysicsSolver.h @@ -8,18 +8,24 @@ class Hitbox; class Chunks; class PhysicsSolver { - glm::vec3 gravity; + glm::vec3 gravity; public: - PhysicsSolver(glm::vec3 gravity); - void step(Chunks* chunks, - Hitbox* hitbox, - float delta, - uint substeps, - bool shifting, - float gravityScale, - bool collisions); - void colisionCalc(Chunks* chunks, Hitbox* hitbox, glm::vec3& vel, glm::vec3& pos, const glm::vec3 half); - bool isBlockInside(int x, int y, int z, Hitbox* hitbox); + PhysicsSolver(glm::vec3 gravity); + void step(Chunks* chunks, + Hitbox* hitbox, + float delta, + uint substeps, + bool shifting, + float gravityScale, + bool collisions); + void colisionCalc( + Chunks* chunks, + Hitbox* hitbox, + glm::vec3& vel, + glm::vec3& pos, + const glm::vec3 half, + float stepHeight); + bool isBlockInside(int x, int y, int z, Hitbox* hitbox); }; #endif /* PHYSICS_PHYSICSSOLVER_H_ */ From 6d60cc82760f985c575c6625a25cfaa4fc2dd7cb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 13 Jan 2024 21:33:36 +0300 Subject: [PATCH 5/5] small fix --- src/physics/PhysicsSolver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/physics/PhysicsSolver.cpp b/src/physics/PhysicsSolver.cpp index e5a588c9..834d5389 100644 --- a/src/physics/PhysicsSolver.cpp +++ b/src/physics/PhysicsSolver.cpp @@ -176,7 +176,6 @@ void PhysicsSolver::colisionCalc( if (glm::abs(newy-pos.y) <= MAX_FIX+stepHeight) { pos.y = newy; } - hitbox->grounded = true; break; } }