mirror of
https://github.com/pyrollo/display_modpack.git
synced 2025-10-23 20:05:41 +02:00
feat(orientation): Make display_api able to handle dynamic entity orientation
This commit is contained in:
@@ -147,7 +147,8 @@ function display_api.update_entities(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, objref in pairs(get_display_objrefs(pos, true)) do
|
for _, objref in pairs(get_display_objrefs(pos, true)) do
|
||||||
local edef = ndef.display_entities[objref:get_luaentity().name]
|
local entity = objref:get_luaentity()
|
||||||
|
local edef = ndef.display_entities[entity.name]
|
||||||
local depth = clip_pos_prop(edef.depth)
|
local depth = clip_pos_prop(edef.depth)
|
||||||
local right = clip_pos_prop(edef.right)
|
local right = clip_pos_prop(edef.right)
|
||||||
local top = clip_pos_prop(edef.top)
|
local top = clip_pos_prop(edef.top)
|
||||||
@@ -160,14 +161,19 @@ function display_api.update_entities(pos)
|
|||||||
|
|
||||||
if objref.set_rotation then
|
if objref.set_rotation then
|
||||||
objref:set_rotation({
|
objref:set_rotation({
|
||||||
x = ov.rotation.x*math.pi/2,
|
x = ov.rotation.x * math.pi / 2 +
|
||||||
y = ov.rotation.y*math.pi/2 + (edef.yaw or 0),
|
(entity.rotation and entity.rotation.x or 0),
|
||||||
z = ov.rotation.z*math.pi/2,
|
y = ov.rotation.y * math.pi / 2 +
|
||||||
|
(entity.rotation and entity.rotation.y or 0) +
|
||||||
|
(edef.yaw or 0),
|
||||||
|
z = ov.rotation.z * math.pi / 2 +
|
||||||
|
(entity.rotation and entity.rotation.z or 0),
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
if ov.rotation.x ~=0 or ov.rotation.y ~= 0 then
|
if ov.rotation.x ~=0 or ov.rotation.y ~= 0 then
|
||||||
minetest.log("warning", string.format(
|
minetest.log("warning", string.format(
|
||||||
"[display_api] unable to rotate correctly entity for node at %s without set_rotation method.",
|
"[display_api] unable to rotate correctly entity for " ..
|
||||||
|
"node at %s without set_rotation method.",
|
||||||
minetest.pos_to_string(pos)))
|
minetest.pos_to_string(pos)))
|
||||||
end
|
end
|
||||||
objref:set_yaw(ov.rotation.y*math.pi/2 + (edef.yaw or 0))
|
objref:set_yaw(ov.rotation.y*math.pi/2 + (edef.yaw or 0))
|
||||||
@@ -276,14 +282,18 @@ end
|
|||||||
|
|
||||||
--- Creates display entity with some fields and the on_activate callback
|
--- Creates display entity with some fields and the on_activate callback
|
||||||
function display_api.register_display_entity(entity_name)
|
function display_api.register_display_entity(entity_name)
|
||||||
if not minetest.registered_entities[entity_name] then
|
|
||||||
|
if minetest.registered_entities[entity_name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_entity(':'..entity_name, {
|
minetest.register_entity(':'..entity_name, {
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
visual = "upright_sprite",
|
visual = "upright_sprite",
|
||||||
textures = {},
|
textures = {},
|
||||||
collide_with_objects = false,
|
collide_with_objects = false,
|
||||||
pointable = false
|
pointable = false,
|
||||||
},
|
},
|
||||||
on_activate = display_api.on_activate,
|
on_activate = display_api.on_activate,
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
@@ -294,13 +304,13 @@ function display_api.register_display_entity(entity_name)
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_lbm({
|
minetest.register_lbm({
|
||||||
label = "Update display_api entities",
|
label = "Update display_api entities",
|
||||||
name = "display_api:update_entities",
|
name = "display_api:update_entities",
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
nodenames = {"group:display_api",
|
nodenames = {"group:display_api",
|
||||||
"group:display_modpack_node", "group:display_lib_node"}, -- See deprecated(1)
|
"group:display_modpack_node",
|
||||||
|
"group:display_lib_node"}, -- See deprecated(1)
|
||||||
action = function(pos, node) display_api.update_entities(pos) end,
|
action = function(pos, node) display_api.update_entities(pos) end,
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user