improve drop visuals

This commit is contained in:
MihailRis 2024-07-03 21:09:38 +03:00
parent 4b084dffad
commit e6c3775286
2 changed files with 20 additions and 5 deletions

View File

@ -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

View File

@ -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<l_index>},
{"name", lua::wrap<l_name>},
@ -325,5 +332,6 @@ const luaL_Reg blocklib [] = {
{"get_textures", lua::wrap<l_get_textures>},
{"get_model", lua::wrap<l_get_model>},
{"get_hitbox", lua::wrap<l_get_hitbox>},
{"get_rotation_profile", lua::wrap<l_get_rotation_profile>},
{NULL, NULL}
};