From 15068e5b4b578e6aac3966e5eca4cbad4c092ec7 Mon Sep 17 00:00:00 2001 From: neveix Date: Fri, 14 Aug 2026 22:23:40 +0500 Subject: [PATCH 01/20] fix p.8 --- res/content/base/modules/util.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/res/content/base/modules/util.lua b/res/content/base/modules/util.lua index 4d25ccb91..db5e4f2f3 100644 --- a/res/content/base/modules/util.lua +++ b/res/content/base/modules/util.lua @@ -2,6 +2,26 @@ local util = {} local DROP_FORCE = 8 local DROP_INIT_VEL = {0, 3, 0} +local DROP_MAX_ITEM_DIR_SHIFT_DEGREES = 65 + +local function calculate_item_drop_dir(pid) + local yaw, pitch = player.get_rot(pid) + local vp = gui.get_viewport() + local mpos = table.map(input.get_mouse_pos(), function(i, v) + return v / vp[i] - 0.5 + end) + if not hud.is_inventory_open() and not hud.is_player_inventory_open() then + mpos = {0, 0} + end + pitch = math.clamp(pitch - mpos[2]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2, -90, 90) + yaw = math.rad(yaw + 90 -mpos[1]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2) + pitch = math.rad(pitch) + return vec3.normalize({ + math.cos(yaw) * math.cos(pitch), + math.sin(pitch), + -math.sin(yaw) * math.cos(pitch) + }) +end ---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack function util.drop_from_slot(invid, slot, mode) @@ -30,7 +50,8 @@ function util.drop_from_slot(invid, slot, mode) local data = inventory.get_all_data(invid, slot) local pvel = { player.get_vel(pid) } local ppos = vec3.add({ player.get_pos(pid) }, { 0, 0.7, 0 }) - local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE) + local dir = calculate_item_drop_dir(pid) + local throw_force = vec3.mul(dir, DROP_FORCE) local drop = util.drop(ppos, itemid, drop_itemcount, data, 1.5) if not drop then return From 3b3bf8e878d5a219f802f59dfdb0dfadb989b45d Mon Sep 17 00:00:00 2001 From: Neveix <87336789+Neveix@users.noreply.github.com> Date: Fri, 14 Aug 2026 23:25:42 +0500 Subject: [PATCH 02/20] Inventory enhancements #897: 2, 5, 9, 11, 12 (#931) * implement a bit * change shift to ctrl * add enhancement #2 * add ctrl-interaction with content access * fix libinventory.move bug (none checking) * fix p.5 * move shareinv logic into inventory_utils * add inventory utils * small refactor * fix iframe.src = "" --------- Co-authored-by: MihailRis --- res/layouts/inventory.xml | 4 +- res/layouts/inventory.xml.lua | 13 +---- res/modules/inventory_utils.lua | 21 +++++++ src/frontend/hud.cpp | 14 ++++- src/graphics/ui/elements/InventoryView.cpp | 55 ++++++++++++------- src/graphics/ui/elements/InventoryView.hpp | 2 + src/items/ItemStack.cpp | 8 +++ src/items/ItemStack.hpp | 1 + src/logic/scripting/lua/libs/libinventory.cpp | 3 +- 9 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 res/modules/inventory_utils.lua diff --git a/res/layouts/inventory.xml b/res/layouts/inventory.xml index 4291ab4d3..7a33b054f 100644 --- a/res/layouts/inventory.xml +++ b/res/layouts/inventory.xml @@ -1,4 +1,4 @@ - - + + diff --git a/res/layouts/inventory.xml.lua b/res/layouts/inventory.xml.lua index 9f836223d..5c79db6ff 100644 --- a/res/layouts/inventory.xml.lua +++ b/res/layouts/inventory.xml.lua @@ -1,12 +1 @@ -function inventory_share_func(invid, slotid) - local blockinv = hud.get_block_inventory() - if blockinv ~= 0 then - inventory.move(invid, slotid, blockinv) - elseif rules.get("allow-content-access") then - inventory.set(invid, slotid, 0, 0) - elseif slotid < 10 then - inventory.move_range(invid, slotid, invid, 10) - else - inventory.move_range(invid, slotid, invid, 0, 9) - end -end +share_func = require("core:inventory_utils").share_default_func diff --git a/res/modules/inventory_utils.lua b/res/modules/inventory_utils.lua new file mode 100644 index 000000000..17089cdab --- /dev/null +++ b/res/modules/inventory_utils.lua @@ -0,0 +1,21 @@ +local M = {} + +function M.share_default_func(invid, slotid) + local blockinv = hud.get_block_inventory() + local playerinv = player.get_inventory(hud.get_player()) + if blockinv ~= 0 then + if invid == blockinv then + inventory.move(blockinv, slotid, playerinv) + else + inventory.move(invid, slotid, blockinv) + end + elseif rules.get("allow-content-access") then + inventory.set(invid, slotid, 0, 0) + elseif slotid < 10 then + inventory.move_range(invid, slotid, invid, 10) + else + inventory.move_range(invid, slotid, invid, 0, 9) + end +end + +return M diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 08a4b8455..6751b885c 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -106,6 +106,7 @@ std::shared_ptr HudElement::getNode() const { std::shared_ptr Hud::createContentAccess() { auto& content = frontend.getLevel().content; auto& indices = *content.getIndices(); + auto& input = this->input; auto inventory = player.getInventory(); size_t itemsCount = indices.items.count(); @@ -115,12 +116,19 @@ std::shared_ptr Hud::createContentAccess() { } SlotLayout slotLayout(-1, glm::vec2(), false, true, nullptr, - [inventory, &indices](uint, ItemStack& item) { + [inventory, &indices, &input](uint, ItemStack& item) { auto copy = ItemStack(item); + if (input.pressed(Keycode::LEFT_CONTROL)) { + copy.maximizeCount(indices); + } inventory->move(copy, indices); }, - [this, inventory](uint, ItemStack& item) { - inventory->getSlot(player.getChosenSlot()).set(item); + [this, inventory, &indices, &input](uint, ItemStack& item) { + auto copy = ItemStack(item); + if (input.pressed(Keycode::LEFT_CONTROL)) { + copy.maximizeCount(indices); + } + inventory->getSlot(player.getChosenSlot()).set(copy); }); InventoryBuilder builder(gui); diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index 395c8d34e..614d4c913 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -366,28 +366,12 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) { ); return; } - + auto indices = *content->getIndices(); if (!layout.itemSource && stack.accepts(grabbed) && layout.placing) { action = InteractionAction::PUT; - stack.move(grabbed, *content->getIndices()); + stack.move(grabbed, indices); } else { - if (layout.itemSource) { - if (grabbed.isEmpty()) { - action = InteractionAction::TAKE; - grabbed.set(stack); - } else { - action = InteractionAction::PUT; - grabbed.clear(); - } - } else if (grabbed.isEmpty()) { - if (layout.taking) { - action = InteractionAction::TAKE; - std::swap(grabbed, stack); - } - } else if (layout.taking && layout.placing) { - action = InteractionAction::PUT; - std::swap(grabbed, stack); - } + actIfCannotPut(stack, grabbed, action); } if (action != InteractionAction::UNDEFINED) { @@ -400,6 +384,39 @@ void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) { } } +void SlotView::actIfCannotPut(ItemStack& stack, ItemStack& grabbed, InteractionAction& action) { + const auto& input = gui.getInput(); + auto indices = *content->getIndices(); + if (layout.itemSource) { + if (grabbed.isEmpty()) { + action = InteractionAction::TAKE; + grabbed.set(stack); + if (input.pressed(Keycode::LEFT_CONTROL)) { + grabbed.maximizeCount(*content->getIndices()); + } + } else { + if (grabbed.accepts(stack)) { + auto& def = indices.items.require(stack.getItemId()); + if (grabbed.getCount() < def.stackSize) { + action = InteractionAction::TAKE; + grabbed.setCount(grabbed.getCount() + 1); + } + } else { + action = InteractionAction::PUT; + grabbed.clear(); + } + } + } else if (grabbed.isEmpty()) { + if (layout.taking) { + action = InteractionAction::TAKE; + std::swap(grabbed, stack); + } + } else if (layout.taking && layout.placing) { + action = InteractionAction::PUT; + std::swap(grabbed, stack); + } +} + void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) { if (layout.rightClick) { layout.rightClick(inventoryId, stack); diff --git a/src/graphics/ui/elements/InventoryView.hpp b/src/graphics/ui/elements/InventoryView.hpp index 243d8b6b5..fbfe3eee9 100644 --- a/src/graphics/ui/elements/InventoryView.hpp +++ b/src/graphics/ui/elements/InventoryView.hpp @@ -123,6 +123,8 @@ namespace gui { SHARE = 2, UNDEFINED, }; + private: + void actIfCannotPut(ItemStack& stack, ItemStack& grabbed, InteractionAction& action); }; class InventoryView final : public gui::Container { diff --git a/src/items/ItemStack.cpp b/src/items/ItemStack.cpp index f99d8700a..d0f39d5fe 100644 --- a/src/items/ItemStack.cpp +++ b/src/items/ItemStack.cpp @@ -48,6 +48,14 @@ void ItemStack::setCount(itemcount_t count) { } } +void ItemStack::maximizeCount(const ContentIndices& indices) { + auto& def = indices.items.require(getItemId()); + this->count = def.stackSize; + if (count == 0) { + clear(); + } +} + void ItemStack::setField(std::string_view name, dv::value value) { if (fields == nullptr) { if (value == nullptr) { diff --git a/src/items/ItemStack.hpp b/src/items/ItemStack.hpp index 4896bc39e..1ec3fe41d 100644 --- a/src/items/ItemStack.hpp +++ b/src/items/ItemStack.hpp @@ -18,6 +18,7 @@ public: void set(const ItemStack& item); void set(ItemStack&& item); void setCount(itemcount_t count); + void maximizeCount(const ContentIndices& indices); /// @brief Set a field in the item stack data. void setField(std::string_view name, dv::value value); diff --git a/src/logic/scripting/lua/libs/libinventory.cpp b/src/logic/scripting/lua/libs/libinventory.cpp index 2aea52394..9d11d66c6 100644 --- a/src/logic/scripting/lua/libs/libinventory.cpp +++ b/src/logic/scripting/lua/libs/libinventory.cpp @@ -2,6 +2,7 @@ #include "items/Inventories.hpp" #include "items/ItemStack.hpp" #include "logic/BlocksController.hpp" +#include "logic/scripting/lua/lua_util.hpp" #include "world/Level.hpp" #include "api_lua.hpp" @@ -180,7 +181,7 @@ static int l_move(lua::State* L) { validate_slotid(slotAid, invA); auto invBid = lua::tointeger(L, 3); - auto slotBid = lua::isnil(L, 4) ? -1 : lua::tointeger(L, 4); + auto slotBid = lua::isnoneornil(L, 4) ? -1 : lua::tointeger(L, 4); auto& invB = get_inventory(invBid, 3); auto& slot = invA.getSlot(slotAid); if (slotBid == -1) { From efb4532536dd85c1edde19a6fc40e2ff19f807d6 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 00:55:04 +0500 Subject: [PATCH 03/20] add mul* functions to quats & fix to_string --- src/logic/scripting/lua/libs/libquat.cpp | 40 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/logic/scripting/lua/libs/libquat.cpp b/src/logic/scripting/lua/libs/libquat.cpp index 53757cb36..5002e9bb3 100644 --- a/src/logic/scripting/lua/libs/libquat.cpp +++ b/src/logic/scripting/lua/libs/libquat.cpp @@ -1,3 +1,5 @@ +#include +#include #include "api_lua.hpp" #define GLM_ENABLE_EXPERIMENTAL @@ -31,14 +33,14 @@ static int l_tostring(lua::State* L) { lua::check_argc(L, 1); auto quat = lua::toquat(L, 1); + float components[4] = {quat.w, quat.x, quat.y, quat.z}; std::stringstream ss; - ss << "quat" - << "{"; + ss << "quat" << "{"; for (int i = 0; i < 4; i++) { if (i > 0) { ss << ", "; } - ss << quat[i]; + ss << components[i]; } ss << "}"; return lua::pushstring(L, ss.str()); @@ -52,10 +54,42 @@ static int l_from_euler(lua::State *L) { return lua::pushquat(L, glm::quat(euler)); } +static int l_mul(lua::State* L) { + uint argc = lua::check_argc(L, 2, 3); + glm::quat a = lua::toquat(L, 1); + glm::quat b = lua::toquat(L, 2); + + glm::quat result = a * b; + + if (argc == 3) { + lua::setquat(L, 3, result); + return 0; + } + + return lua::pushquat(L, result); +} + +static int l_mul_vec3(lua::State* L) { + uint argc = lua::check_argc(L, 2, 3); + glm::quat q = lua::toquat(L, 1); + glm::vec3 v = lua::tovec3(L, 2); + + glm::vec3 result = q * v; + + if (argc == 3) { + lua::setvec(L, 3, result); + return 0; + } + + return lua::pushvec3(L, result); +} + const luaL_Reg quatlib[] = { {"from_mat4", lua::wrap}, {"from_euler", lua::wrap}, {"slerp", lua::wrap}, {"tostring", lua::wrap}, + {"mul", lua::wrap}, + {"mul_vec3", lua::wrap}, {nullptr, nullptr} }; From ae5c1a4533ae10b026761d6609617b25719c7003 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 01:08:32 +0500 Subject: [PATCH 04/20] move GLM_EXPERIMENTAL to the top --- src/logic/scripting/lua/libs/libquat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libquat.cpp b/src/logic/scripting/lua/libs/libquat.cpp index 5002e9bb3..d062f40a4 100644 --- a/src/logic/scripting/lua/libs/libquat.cpp +++ b/src/logic/scripting/lua/libs/libquat.cpp @@ -1,8 +1,8 @@ +#define GLM_ENABLE_EXPERIMENTAL #include #include #include "api_lua.hpp" -#define GLM_ENABLE_EXPERIMENTAL #include #include #include From 516b4064768db430eb3e91665367ed9f096fce45 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 01:18:39 +0500 Subject: [PATCH 05/20] fix stringstream usage --- src/logic/scripting/lua/libs/libquat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/libs/libquat.cpp b/src/logic/scripting/lua/libs/libquat.cpp index d062f40a4..a3fe62149 100644 --- a/src/logic/scripting/lua/libs/libquat.cpp +++ b/src/logic/scripting/lua/libs/libquat.cpp @@ -35,7 +35,7 @@ static int l_tostring(lua::State* L) { float components[4] = {quat.w, quat.x, quat.y, quat.z}; std::stringstream ss; - ss << "quat" << "{"; + ss << "quat {"; for (int i = 0; i < 4; i++) { if (i > 0) { ss << ", "; From dbe1dfd380192702d9398c6f926a1d6552ee684e Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 13:11:56 +0500 Subject: [PATCH 06/20] fix gimbal lock --- res/content/base/modules/util.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/res/content/base/modules/util.lua b/res/content/base/modules/util.lua index db5e4f2f3..4991331d0 100644 --- a/res/content/base/modules/util.lua +++ b/res/content/base/modules/util.lua @@ -13,14 +13,18 @@ local function calculate_item_drop_dir(pid) if not hud.is_inventory_open() and not hud.is_player_inventory_open() then mpos = {0, 0} end - pitch = math.clamp(pitch - mpos[2]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2, -90, 90) - yaw = math.rad(yaw + 90 -mpos[1]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2) - pitch = math.rad(pitch) - return vec3.normalize({ - math.cos(yaw) * math.cos(pitch), - math.sin(pitch), - -math.sin(yaw) * math.cos(pitch) - }) + + local q_yaw = quat.from_euler({0, yaw, 0}) + local q_pitch = quat.from_euler({pitch, 0, 0}) + local q_rotation = quat.mul(q_yaw, q_pitch) + + local q_shift = quat.from_euler({ + -mpos[2]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2, + -mpos[1]*DROP_MAX_ITEM_DIR_SHIFT_DEGREES*2, + 0, + }) + quat.mul(q_rotation, q_shift, q_rotation) + return quat.mul_vec3(q_rotation, {0, 0, -1}) end ---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack From 22b70b701e192472ab859345fbc611cf69b7ce63 Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 14:01:46 +0500 Subject: [PATCH 07/20] add quaternion mul* docs --- doc/en/scripting/builtins/libquat.md | 37 +++++++++++++++++++++++++++- doc/ru/scripting/builtins/libquat.md | 23 +++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/doc/en/scripting/builtins/libquat.md b/doc/en/scripting/builtins/libquat.md index f7cc7a0f6..4ad15bad7 100644 --- a/doc/en/scripting/builtins/libquat.md +++ b/doc/en/scripting/builtins/libquat.md @@ -2,7 +2,10 @@ Quaternions manipulation library. -## Quaternion from matrix - *mat4.from_quat(...)* +Quaternions can be created as a table of 4 numbers: +`{w, x, y, z}` + +## Quaternion from matrix - *quat.from_mat4(...)* ```lua -- creates a quaternion based on the rotation matrix @@ -12,6 +15,38 @@ quat.from_mat4(m: matrix) quat.from_mat4(m: matrix, dst: quat) ``` +## Quaternion of Euler angles - *quat.from_euler(...)* + +```lua +-- creates quaternion from euler angles passed as XYZ (pitch, yaw, roll) +-- angles in degrees +quat.from_euler(euler: vec3) -> quat + +-- writes quaternion from euler angles passed as XYZ (pitch, yaw, roll) to dst +-- angles in degrees +quat.from_euler(euler: vec3, dst: quat) +``` + +## Quaternion composition - quat.mul(...) + +```lua +-- multiplies quaternions +quat.mul(a: quat, b: quat) -> quat + +-- writes a quaternions multiplication result to dst +quat.mul(a: quat, b: quat, dst: quat) +``` + +## 3D vector rotation - quat.mul_vec3(...) + +```lua +-- rotates vector by quaternion +quat.mul_vec3(a: quat, b: vec3) -> vec3 + +-- writes rotated vector by quaternion to dst +quat.mul_vec3(a: quat, b: vec3, dst: vec3) +``` + ## Spherical linear interpolation - *quat.slerp(...)* The interpolation always take the short path and the rotation is performed at constant speed. diff --git a/doc/ru/scripting/builtins/libquat.md b/doc/ru/scripting/builtins/libquat.md index e991de252..745ac6822 100644 --- a/doc/ru/scripting/builtins/libquat.md +++ b/doc/ru/scripting/builtins/libquat.md @@ -2,6 +2,9 @@ Библиотека для работы с кватернионами. +Кватернионы задаюся таблицей, состоящей из 4 компонентов: +`{w, x, y, z}` + ## Кватернион из матрицы - *quat.from_mat4(...)* ```lua @@ -24,6 +27,26 @@ quat.from_euler(euler: vec3) -> quat quat.from_euler(euler: vec3, dst: quat) ``` +## Композиция кватернионов - quat.mul(...) + +```lua +-- Умножает два кватерниона (композиция поворотов) +quat.mul(a: quat, b: quat) -> quat + +-- Записывает кватернион как произведение двух кватернионов (композиция поворотов) +quat.mul(a: quat, b: quat, dst: quat) +``` + +## Поворот 3д вектора на кватернион - quat.mul_vec3(...) + +```lua +-- Поворачивает вектор на заданный кватернион +quat.mul_vec3(a: quat, b: vec3) -> vec3 + +-- Записывает результат поворота вектора на заданный кватернион +quat.mul_vec3(a: quat, b: vec3, dst: vec3) +``` + ## Сферическая линейная интерполяция - *quat.slerp(...)* Интерполяция всегда выполняется по короткому пути, а вращение выполняется с постоянной скоростью. From 305dab7ead4b2a5b52bb91d83e8b689a7edd286f Mon Sep 17 00:00:00 2001 From: neveix Date: Sat, 15 Aug 2026 14:58:09 +0500 Subject: [PATCH 08/20] remove duplicated --- doc/en/scripting/builtins/libquat.md | 29 ++++++---------------------- doc/ru/scripting/builtins/libquat.md | 27 +++++--------------------- 2 files changed, 11 insertions(+), 45 deletions(-) diff --git a/doc/en/scripting/builtins/libquat.md b/doc/en/scripting/builtins/libquat.md index 4ad15bad7..5d72413e2 100644 --- a/doc/en/scripting/builtins/libquat.md +++ b/doc/en/scripting/builtins/libquat.md @@ -9,10 +9,7 @@ Quaternions can be created as a table of 4 numbers: ```lua -- creates a quaternion based on the rotation matrix -quat.from_mat4(m: matrix) - --- writes a quaternion from the rotation matrix to dst -quat.from_mat4(m: matrix, dst: quat) +quat.from_mat4(m: matrix, [optional] dst: quat) -> quat ``` ## Quaternion of Euler angles - *quat.from_euler(...)* @@ -20,31 +17,21 @@ quat.from_mat4(m: matrix, dst: quat) ```lua -- creates quaternion from euler angles passed as XYZ (pitch, yaw, roll) -- angles in degrees -quat.from_euler(euler: vec3) -> quat - --- writes quaternion from euler angles passed as XYZ (pitch, yaw, roll) to dst --- angles in degrees -quat.from_euler(euler: vec3, dst: quat) +quat.from_euler(euler: vec3, [optional] dst: quat) -> quat ``` ## Quaternion composition - quat.mul(...) ```lua -- multiplies quaternions -quat.mul(a: quat, b: quat) -> quat - --- writes a quaternions multiplication result to dst -quat.mul(a: quat, b: quat, dst: quat) +quat.mul(a: quat, b: quat, [optional] dst: quat) -> quat ``` ## 3D vector rotation - quat.mul_vec3(...) ```lua -- rotates vector by quaternion -quat.mul_vec3(a: quat, b: vec3) -> vec3 - --- writes rotated vector by quaternion to dst -quat.mul_vec3(a: quat, b: vec3, dst: vec3) +quat.mul_vec3(a: quat, b: vec3, [optional] dst: vec3) -> vec3 ``` ## Spherical linear interpolation - *quat.slerp(...)* @@ -54,16 +41,12 @@ The interpolation always take the short path and the rotation is performed at co ```lua -- creates a quaternion as an interpolation between a and b, -- where t is interpolation factor -quat.slerp(a: quat, b: quat, t: number) - --- writes a quaternion as an interpolation between a and b to dst, --- where t is interpolation factor -quat.slerp(a: quat, b: quat, t: number, dst: quat) +quat.slerp(a: quat, b: quat, t: number, [optional] dst: quat) -> quat ``` ## Casting to string - *quat.tostring(...)* ```lua -- returns a string representing the contents of the quaternion -quat.tostring(q: quat) +quat.tostring(q: quat) -> string ``` diff --git a/doc/ru/scripting/builtins/libquat.md b/doc/ru/scripting/builtins/libquat.md index 745ac6822..a32a24e6d 100644 --- a/doc/ru/scripting/builtins/libquat.md +++ b/doc/ru/scripting/builtins/libquat.md @@ -9,10 +9,7 @@ ```lua -- создаёт кватернион на основе матрицы вращения -quat.from_mat4(m: matrix) -> quat - --- записывает кватернион по матрице вращения в dst -quat.from_mat4(m: matrix, dst: quat) +quat.from_mat4(m: matrix, [опционально] dst: quat) -> quat ``` ## Кватернион из углов Эйлера - *quat.from_euler(...)* @@ -20,31 +17,21 @@ quat.from_mat4(m: matrix, dst: quat) ```lua -- создаёт кватернион на основе вектора, содержащего углы Эйлера в порядке XYZ (pitch, yaw, roll) -- (значения углов строго в градусах) -quat.from_euler(euler: vec3) -> quat - --- записывает кватернион в dst на основе вектора, содержащего углы Эйлера в порядке XYZ (pitch, yaw, roll) --- (значения углов строго в градусах) -quat.from_euler(euler: vec3, dst: quat) +quat.from_euler(euler: vec3, [опционально] dst: quat) -> quat ``` ## Композиция кватернионов - quat.mul(...) ```lua -- Умножает два кватерниона (композиция поворотов) -quat.mul(a: quat, b: quat) -> quat - --- Записывает кватернион как произведение двух кватернионов (композиция поворотов) -quat.mul(a: quat, b: quat, dst: quat) +quat.mul(a: quat, b: quat, [опционально] dst: quat) -> quat ``` ## Поворот 3д вектора на кватернион - quat.mul_vec3(...) ```lua -- Поворачивает вектор на заданный кватернион -quat.mul_vec3(a: quat, b: vec3) -> vec3 - --- Записывает результат поворота вектора на заданный кватернион -quat.mul_vec3(a: quat, b: vec3, dst: vec3) +quat.mul_vec3(a: quat, b: vec3, [опционально] dst: vec3) -> vec3 ``` ## Сферическая линейная интерполяция - *quat.slerp(...)* @@ -54,11 +41,7 @@ quat.mul_vec3(a: quat, b: vec3, dst: vec3) ```lua -- создаёт кватернион как интерполяцию между a и b, -- где t - фактор интерполяции -quat.slerp(a: quat, b: quat, t: number) -> quat - --- записывает кватернион как интерполяцию между a и b в dst, --- где t - фактор интерполяции -quat.slerp(a: quat, b: quat, t: number, dst: quat) +quat.slerp(a: quat, b: quat, t: number, [опционально] dst: quat) -> quat ``` ## Перевод в строку - *quat.tostring(...)* From fa0f87349b5c61ee0ca43d7d6b5b64237c39a6a4 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 17:19:54 +0300 Subject: [PATCH 09/20] fix blank texture overwritten by screen frame output --- src/graphics/ui/elements/Frame.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/graphics/ui/elements/Frame.cpp b/src/graphics/ui/elements/Frame.cpp index f99673f22..0387f5c1e 100644 --- a/src/graphics/ui/elements/Frame.cpp +++ b/src/graphics/ui/elements/Frame.cpp @@ -48,10 +48,14 @@ void gui::Frame::draw(const DrawContext& pctx, const Assets& assets) { void gui::Frame::updateOutput(Assets& assets) { if (fbo && (fbo->getWidth() != size.x || fbo->getHeight() != size.y)) { fbo->resize(size.x, size.y); - assets.store(fbo->getSharedTexture(), outputTexture); + if (!outputTexture.empty()) { + assets.store(fbo->getSharedTexture(), outputTexture); + } } else if (fbo == nullptr) { fbo = std::make_unique(size.x, size.y, true); - assets.store(fbo->getSharedTexture(), outputTexture); + if (!outputTexture.empty()) { + assets.store(fbo->getSharedTexture(), outputTexture); + } } } From 98326627f55791d8d2308be3547901c53141d6aa Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 17:27:03 +0300 Subject: [PATCH 10/20] revert "fix vcm texture sides" This reverts commit 38bebac37ee2a290315c3148576e98c825efa46d. --- src/coders/vcm.cpp | 12 ++++++------ src/graphics/commons/Model.cpp | 24 ++++++++++++------------ src/graphics/ui/elements/ModelViewer.cpp | 10 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/coders/vcm.cpp b/src/coders/vcm.cpp index 3083e1d36..308fb8462 100644 --- a/src/coders/vcm.cpp +++ b/src/coders/vcm.cpp @@ -55,12 +55,12 @@ model::Model VcmModel::squashed() const { } static const std::unordered_map side_indices { - {"east", 0}, - {"west", 1}, - {"bottom", 2}, - {"top", 3}, - {"south", 4}, - {"north", 5}, + {"north", 0}, + {"south", 1}, + {"top", 2}, + {"bottom", 3}, + {"west", 4}, + {"east", 5}, }; static bool to_boolean(const xml::Attribute& attr) { diff --git a/src/graphics/commons/Model.cpp b/src/graphics/commons/Model.cpp index 8c2194775..2de10ad30 100644 --- a/src/graphics/commons/Model.cpp +++ b/src/graphics/commons/Model.cpp @@ -136,18 +136,18 @@ void Mesh::addBox( const bool enabledSides[6], const glm::mat4& transform ) { - if (enabledSides[0]) // east - addPlane(pos-X*size, Z*size, Y*size, -X, uvs[0], transform); - if (enabledSides[1]) // west - addPlane(pos+X*size, -Z*size, Y*size, X, uvs[1] * glm::vec2(-1, 1), transform); - if (enabledSides[2]) // bottom - addPlane(pos-Y*size, X*size, Z*size, -Y, uvs[2], transform); - if (enabledSides[3]) // top - addPlane(pos+Y*size, X*size, -Z*size, Y, uvs[3] * glm::vec2(-1, 1), transform); - if (enabledSides[4]) // south - addPlane(pos-Z*size, -X*size, Y*size, -Z, uvs[4], transform); - if (enabledSides[5]) // north - addPlane(pos+Z*size, X*size, Y*size, Z, uvs[5] * glm::vec2(-1, 1), transform); + if (enabledSides[0]) // north + addPlane(pos+Z*size, X*size, Y*size, Z, uvs[0], transform); + if (enabledSides[1]) // south + addPlane(pos-Z*size, -X*size, Y*size, -Z, uvs[1], transform); + if (enabledSides[2]) // top + addPlane(pos+Y*size, X*size, -Z*size, Y, uvs[2] * glm::vec2(-1), transform); + if (enabledSides[3]) // bottom + addPlane(pos-Y*size, X*size, Z*size, -Y, uvs[3] * glm::vec2(-1, 1), transform); + if (enabledSides[4]) // west + addPlane(pos+X*size, -Z*size, Y*size, X, uvs[4], transform); + if (enabledSides[5]) // east + addPlane(pos-X*size, Z*size, Y*size, -X, uvs[5] * glm::vec2(-1, 1), transform); } void Mesh::scale(const glm::vec3& size) { diff --git a/src/graphics/ui/elements/ModelViewer.cpp b/src/graphics/ui/elements/ModelViewer.cpp index 748eabae5..bfeed086d 100644 --- a/src/graphics/ui/elements/ModelViewer.cpp +++ b/src/graphics/ui/elements/ModelViewer.cpp @@ -83,12 +83,12 @@ static util::TextureRegion determine_texture_region( const Assets& assets, const std::string& texture ) { static std::array faces { - "blocks:dbg_east", - "blocks:dbg_west", - "blocks:dbg_bottom", - "blocks:dbg_top", - "blocks:dbg_south", "blocks:dbg_north", + "blocks:dbg_south", + "blocks:dbg_top", + "blocks:dbg_bottom", + "blocks:dbg_west", + "blocks:dbg_east", }; if (texture.length() < 2 || texture.at(0) != '$') { From 22a9ab4b7a322e4ee4000454cca02c73c96496f0 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 19:50:38 +0300 Subject: [PATCH 11/20] fix region again --- src/coders/vcm.cpp | 18 +++++++++++------- src/graphics/commons/Model.cpp | 24 ++++++++++++------------ src/graphics/ui/elements/ModelViewer.cpp | 10 +++++----- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/coders/vcm.cpp b/src/coders/vcm.cpp index 308fb8462..fb405cfac 100644 --- a/src/coders/vcm.cpp +++ b/src/coders/vcm.cpp @@ -55,12 +55,12 @@ model::Model VcmModel::squashed() const { } static const std::unordered_map side_indices { - {"north", 0}, - {"south", 1}, - {"top", 2}, - {"bottom", 3}, - {"west", 4}, - {"east", 5}, + {"east", 0}, + {"west", 1}, + {"bottom", 2}, + {"top", 3}, + {"south", 4}, + {"north", 5}, }; static bool to_boolean(const xml::Attribute& attr) { @@ -306,7 +306,11 @@ static void perform_box(const xmlelement& root, ModelBuilder& builder) { texfaces[idx] = elem->attr("texture").getText(); } if (elem->has("region")) { - regions[idx].set(elem->attr("region").asVec4()); + auto region = elem->attr("region").asVec4(); + if (idx % 2 == 1) { + std::swap(region[0], region[2]); + } + regions[idx].set(region); } if (elem->has("region-scale")) { regions[idx].scale(elem->attr("region-scale").asVec2()); diff --git a/src/graphics/commons/Model.cpp b/src/graphics/commons/Model.cpp index 2de10ad30..8c2194775 100644 --- a/src/graphics/commons/Model.cpp +++ b/src/graphics/commons/Model.cpp @@ -136,18 +136,18 @@ void Mesh::addBox( const bool enabledSides[6], const glm::mat4& transform ) { - if (enabledSides[0]) // north - addPlane(pos+Z*size, X*size, Y*size, Z, uvs[0], transform); - if (enabledSides[1]) // south - addPlane(pos-Z*size, -X*size, Y*size, -Z, uvs[1], transform); - if (enabledSides[2]) // top - addPlane(pos+Y*size, X*size, -Z*size, Y, uvs[2] * glm::vec2(-1), transform); - if (enabledSides[3]) // bottom - addPlane(pos-Y*size, X*size, Z*size, -Y, uvs[3] * glm::vec2(-1, 1), transform); - if (enabledSides[4]) // west - addPlane(pos+X*size, -Z*size, Y*size, X, uvs[4], transform); - if (enabledSides[5]) // east - addPlane(pos-X*size, Z*size, Y*size, -X, uvs[5] * glm::vec2(-1, 1), transform); + if (enabledSides[0]) // east + addPlane(pos-X*size, Z*size, Y*size, -X, uvs[0], transform); + if (enabledSides[1]) // west + addPlane(pos+X*size, -Z*size, Y*size, X, uvs[1] * glm::vec2(-1, 1), transform); + if (enabledSides[2]) // bottom + addPlane(pos-Y*size, X*size, Z*size, -Y, uvs[2], transform); + if (enabledSides[3]) // top + addPlane(pos+Y*size, X*size, -Z*size, Y, uvs[3] * glm::vec2(-1, 1), transform); + if (enabledSides[4]) // south + addPlane(pos-Z*size, -X*size, Y*size, -Z, uvs[4], transform); + if (enabledSides[5]) // north + addPlane(pos+Z*size, X*size, Y*size, Z, uvs[5] * glm::vec2(-1, 1), transform); } void Mesh::scale(const glm::vec3& size) { diff --git a/src/graphics/ui/elements/ModelViewer.cpp b/src/graphics/ui/elements/ModelViewer.cpp index bfeed086d..748eabae5 100644 --- a/src/graphics/ui/elements/ModelViewer.cpp +++ b/src/graphics/ui/elements/ModelViewer.cpp @@ -83,12 +83,12 @@ static util::TextureRegion determine_texture_region( const Assets& assets, const std::string& texture ) { static std::array faces { - "blocks:dbg_north", - "blocks:dbg_south", - "blocks:dbg_top", - "blocks:dbg_bottom", - "blocks:dbg_west", "blocks:dbg_east", + "blocks:dbg_west", + "blocks:dbg_bottom", + "blocks:dbg_top", + "blocks:dbg_south", + "blocks:dbg_north", }; if (texture.length() < 2 || texture.at(0) != '$') { From c481997b8243a2ecf617fe2f1c7135f1bfe00f55 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 20:41:41 +0300 Subject: [PATCH 12/20] fix editor toolbar --- res/layouts/code_editor.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/layouts/code_editor.xml b/res/layouts/code_editor.xml index b3cd2ed9c..3d3e584d5 100644 --- a/res/layouts/code_editor.xml +++ b/res/layouts/code_editor.xml @@ -17,7 +17,7 @@ color="#FFFFFF80" size="16" pos="4,6" hover-color="#1080FF"> + size="76,24" padding="8,6,8,2" interval="8" color="0"> Date: Mon, 17 Aug 2026 22:55:17 +0500 Subject: [PATCH 13/20] move hud.get_player() out from util.lua & add error returning --- res/content/base/modules/util.lua | 41 ++++++++++++++++++------------- res/content/base/scripts/hud.lua | 7 +++--- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/res/content/base/modules/util.lua b/res/content/base/modules/util.lua index 4d25ccb91..57bc6ccb6 100644 --- a/res/content/base/modules/util.lua +++ b/res/content/base/modules/util.lua @@ -1,20 +1,21 @@ local util = {} local DROP_FORCE = 8 -local DROP_INIT_VEL = {0, 3, 0} +local DROP_INIT_VEL = { 0, 3, 0 } +--- Create a drop from slot, set it velocity, and return it ---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack -function util.drop_from_slot(invid, slot, mode) +---@return table? entity, string? error +function util.drop_from_slot(pid, invid, slot, mode) if invid == 0 then - return + return nil, "invid cannot be 0" end - local pid = hud.get_player() if mode == 2 and not player.is_infinite_items(pid) then - return + return nil, "no permission to dupe items" end local itemid, itemcount = inventory.get(invid, slot) if itemid == 0 then - return + return nil, "no item in slot" end local drop_itemcount = 1 @@ -31,24 +32,28 @@ function util.drop_from_slot(invid, slot, mode) local pvel = { player.get_vel(pid) } local ppos = vec3.add({ player.get_pos(pid) }, { 0, 0.7, 0 }) local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE) - local drop = util.drop(ppos, itemid, drop_itemcount, data, 1.5) + local drop, err = util.drop(ppos, itemid, drop_itemcount, data, 1.5) if not drop then - return + return nil, err end local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)) drop.rigidbody:set_vel(velocity) + return drop end +---@return table? entity, string? error function util.drop(ppos, itemid, count, data, pickup_delay) if itemid == 0 or not itemid then - return nil + return nil, "item is empty" end - return entities.spawn("base:drop", ppos, {base__drop={ - id=itemid, - count=count, - data=data, - pickup_delay=pickup_delay - }}) + return entities.spawn("base:drop", ppos, { + base__drop = { + id = itemid, + count = count, + data = data, + pickup_delay = pickup_delay + } + }) end function util.calc_loot(loot_table) @@ -66,7 +71,9 @@ function util.calc_loot(loot_table) if count == 0 then goto continue end - table.insert(results, {item=item.index(loot.item), count=count}) + table.insert(results, { + item = item.index(loot.item), count = count + }) end ::continue:: end @@ -78,7 +85,7 @@ function util.block_loot(blockid) if lootscheme then return util.calc_loot(lootscheme) end - return {{item=block.get_picking_item(blockid), count=1}} + return { { item = block.get_picking_item(blockid), count = 1 } } end return util diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index d0e3d1532..313e7b5b4 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -2,8 +2,9 @@ local base_util = require "util" function on_hud_open() events.on("core:drop_outside_inventory", function(mode) + local pid = hud.get_player() local invid = hud.get_exchange_inventory() - base_util.drop_from_slot(invid, 0, mode) + base_util.drop_from_slot(pid, invid, 0, mode) end) input.add_callback("player.drop", function() if hud.is_paused() or hud.is_inventory_open() then @@ -13,9 +14,9 @@ function on_hud_open() local invid, slot = player.get_inventory(pid) local mode = 1 if input.is_pressed("key:left-ctrl") or input.is_pressed("key:right-ctrl") then - mode = 0 + mode = 0 end - base_util.drop_from_slot(invid, slot, mode) + base_util.drop_from_slot(pid, invid, slot, mode) end) rules.create("do-loot-non-player", true) end From c0b73998ed7325b0d537592ce0fceab23af436b8 Mon Sep 17 00:00:00 2001 From: neveix Date: Mon, 17 Aug 2026 23:47:51 +0500 Subject: [PATCH 14/20] move hud away from utils 2 & add new argument --- res/content/base/modules/util.lua | 33 ++++++++++++++----------------- res/content/base/scripts/hud.lua | 6 +++++- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/res/content/base/modules/util.lua b/res/content/base/modules/util.lua index 6d5a77705..843f818c7 100644 --- a/res/content/base/modules/util.lua +++ b/res/content/base/modules/util.lua @@ -1,26 +1,22 @@ local util = {} -local DROP_FORCE = 8 -local DROP_INIT_VEL = { 0, 3, 0 } -local DROP_MAX_ITEM_DIR_SHIFT_DEGREES = 65 +util.DROP_FORCE = 8 +util.DROP_INIT_VEL = { 0, 3, 0 } +util.DROP_MAX_ITEM_DIR_SHIFT_DEGREES = 65 -local function calculate_item_drop_dir(pid) - local yaw, pitch = player.get_rot(pid) - local vp = gui.get_viewport() - local mpos = table.map(input.get_mouse_pos(), function(i, v) - return v / vp[i] - 0.5 - end) - if not hud.is_inventory_open() and not hud.is_player_inventory_open() then - mpos = { 0, 0 } +---@param dir_shift? vec2 direction shift for drop; x and y must be clamped to [-0.5, 0.5] +local function calculate_item_drop_dir(pid, dir_shift) + if not dir_shift then + dir_shift = { 0, 0 } end - + local yaw, pitch = player.get_rot(pid) local q_yaw = quat.from_euler({ 0, yaw, 0 }) local q_pitch = quat.from_euler({ pitch, 0, 0 }) local q_rotation = quat.mul(q_yaw, q_pitch) local q_shift = quat.from_euler({ - -mpos[2] * DROP_MAX_ITEM_DIR_SHIFT_DEGREES * 2, - -mpos[1] * DROP_MAX_ITEM_DIR_SHIFT_DEGREES * 2, + -dir_shift[2] * util.DROP_MAX_ITEM_DIR_SHIFT_DEGREES * 2, + -dir_shift[1] * util.DROP_MAX_ITEM_DIR_SHIFT_DEGREES * 2, 0, }) quat.mul(q_rotation, q_shift, q_rotation) @@ -29,8 +25,9 @@ end --- Create a drop from slot, set it velocity, and return it ---@param mode integer 0 - whole stack, 1 - single item, 2 - dupe whole stack +---@param dir_shift? vec2 direction shift for drop; x and y must be clamped to [-0.5, 0.5] ---@return table? entity, string? error -function util.drop_from_slot(pid, invid, slot, mode) +function util.drop_from_slot(pid, invid, slot, mode, dir_shift) if invid == 0 then return nil, "invid cannot be 0" end @@ -55,13 +52,13 @@ function util.drop_from_slot(pid, invid, slot, mode) local data = inventory.get_all_data(invid, slot) local pvel = { player.get_vel(pid) } local ppos = vec3.add({ player.get_pos(pid) }, { 0, 0.7, 0 }) - local dir = calculate_item_drop_dir(pid) - local throw_force = vec3.mul(dir, DROP_FORCE) + local dir = calculate_item_drop_dir(pid, dir_shift) + local throw_force = vec3.mul(dir, util.DROP_FORCE) local drop, err = util.drop(ppos, itemid, drop_itemcount, data, 1.5) if not drop then return nil, err end - local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)) + local velocity = vec3.add(throw_force, vec3.add(pvel, util.DROP_INIT_VEL)) drop.rigidbody:set_vel(velocity) return drop end diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index 313e7b5b4..5d3bfeb46 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -4,7 +4,11 @@ function on_hud_open() events.on("core:drop_outside_inventory", function(mode) local pid = hud.get_player() local invid = hud.get_exchange_inventory() - base_util.drop_from_slot(pid, invid, 0, mode) + local vp = gui.get_viewport() + local dir_shift = table.map(input.get_mouse_pos(), function(i, v) + return v / vp[i] - 0.5 + end) + base_util.drop_from_slot(pid, invid, 0, mode, dir_shift) end) input.add_callback("player.drop", function() if hud.is_paused() or hud.is_inventory_open() then From d54bb5bf54d536fe602c15378433cf95de21a159 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 22:20:25 +0300 Subject: [PATCH 15/20] change: flip the planet --- src/coders/vcm.cpp | 12 ++++++------ src/graphics/ui/elements/ModelViewer.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coders/vcm.cpp b/src/coders/vcm.cpp index fb405cfac..8c4965ca4 100644 --- a/src/coders/vcm.cpp +++ b/src/coders/vcm.cpp @@ -55,12 +55,12 @@ model::Model VcmModel::squashed() const { } static const std::unordered_map side_indices { - {"east", 0}, - {"west", 1}, - {"bottom", 2}, - {"top", 3}, - {"south", 4}, - {"north", 5}, + {"west", 0}, // -X + {"east", 1}, // +X + {"bottom", 2}, // -Y + {"top", 3}, // +Y + {"north", 4}, // -Z + {"south", 5}, // +Z }; static bool to_boolean(const xml::Attribute& attr) { diff --git a/src/graphics/ui/elements/ModelViewer.cpp b/src/graphics/ui/elements/ModelViewer.cpp index 748eabae5..435f3340d 100644 --- a/src/graphics/ui/elements/ModelViewer.cpp +++ b/src/graphics/ui/elements/ModelViewer.cpp @@ -83,12 +83,12 @@ static util::TextureRegion determine_texture_region( const Assets& assets, const std::string& texture ) { static std::array faces { - "blocks:dbg_east", "blocks:dbg_west", + "blocks:dbg_east", "blocks:dbg_bottom", "blocks:dbg_top", - "blocks:dbg_south", "blocks:dbg_north", + "blocks:dbg_south", }; if (texture.length() < 2 || texture.at(0) != '$') { From c713015134a4baaeb3922b56654a38ac481a0be2 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 22:23:20 +0300 Subject: [PATCH 16/20] add vcm old models converter button to the editor temporary --- res/layouts/code_editor.xml | 6 +++ res/layouts/code_editor.xml.lua | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/res/layouts/code_editor.xml b/res/layouts/code_editor.xml index 3d3e584d5..fb4833da1 100644 --- a/res/layouts/code_editor.xml +++ b/res/layouts/code_editor.xml @@ -31,6 +31,12 @@ hover-color="#1080FF" onclick="run_current_file()" color="#FFFFFF80" size="16"> + + diff --git a/res/layouts/code_editor.xml.lua b/res/layouts/code_editor.xml.lua index 733fa9036..61e90842f 100644 --- a/res/layouts/code_editor.xml.lua +++ b/res/layouts/code_editor.xml.lua @@ -113,6 +113,78 @@ local function reload_model(filename, name) assets.parse_model(file.ext(filename), document.editor.text, name) end +-- === TODO: remove after 0.32 === +local pattern = + "region %(%s*" + .. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*" + .. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*" + .. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*" + .. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)" + .. "%s*%)" + +local function replace1(x1, y1, x2, y2) + return string.format("region (%s, %s, %s, %s)", x2, y2, x1, y1) +end + +local function replace2(x1, y1, x2, y2) + return string.format("region (%s, %s, %s, %s)", x2, y1, x1, y2) +end + +function convert_vcm(text) + local lines = {} + local zpairs = { + {"%(north%)", "%(south%)", "(TMPS)", "(TMPN)"}, + {"%,north", "%,south", ",TMPS", ",TMPN"}, + {"north%,", "south%,", "TMPS,", "TMPN,"}, + } + local xpairs = { + {"%(west%)", "%(east%)", "(TMPE)", "(TMPW)"}, + {"%,west", "%,east", ",TMPE", ",TMPW"}, + {"west%,", "east%,", "TMPE,", "TMPW,"}, + } + + for i, pair in ipairs(zpairs) do + text = text:gsub(pair[1], pair[3]) + text = text:gsub(pair[2], pair[4]) + end + text = text:gsub("TMPS", "south") + text = text:gsub("TMPN", "north") + + for i, pair in ipairs(xpairs) do + text = text:gsub(pair[1], pair[3]) + text = text:gsub(pair[2], pair[4]) + end + text = text:gsub("TMPW", "west") + text = text:gsub("TMPE", "east") + + for line in text:gmatch("[^\n]*\n?") do + if line == "" then + break + end + + if line:find("(top)", 1, true) then + line = line:gsub(pattern, replace1) + end + + if line:find("(bottom)", 1, true) + or line:find("(east)", 1, true) then + line = line:gsub(pattern, replace2) + end + + table.insert(lines, line) + end + + return table.concat(lines) +end + +function fix_vcm_regions() + if not current_file.filename then + return + end + document.editor.text = convert_vcm(document.editor.text) +end +-- =============================== + function run_current_file() if not current_file.filename then return From 423685139fe83bb2e571fbdfa41327ce61a64dd0 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 23:24:54 +0300 Subject: [PATCH 17/20] fix stairs model --- res/models/stairs.vcm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/res/models/stairs.vcm b/res/models/stairs.vcm index 2027c09e3..b13cd2d80 100644 --- a/res/models/stairs.vcm +++ b/res/models/stairs.vcm @@ -1,4 +1,4 @@ -@box from (0,0,0) to (1,0.5,1) delete (top,south) -@box from (0,0.5,0) to (1,1,0.5) delete (bottom,south) +@box from (0,0,0) to (1,0.5,1) delete (top,north) +@box from (0,0.5,0) to (1,1,0.5) delete (bottom,north) @rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2" @rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1" From fdd8d865d21c8ff1708e0448401f51a05d9ff710 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 23:25:18 +0300 Subject: [PATCH 18/20] update doc/*/block-properties.md --- doc/en/block-properties.md | 8 ++++---- doc/ru/block-properties.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/en/block-properties.md b/doc/en/block-properties.md index 61f44e844..82ba10484 100644 --- a/doc/en/block-properties.md +++ b/doc/en/block-properties.md @@ -192,12 +192,12 @@ An array of 6 numbers describing an offset an size of a block hitbox. The numbers are specified in the range [0.0, 1.0] - i.e. within the block (in the case of an extended block, the hitbox can be larger than one, but must not go beyond the "size" property). Array *\[0.25, 0.0, 0.5, 0.75, 0.4, 0.3\]* describes hitbox width: -- offset 0.25m east +- offset 0.25m west - offset 0.0m up -- offset 0.5m north -- 0.75m width (from east to west) +- offset 0.5m south +- 0.75m width (from west to east) - 0.4m height -- 0.3m length (from south to north) +- 0.3m length (from north to south) For composite hitboxes, the *hitboxes* property is used - an array of hitboxes, for example: diff --git a/doc/ru/block-properties.md b/doc/ru/block-properties.md index 6d613d888..09db5c8ef 100644 --- a/doc/ru/block-properties.md +++ b/doc/ru/block-properties.md @@ -194,12 +194,12 @@ Числа указываются в диапазоне [0.0, 1.0] - т.е в пределах блока (в случае расширенного блока хитбокс может быть больше единицы, но не должен выходить за пределы size). Массив `[0.25, 0.0, 0.5, 0.75, 0.4, 0.3]` описывает хитбокс: -- смещен на 0.25 м на запад +- смещен на 0.25 м на восток - смещен на 0.0 м вверх -- смещен на 0.5 м на север -- шириной (с востока на запад) 0.75 м +- смещен на 0.5 м на юг +- шириной (с запада на восток) 0.75 м - высотой 0.4 м -- длиной (с юга на север) 0.3 м +- длиной (с севера на юг) 0.3 м Для составных хитбоксов используется свойство *hitboxes* - массив хитбоксов, например: From 02dbd01e73f2c69168a1ba4c1929c9d5be263718 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 23:34:38 +0300 Subject: [PATCH 19/20] fix custom models solidity detection --- src/content/ContentBuilder.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/content/ContentBuilder.cpp b/src/content/ContentBuilder.cpp index 97498b497..83836dfe3 100644 --- a/src/content/ContentBuilder.cpp +++ b/src/content/ContentBuilder.cpp @@ -39,16 +39,18 @@ std::unique_ptr ContentBuilder::build() { } else { def.defaults.rt.solid = isSolid(def.defaults) || def.explictlySolid; } - if (def.material.empty()) { - defaults.at("block-material").get(def.material); - } + def.rt.solid = def.defaults.rt.solid; const float EPSILON = 0.01f; - def.rt.solid = + def.rt.solid = def.rt.solid && def.obstacle && (glm::i8vec3(def.hitboxes[0].size() + EPSILON) == def.size); def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1; + if (def.material.empty()) { + defaults.at("block-material").get(def.material); + } + if (def.rotatable) { for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) { def.rt.hitboxes[i].reserve(def.hitboxes.size()); From 693befcde8d6a4dddfc9049d74d303b027953b25 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 17 Aug 2026 23:41:24 +0300 Subject: [PATCH 20/20] fix default vcm aabb uv generation --- src/coders/vcm.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coders/vcm.cpp b/src/coders/vcm.cpp index 8c4965ca4..260657338 100644 --- a/src/coders/vcm.cpp +++ b/src/coders/vcm.cpp @@ -267,12 +267,12 @@ static void perform_box(const xmlelement& root, ModelBuilder& builder) { } UVRegion regions[6] {}; - regions[0].scale(to.x - from.x, to.y - from.y); - regions[1].scale(from.x - to.x, to.y - from.y); + regions[0].scale(to.z - from.z, to.y - from.y); + regions[1].scale(from.z - to.z, to.y - from.y); regions[2].scale(to.x - from.x, to.z - from.z); regions[3].scale(from.x - to.x, to.z - from.z); - regions[4].scale(to.z - from.z, to.y - from.y); - regions[5].scale(from.z - to.z, to.y - from.y); + regions[4].scale(to.x - from.x, to.y - from.y); + regions[5].scale(from.x - to.x, to.y - from.y); auto center = (from + to) * 0.5f; auto halfsize = (to - from) * 0.5f;