add module 'item_models'
This commit is contained in:
parent
cf448def59
commit
27a7d7eb44
@ -1,3 +1,5 @@
|
||||
local item_models = require "core:item_models"
|
||||
|
||||
local tsf = entity.transform
|
||||
local body = entity.rigidbody
|
||||
local rig = entity.skeleton
|
||||
@ -13,6 +15,7 @@ if SAVED_DATA.item then
|
||||
dropitem.count = SAVED_DATA.count
|
||||
end
|
||||
|
||||
local DROP_SCALE = 0.3
|
||||
local scale = {1, 1, 1}
|
||||
local rotation = mat4.rotate({
|
||||
math.random(), math.random(), math.random()
|
||||
@ -25,31 +28,9 @@ end
|
||||
|
||||
do -- setup visuals
|
||||
local matrix = mat4.idt()
|
||||
local icon = item.icon(dropitem.id)
|
||||
if icon:find("^block%-previews%:") then
|
||||
local bid = block.index(icon:sub(16))
|
||||
model = block.get_model(bid)
|
||||
if model == "X" then
|
||||
body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0}))
|
||||
rig:set_model(0, "drop-item")
|
||||
rig:set_texture("$0", icon)
|
||||
else
|
||||
if model == "aabb" then
|
||||
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
|
||||
rig:set_texture("$"..tostring(i-1), "blocks:"..textures[i])
|
||||
end
|
||||
end
|
||||
else
|
||||
body:set_size(vec3.mul(body:get_size(), {1.0, 0.3, 1.0}))
|
||||
rig:set_model(0, "drop-item")
|
||||
rig:set_texture("$0", icon)
|
||||
end
|
||||
scale = item_models.setup(dropitem.id, rig)
|
||||
local bodysize = math.min(scale[1], scale[2], scale[3]) * DROP_SCALE
|
||||
body:set_size({scale[1] * DROP_SCALE, bodysize, scale[3] * DROP_SCALE})
|
||||
mat4.mul(matrix, rotation, matrix)
|
||||
mat4.scale(matrix, scale, matrix)
|
||||
rig:set_matrix(0, matrix)
|
||||
|
||||
32
res/modules/item_models.lua
Normal file
32
res/modules/item_models.lua
Normal file
@ -0,0 +1,32 @@
|
||||
local function setup(id, rig)
|
||||
local icon = item.icon(id)
|
||||
local size = {1.0, 1.0, 1.0}
|
||||
if icon:find("^block%-previews%:") then
|
||||
local bid = block.index(icon:sub(16))
|
||||
model = block.get_model(bid)
|
||||
if model == "X" then
|
||||
size = {1.0, 0.3, 1.0}
|
||||
rig:set_model(0, "drop-item")
|
||||
rig:set_texture("$0", icon)
|
||||
else
|
||||
if model == "aabb" then
|
||||
local rot = block.get_rotation_profile(bid) == "pipe" and 4 or 0
|
||||
size = block.get_hitbox(bid, rot)[2]
|
||||
vec3.mul(size, 2.0, size)
|
||||
end
|
||||
local textures = block.get_textures(bid)
|
||||
for i,t in ipairs(textures) do
|
||||
rig:set_texture("$"..tostring(i-1), "blocks:"..textures[i])
|
||||
end
|
||||
end
|
||||
else
|
||||
size = {1.0, 0.3, 1.0}
|
||||
rig:set_model(0, "drop-item")
|
||||
rig:set_texture("$0", icon)
|
||||
end
|
||||
return size
|
||||
end
|
||||
|
||||
return {
|
||||
setup=setup,
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user