Display location of item frame in item frame map

This commit is contained in:
Nils Dagsson Moskopp 2022-02-04 23:33:34 +01:00
parent 16a68af119
commit f0a925aa20
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
2 changed files with 51 additions and 5 deletions

View File

@ -63,11 +63,50 @@ minetest.register_entity("mcl_itemframes:map", {
textures = {"blank.png"},
},
on_activate = function(self, staticdata)
self.id = staticdata
self.object:set_properties({textures = {mcl_maps.load_map(self.id)}})
local data = minetest.deserialize(staticdata)
-- originally this function only got the id
if nil == data then
self.id = data
self._pos = { x = 0/0, y = 0/0, z = 0/0 }
self._minp = { x = 0/0, y = 0/0, z = 0/0 }
self._maxp = { x = 0/0, y = 0/0, z = 0/0 }
else
self.id = data.id
self._pos = data._pos
self._minp = data._minp
self._maxp = data._maxp
end
local marker = ""
if (
self._pos.x > self._minp.x and
self._pos.x < self._maxp.x and
self._pos.z > self._minp.z and
self._pos.z < self._maxp.z
) then
-- marker is 8×8, points downwards
local x = self._pos.x - self._minp.x - 3
local z = self._maxp.z - self._pos.z - 6
-- hack to avoid clipping
if x < 0 then x = 0 end
if z < 0 then z = 0 end
if x > 120 then x = 120 end
if z > 120 then z = 120 end
marker = "^[combine:8x8:" .. x .. "," .. z .. "=mcl_maps_itemframe_location_marker.png"
end
self.object:set_properties(
{
textures = { mcl_maps.load_map(self.id) .. marker }
}
)
end,
get_staticdata = function(self)
return self.id
local data = {
id = self.id,
_pos = self._pos,
_minp = self._minp,
_maxp = self._maxp,
}
return minetest.serialize(data)
end,
})
@ -105,7 +144,8 @@ local update_item_entity = function(pos, node, param2)
pos.z = pos.z + posad.z*6.5/16
end
local yaw = math.pi*2 - param2 * math.pi/2
local map_id = item:get_meta():get_string("mcl_maps:id")
local meta = item:get_meta()
local map_id = meta:get_string("mcl_maps:id")
if map_id == "" then
local e = minetest.add_entity(pos, "mcl_itemframes:item")
local lua = e:get_luaentity()
@ -124,7 +164,13 @@ local update_item_entity = function(pos, node, param2)
e:set_yaw(yaw)
end
else
local e = minetest.add_entity(pos, "mcl_itemframes:map", map_id)
local staticdata = {
id = map_id,
_pos = pos,
_minp = minetest.string_to_pos(meta:get_string("mcl_maps:minp")),
_maxp = minetest.string_to_pos(meta:get_string("mcl_maps:maxp")),
}
local e = minetest.add_entity(pos, "mcl_itemframes:map", minetest.serialize(staticdata))
e:set_yaw(yaw)
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B