forked from erle/xmaps
Refactor map item creation for API extensibility
This commit is contained in:
parent
9879745ca2
commit
bc34ba34e8
13
init.lua
13
init.lua
|
@ -69,7 +69,9 @@ maps.get_map_filename = function(map_id)
|
|||
return "maps_map_texture_" .. map_id .. ".tga"
|
||||
end
|
||||
|
||||
maps.create_map_item = function(pos, draw_x)
|
||||
maps.create_map_item = function(pos, properties)
|
||||
properties = properties or {}
|
||||
|
||||
local itemstack = ItemStack("maps:map")
|
||||
local meta = itemstack:get_meta()
|
||||
|
||||
|
@ -82,7 +84,7 @@ maps.create_map_item = function(pos, draw_x)
|
|||
local maxp = vector.add(minp, vector.new(size - 1, size - 1, size - 1))
|
||||
meta:set_string("maps:maxp", minetest.pos_to_string(maxp))
|
||||
|
||||
if draw_x then
|
||||
if properties.draw_x then
|
||||
local xpos = vector.round(pos)
|
||||
meta:set_string("maps:xpos", minetest.pos_to_string(xpos))
|
||||
end
|
||||
|
@ -741,14 +743,17 @@ minetest.override_item(
|
|||
on_place = function(itemstack, player, pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
if pos then
|
||||
local map = maps.create_map_item(pos, true)
|
||||
local map = maps.create_map_item(
|
||||
pos,
|
||||
{ draw_x = true }
|
||||
)
|
||||
return map
|
||||
end
|
||||
end,
|
||||
on_secondary_use = function(itemstack, player, pointed_thing)
|
||||
local pos = player:get_pos()
|
||||
if pos then
|
||||
local map = maps.create_map_item(pos, false)
|
||||
local map = maps.create_map_item(pos)
|
||||
return map
|
||||
end
|
||||
end,
|
||||
|
|
Loading…
Reference in New Issue