mirror of
https://github.com/pyrollo/display_modpack.git
synced 2024-11-28 00:53:49 +01:00
Merge pull request #15 from Thomas--S/positions
PR merged : Allow a greater object offset
This commit is contained in:
commit
aa319e4144
@ -49,7 +49,10 @@ This is a helper to register entities used for display.
|
|||||||
### Display_entities fields
|
### Display_entities fields
|
||||||
`on_display_update` is a callback in charge of setting up entity texture. If not set, entity will have no texture and will be displayed as unknown item.
|
`on_display_update` is a callback in charge of setting up entity texture. If not set, entity will have no texture and will be displayed as unknown item.
|
||||||
|
|
||||||
`depth`, `right` and `heigh` : Entity position regarding to node facedir/wallmounted main axis. Values for these fields can be any number between -0.5 and 0.5 (default value is 0). Position 0,0,0 is the center of the node. `depth` goes from front (-0.5) to rear (0.5), `height` goes from bottom (-0.5) to top (0.5) and `right` goes from left (-0.5) to right (0.5).
|
`depth`, `right` and `height` : Entity position regarding to node facedir/wallmounted main axis.
|
||||||
|
Values for these fields can be any number between -1.5 and 1.5 (default value is 0).
|
||||||
|
Position 0,0,0 is the center of the node.
|
||||||
|
`depth` goes from front (-0.5) to rear (0.5), `height` goes from bottom (-0.5) to top (0.5) and `right` goes from left (-0.5) to right (0.5).
|
||||||
|
|
||||||
In order to avoid flickering text, it's better to have text a little behind node surface. A good spacing value is given by `display_api.entity_spacing` variable.
|
In order to avoid flickering text, it's better to have text a little behind node surface. A good spacing value is given by `display_api.entity_spacing` variable.
|
||||||
|
|
||||||
|
@ -79,14 +79,25 @@ local function get_values(node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Checks if the object is related to the given position
|
||||||
|
local function check_entity_pos(pos, objref)
|
||||||
|
local real_pos = vector.round(objref:get_pos())
|
||||||
|
local pos_hash = objref:get_luaentity().pos
|
||||||
|
if pos_hash == nil then
|
||||||
|
return vector.equals(real_pos, vector.round(pos))
|
||||||
|
else
|
||||||
|
return vector.equals(minetest.get_position_from_hash(pos_hash), pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Gets the display entities attached with a node. Removes extra ones
|
--- Gets the display entities attached with a node. Removes extra ones
|
||||||
local function get_entities(pos)
|
local function get_entities(pos)
|
||||||
local objrefs = {}
|
local objrefs = {}
|
||||||
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||||
if ndef and ndef.display_entities then
|
if ndef and ndef.display_entities then
|
||||||
for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 1.5)) do
|
||||||
local entity = objref:get_luaentity()
|
local entity = objref:get_luaentity()
|
||||||
if entity and ndef.display_entities[entity.name] then
|
if entity and ndef.display_entities[entity.name] and check_entity_pos(pos, objref) then
|
||||||
if objrefs[entity.name] then
|
if objrefs[entity.name] then
|
||||||
objref:remove()
|
objref:remove()
|
||||||
else
|
else
|
||||||
@ -100,7 +111,7 @@ end
|
|||||||
|
|
||||||
local function clip_pos_prop(posprop)
|
local function clip_pos_prop(posprop)
|
||||||
if posprop then
|
if posprop then
|
||||||
return math.max(-0.5, math.min(0.5, posprop))
|
return math.max(-1.5, math.min(1.5, posprop))
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
@ -147,6 +158,7 @@ end
|
|||||||
function display_api.update_entities(pos)
|
function display_api.update_entities(pos)
|
||||||
local objrefs = place_entities(pos)
|
local objrefs = place_entities(pos)
|
||||||
for _, objref in pairs(objrefs) do
|
for _, objref in pairs(objrefs) do
|
||||||
|
objref:get_luaentity().pos = minetest.hash_node_position(pos)
|
||||||
call_node_on_display_update(pos, objref)
|
call_node_on_display_update(pos, objref)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -155,8 +167,20 @@ end
|
|||||||
--- of corresponding node for each entity.
|
--- of corresponding node for each entity.
|
||||||
function display_api.on_activate(entity, staticdata)
|
function display_api.on_activate(entity, staticdata)
|
||||||
if entity then
|
if entity then
|
||||||
|
if string.sub(staticdata, 1, string.len("return")) == "return" then
|
||||||
|
local data = core.deserialize(staticdata)
|
||||||
|
if data and type(data) == "table" then
|
||||||
|
entity.pos = data.pos
|
||||||
|
end
|
||||||
|
end
|
||||||
entity.object:set_armor_groups({immortal=1})
|
entity.object:set_armor_groups({immortal=1})
|
||||||
call_node_on_display_update(entity.object:getpos(), entity.object)
|
local pos
|
||||||
|
if entity.pos then
|
||||||
|
pos = minetest.get_position_from_hash(entity.pos)
|
||||||
|
else
|
||||||
|
pos = entity.object:getpos()
|
||||||
|
end
|
||||||
|
display_api.update_entities(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -226,6 +250,11 @@ function display_api.register_display_entity(entity_name)
|
|||||||
visual = "upright_sprite",
|
visual = "upright_sprite",
|
||||||
textures = {},
|
textures = {},
|
||||||
on_activate = display_api.on_activate,
|
on_activate = display_api.on_activate,
|
||||||
|
get_staticdata = function(self)
|
||||||
|
return minetest.serialize({
|
||||||
|
pos = self.pos,
|
||||||
|
})
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user