1
0
Fork 0

Refactor map item creation for API extensibility

This commit is contained in:
Nils Dagsson Moskopp 2022-05-20 18:50:59 +02:00
parent 9879745ca2
commit bc34ba34e8
Signed by untrusted user who does not match committer: erle
GPG Key ID: A3BC671C35191080
1 changed files with 9 additions and 4 deletions

View File

@ -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,