From 9879745ca2d93c2f3e12daacf1214378407b2da3 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Fri, 20 May 2022 18:40:02 +0200 Subject: [PATCH] Allow creation of maps with or without X --- init.lua | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index f402437..621b7ff 100644 --- a/init.lua +++ b/init.lua @@ -69,7 +69,7 @@ maps.get_map_filename = function(map_id) return "maps_map_texture_" .. map_id .. ".tga" end -maps.create_map = function(pos) +maps.create_map_item = function(pos, draw_x) local itemstack = ItemStack("maps:map") local meta = itemstack:get_meta() @@ -82,8 +82,10 @@ maps.create_map = function(pos) local maxp = vector.add(minp, vector.new(size - 1, size - 1, size - 1)) meta:set_string("maps:maxp", minetest.pos_to_string(maxp)) - local xpos = vector.round(pos) - meta:set_string("maps:xpos", minetest.pos_to_string(xpos)) + if draw_x then + local xpos = vector.round(pos) + meta:set_string("maps:xpos", minetest.pos_to_string(xpos)) + end local filename = maps.get_map_filename(map_id) maps.work[map_id] = true @@ -733,19 +735,23 @@ minetest.register_globalstep( end ) -maps.create_map_item = function(itemstack, player, pointed_thing) - local pos = player:get_pos() - if pos then - local map = maps.create_map(pos) - return map - end -end - minetest.override_item( "map:mapping_kit", { - on_place = maps.create_map_item, - on_secondary_use = maps.create_map_item, + on_place = function(itemstack, player, pointed_thing) + local pos = pointed_thing.under + if pos then + local map = maps.create_map_item(pos, 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) + return map + end + end, } )