From 5bb1657bd86cb9938c08a669d7d3b3313e50b631 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 3 May 2021 10:46:59 +0200 Subject: [PATCH] Add moving marker for the player --- mods/ITEMS/mcl_maps/init.lua | 59 +++++++++++++++--- .../textures/mcl_maps_player_arrow.png | Bin 0 -> 1528 bytes .../mcl_maps/textures/mcl_maps_player_dot.png | Bin 0 -> 3101 bytes 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 mods/ITEMS/mcl_maps/textures/mcl_maps_player_arrow.png create mode 100644 mods/ITEMS/mcl_maps/textures/mcl_maps_player_dot.png diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index d6b972b86..b2c03b354 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -27,16 +27,20 @@ local loaded_maps = {} local c_air = minetest.get_content_id("air") function mcl_maps.create_map(pos) + local minp = vector.multiply(vector.floor(vector.divide(pos, 128)), 128) + local maxp = vector.add(minp, vector.new(127, 127, 127)) + local itemstack = ItemStack("mcl_maps:filled_map") local meta = itemstack:get_meta() local next_id = storage:get_int("next_id") storage:set_int("next_id", next_id + 1) local id = tostring(next_id) meta:set_string("mcl_maps:id", id) + meta:set_string("mcl_maps:minp", minetest.pos_to_string(minp)) + meta:set_string("mcl_maps:maxp", minetest.pos_to_string(maxp)) tt.reload_itemstack_description(itemstack) + creating_maps[id] = true - local minp = vector.multiply(vector.floor(vector.divide(pos, 128)), 128) - local maxp = vector.add(minp, vector.new(127, 127, 127)) minetest.emerge_area(minp, maxp, function(blockpos, action, calls_remaining) if calls_remaining > 0 then return @@ -260,14 +264,20 @@ local maps = {} local huds = {} minetest.register_on_joinplayer(function(player) - huds[player] = player:hud_add({ + local map_def = { hud_elem_type = "image", text = "blank.png", - position = {x = 0.875, y = 0.8}, - alignment = {x = -1, y = -1}, + position = {x = 0.75, y = 0.8}, + alignment = {x = 0, y = -1}, offset = {x = 0, y = 0}, scale = {x = 2, y = 2}, - }) + } + local marker_def = table.copy(map_def) + marker_def.alignment = {x = 0, y = 0} + huds[player] = { + map = player:hud_add(map_def), + marker = player:hud_add(marker_def), + } end) minetest.register_on_leaveplayer(function(player) @@ -279,6 +289,7 @@ minetest.register_globalstep(function(dtime) for _, player in pairs(minetest.get_connected_players()) do local wield = player:get_wielded_item() local texture = mcl_maps.load_map_item(wield) + local hud = huds[player] if texture then local wield_def = wield:get_definition() local hand_def = player:get_inventory():get_stack("hand", 1):get_definition() @@ -289,11 +300,43 @@ minetest.register_globalstep(function(dtime) end if texture ~= maps[player] then - player:hud_change(huds[player], "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture) + player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture) maps[player] = texture end + + local pos = vector.round(player:get_pos()) + local meta = wield:get_meta() + local minp = minetest.string_to_pos(meta:get_string("mcl_maps:minp")) + local maxp = minetest.string_to_pos(meta:get_string("mcl_maps:maxp")) + + local marker = "mcl_maps_player_arrow.png" + + if pos.x < minp.x then + marker = "mcl_maps_player_dot.png" + pos.x = minp.x + elseif pos.x > maxp.x then + marker = "mcl_maps_player_dot.png" + pos.x = maxp.x + end + + if pos.z < minp.z then + marker = "mcl_maps_player_dot.png" + pos.z = minp.z + elseif pos.z > maxp.z then + marker = "mcl_maps_player_dot.png" + pos.z = maxp.z + end + + if marker == "mcl_maps_player_arrow.png" then + local yaw = (math.floor(player:get_look_horizontal() * 180 / math.pi / 90 + 0.5) % 4) * 90 + marker = marker .. "^[transformR" .. yaw + end + + player:hud_change(hud.marker, "text", marker) + player:hud_change(hud.marker, "offset", {x = (6 - 140 / 2 + pos.x - minp.x) * 2, y = (6 - 140 + maxp.z - pos.z) * 2}) elseif maps[player] then - player:hud_change(huds[player], "text", "blank.png") + player:hud_change(hud.map, "text", "blank.png") + player:hud_change(hud.marker, "text", "blank.png") maps[player] = nil end end diff --git a/mods/ITEMS/mcl_maps/textures/mcl_maps_player_arrow.png b/mods/ITEMS/mcl_maps/textures/mcl_maps_player_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..3f58f676501e514ddee898f7a19ad409590a5249 GIT binary patch literal 1528 zcmV zaB^>EX>4U6ba`-PAZ2)IW&i+q+O1bvlH@83{MRYw2uNZ*4q%9QH+aXN1mjv<-CawM z30ssbv}6h#MeYCpI{m@L$yl;3M4!AjxNNdXGA7aNSDH^Yc0TtjEXntJx-1f?6jGOc zUiKM!cU^FpbGg@3TyG>UM@Qu4P)B6JWV=lgdfD}Cm!s77iBB=yrdni|bs5f7)}4;> z*1PeWZWT5FrOhFbiZo?4^BMOHblj{N(#!)-@xj?_Z?D)g#EgZ?X5bSC_2^qJDMM1e*^x zFf4#v=Q58Ga68Py90?BD_5jwrAdGksUT|Tq6SG) zb?{`z;4VRvZW_T^l}4&i%Ow|{anp=fIU@4LFcpR~#*%Lb{q*vkLA}=j5u3Q<)F#0) z`Wk5r=Ef6NAcXtk%}s!hvFJB9{exBogKokcQD8P@cTpT)drK$J3Ofh6?+T`{EeC)I zu^p0O1p~&jI`(XWNMHtz5d>vqE^4KK0d`I{Bq>(a3k8WXVq;CHQMN+k0HjG zVos72XP`?yg%ndtISXY3%J7w8pP?yIwAkW`FQLSeO0H<1YOAZhh8kUKo_fBp#%tT2#~ZBiVofGf!!BG{gO)-# zT<|zf+~5q1iDfVz1_Nkl8JwBO*2-XRaAuNVQ#e7AZg4{z55_>DZ7iz>G#C%q3QkD zpV0qOnY*N$RdNp9rQ|s`W=W0pq&XyAOp2ZtwV1wHb@iJM4IQeQpYMd9Dy1JPYuf|z z@{l%;=Q*RR>M^lB@p_E>@&j^T zS}(o57W?ba^zlhH{&3*$B>e>pgOXObK^?>Z00D$)LqkwWLqi~Na&Km7Y-Iodc$|Ha zJxIeq9K~PLmKLcv*g?f1Lv^wsD&nYBC_;r$E41oha{YuR4M~cNqu^R_@ME#+;Nq;S zgR3A2et@{SIVrkGiT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