From e6c3775286e2c28ad8a7df20ff8c305a493eed06 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 3 Jul 2024 21:09:38 +0300 Subject: [PATCH] improve drop visuals --- res/content/base/scripts/components/drop.lua | 15 +++++++++++---- src/logic/scripting/lua/libblock.cpp | 10 +++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/res/content/base/scripts/components/drop.lua b/res/content/base/scripts/components/drop.lua index e6466b2a..3adc5760 100644 --- a/res/content/base/scripts/components/drop.lua +++ b/res/content/base/scripts/components/drop.lua @@ -16,14 +16,17 @@ do -- setup visuals local icon = item.icon(dropitem.id) if icon:find("^block%-previews%:") then local bid = block.index(icon:sub(16)) - local model = block.get_model(bid) + model = block.get_model(bid) if model == "X" then entity:set_rig("drop-item") body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0})) rig:set_texture("$0", icon) else if model == "aabb" then - scale = block.get_hitbox(bid, 0)[2] + local rot = block.get_rotation_profile(bid) == "pipe" and 4 or 0 + scale = block.get_hitbox(bid, rot)[2] + body:set_size(vec3.mul(body:get_size(), {1.0, 0.7, 1.0})) + vec3.mul(scale, 1.5, scale) end local textures = block.get_textures(bid) for i,t in ipairs(textures) do @@ -41,7 +44,11 @@ do -- setup visuals end function on_grounded(force) - local matrix = mat4.rotate({0, 1, 0}, math.random()*360) + local matrix = mat4.idt() + mat4.rotate(matrix, {0, 1, 0}, math.random()*360, matrix) + if model == "aabb" then + mat4.rotate(matrix, {1, 0, 0}, 90, matrix) + end mat4.scale(matrix, scale, matrix) rig:set_matrix(0, matrix) inair = false @@ -66,7 +73,7 @@ function on_update() mat4.rotate(rotation, {0, 1, 0}, 240*dt, rotation) mat4.rotate(rotation, {0, 0, 1}, 240*dt, rotation) - + local matrix = mat4.idt() mat4.mul(matrix, rotation, matrix) mat4.scale(matrix, scale, matrix) diff --git a/src/logic/scripting/lua/libblock.cpp b/src/logic/scripting/lua/libblock.cpp index 1527babb..ce54b258 100644 --- a/src/logic/scripting/lua/libblock.cpp +++ b/src/logic/scripting/lua/libblock.cpp @@ -286,7 +286,7 @@ static int l_get_model(lua::State* L) { static int l_get_hitbox(lua::State* L) { if (auto def = require_block(L)) { - auto& hitbox = def->rt.hitboxes[0].at(lua::tointeger(L, 2)); + auto& hitbox = def->rt.hitboxes[lua::tointeger(L, 2)].at(0); lua::createtable(L, 2, 0); lua::pushvec3_arr(L, hitbox.min()); @@ -299,6 +299,13 @@ static int l_get_hitbox(lua::State* L) { return 0; } +static int l_get_rotation_profile(lua::State* L) { + if (auto def = require_block(L)) { + return lua::pushstring(L, def->rotations.name); + } + return 0; +} + const luaL_Reg blocklib [] = { {"index", lua::wrap}, {"name", lua::wrap}, @@ -325,5 +332,6 @@ const luaL_Reg blocklib [] = { {"get_textures", lua::wrap}, {"get_model", lua::wrap}, {"get_hitbox", lua::wrap}, + {"get_rotation_profile", lua::wrap}, {NULL, NULL} };