mirror of
https://github.com/pyrollo/display_modpack.git
synced 2025-10-22 19:45:22 +02:00
feat(orientation): Make display_api able to handle dynamic entity orientation
This commit is contained in:
@@ -95,7 +95,7 @@ local function get_orientation_values(node)
|
|||||||
local paramtype2 = ndef.paramtype2
|
local paramtype2 = ndef.paramtype2
|
||||||
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
||||||
return wallmounted_values[node.param2 % 8]
|
return wallmounted_values[node.param2 % 8]
|
||||||
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
||||||
return facedir_values[node.param2 % 32]
|
return facedir_values[node.param2 % 32]
|
||||||
else
|
else
|
||||||
-- No orientation or unknown orientation type
|
-- No orientation or unknown orientation type
|
||||||
@@ -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))
|
||||||
@@ -229,7 +235,7 @@ function display_api.on_place(itemstack, placer, pointed_thing, override_param2)
|
|||||||
param2 = minetest.dir_to_wallmounted(dir)
|
param2 = minetest.dir_to_wallmounted(dir)
|
||||||
|
|
||||||
elseif ndef.paramtype2 == "facedir" or
|
elseif ndef.paramtype2 == "facedir" or
|
||||||
ndef.paramtype2 == "colorfacedir" then
|
ndef.paramtype2 == "colorfacedir" then
|
||||||
param2 = minetest.dir_to_facedir(dir, true)
|
param2 = minetest.dir_to_facedir(dir, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -276,24 +282,27 @@ 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
|
|
||||||
minetest.register_entity(':'..entity_name, {
|
if minetest.registered_entities[entity_name] then
|
||||||
initial_properties = {
|
return
|
||||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
|
||||||
visual = "upright_sprite",
|
|
||||||
textures = {},
|
|
||||||
collide_with_objects = false,
|
|
||||||
pointable = false
|
|
||||||
},
|
|
||||||
on_activate = display_api.on_activate,
|
|
||||||
get_staticdata = function(self)
|
|
||||||
return minetest.serialize({ nodepos = self.nodepos })
|
|
||||||
end,
|
|
||||||
on_blast = function(self, damage)
|
|
||||||
return false, false, {}
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_entity(':'..entity_name, {
|
||||||
|
initial_properties = {
|
||||||
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||||
|
visual = "upright_sprite",
|
||||||
|
textures = {},
|
||||||
|
collide_with_objects = false,
|
||||||
|
pointable = false,
|
||||||
|
},
|
||||||
|
on_activate = display_api.on_activate,
|
||||||
|
get_staticdata = function(self)
|
||||||
|
return minetest.serialize({ nodepos = self.nodepos })
|
||||||
|
end,
|
||||||
|
on_blast = function(self, damage)
|
||||||
|
return false, false, {}
|
||||||
|
end,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_lbm({
|
minetest.register_lbm({
|
||||||
@@ -301,6 +310,7 @@ minetest.register_lbm({
|
|||||||
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