add aabb drop models support
This commit is contained in:
parent
fa450c1c15
commit
4b084dffad
@ -6,20 +6,25 @@ inair = true
|
|||||||
ready = false
|
ready = false
|
||||||
|
|
||||||
local dropitem = ARGS.item
|
local dropitem = ARGS.item
|
||||||
|
local scale = {1, 1, 1}
|
||||||
|
local rotation = mat4.rotate({
|
||||||
|
math.random(), math.random(), math.random()
|
||||||
|
}, 360)
|
||||||
|
|
||||||
do -- setup visuals
|
do -- setup visuals
|
||||||
local rotation = mat4.rotate({0, 1, 0}, math.random() * 360)
|
local matrix = mat4.idt()
|
||||||
mat4.rotate(rotation, {1, 0, 0}, math.random() * 360, rotation)
|
|
||||||
mat4.rotate(rotation, {0, 0, 1}, math.random() * 360, rotation)
|
|
||||||
rig:set_matrix(0, rotation)
|
|
||||||
local icon = item.icon(dropitem.id)
|
local icon = item.icon(dropitem.id)
|
||||||
if icon:find("^block%-previews%:") then
|
if icon:find("^block%-previews%:") then
|
||||||
local bid = block.index(icon:sub(16))
|
local bid = block.index(icon:sub(16))
|
||||||
if block.get_model(bid) == "X" then
|
local model = block.get_model(bid)
|
||||||
|
if model == "X" then
|
||||||
entity:set_rig("drop-item")
|
entity:set_rig("drop-item")
|
||||||
body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0}))
|
body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0}))
|
||||||
rig:set_texture("$0", icon)
|
rig:set_texture("$0", icon)
|
||||||
else
|
else
|
||||||
|
if model == "aabb" then
|
||||||
|
scale = block.get_hitbox(bid, 0)[2]
|
||||||
|
end
|
||||||
local textures = block.get_textures(bid)
|
local textures = block.get_textures(bid)
|
||||||
for i,t in ipairs(textures) do
|
for i,t in ipairs(textures) do
|
||||||
rig:set_texture("$"..tostring(i-1), "blocks:"..textures[i])
|
rig:set_texture("$"..tostring(i-1), "blocks:"..textures[i])
|
||||||
@ -30,10 +35,15 @@ do -- setup visuals
|
|||||||
body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0}))
|
body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0}))
|
||||||
rig:set_texture("$0", icon)
|
rig:set_texture("$0", icon)
|
||||||
end
|
end
|
||||||
|
mat4.mul(matrix, rotation, matrix)
|
||||||
|
mat4.scale(matrix, scale, matrix)
|
||||||
|
rig:set_matrix(0, matrix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_grounded(force)
|
function on_grounded(force)
|
||||||
rig:set_matrix(0, mat4.rotate({0, 1, 0}, math.random()*360))
|
local matrix = mat4.rotate({0, 1, 0}, math.random()*360)
|
||||||
|
mat4.scale(matrix, scale, matrix)
|
||||||
|
rig:set_matrix(0, matrix)
|
||||||
inair = false
|
inair = false
|
||||||
ready = true
|
ready = true
|
||||||
end
|
end
|
||||||
@ -53,9 +63,13 @@ end
|
|||||||
function on_update()
|
function on_update()
|
||||||
if inair then
|
if inair then
|
||||||
local dt = time.delta();
|
local dt = time.delta();
|
||||||
local matrix = rig:get_matrix(0)
|
|
||||||
mat4.rotate(matrix, {0, 1, 0}, 240*dt, matrix)
|
mat4.rotate(rotation, {0, 1, 0}, 240*dt, rotation)
|
||||||
mat4.rotate(matrix, {0, 0, 1}, 240*dt, matrix)
|
mat4.rotate(rotation, {0, 0, 1}, 240*dt, rotation)
|
||||||
|
|
||||||
|
local matrix = mat4.idt()
|
||||||
|
mat4.mul(matrix, rotation, matrix)
|
||||||
|
mat4.scale(matrix, scale, matrix)
|
||||||
rig:set_matrix(0, matrix)
|
rig:set_matrix(0, matrix)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -280,8 +280,23 @@ static int l_get_model(lua::State* L) {
|
|||||||
case BlockModel::custom: return lua::pushstring(L, "custom");
|
case BlockModel::custom: return lua::pushstring(L, "custom");
|
||||||
case BlockModel::none: return lua::pushstring(L, "none");
|
case BlockModel::none: return lua::pushstring(L, "none");
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
lua::createtable(L, 2, 0);
|
||||||
|
|
||||||
|
lua::pushvec3_arr(L, hitbox.min());
|
||||||
|
lua::rawseti(L, 1);
|
||||||
|
|
||||||
|
lua::pushvec3_arr(L, hitbox.size());
|
||||||
|
lua::rawseti(L, 2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg blocklib [] = {
|
const luaL_Reg blocklib [] = {
|
||||||
@ -309,5 +324,6 @@ const luaL_Reg blocklib [] = {
|
|||||||
{"seek_origin", lua::wrap<l_seek_origin>},
|
{"seek_origin", lua::wrap<l_seek_origin>},
|
||||||
{"get_textures", lua::wrap<l_get_textures>},
|
{"get_textures", lua::wrap<l_get_textures>},
|
||||||
{"get_model", lua::wrap<l_get_model>},
|
{"get_model", lua::wrap<l_get_model>},
|
||||||
|
{"get_hitbox", lua::wrap<l_get_hitbox>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user