diff --git a/README.md b/README.md index de624b9d..d408f788 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,8 @@ The following mods are also included: * transport/ * [carts][] ([WTFPL/CC0](mods/transport/carts/README.txt)) * [helicopter][] ([GPL](mods/transport/helicopter/LICENSE) / [CC-BY-NC](mods/transport/helicopter/README.md)) +* ui/ + * [compass][] (CC-BY-SA / WTFPL) * weather/ * [lightning][] ([LGPL/CC-BY-SA](mods/weather/lightning/README.md)) * [weather][] ([LGPL/WTFPL/CC-BY-SA](mods/weather/weather/README)) @@ -109,6 +111,7 @@ The following mods are also included: [character_creator]: https://forum.minetest.net/viewtopic.php?f=9&t=13138 [chatlog]: https://forum.minetest.net/viewtopic.php?id=6220 [cme]: https://forum.minetest.net/viewtopic.php?t=8638 +[compass]: https://forum.minetest.net/viewtopic.php?t=3785 [craft_guide]: https://forum.minetest.net/viewtopic.php?t=2334 [creeper]: https://forum.minetest.net/viewtopic.php?t=11891 [farming_plus]: https://forum.minetest.net/viewtopic.php?t=2787 diff --git a/mods/ui/compass/depends.txt b/mods/ui/compass/depends.txt new file mode 100644 index 00000000..4ad96d51 --- /dev/null +++ b/mods/ui/compass/depends.txt @@ -0,0 +1 @@ +default diff --git a/mods/ui/compass/init.lua b/mods/ui/compass/init.lua new file mode 100644 index 00000000..639576ce --- /dev/null +++ b/mods/ui/compass/init.lua @@ -0,0 +1,119 @@ +-- default to 0/0/0 +local default_spawn = {x=0, y=0, z=0} +-- default to static spawnpoint (overwrites 0/0/0) +local default_spawn_settings = minetest.setting_get("static_spawnpoint") +if (default_spawn_settings) then + pos1 = string.find(default_spawn_settings, ",", 0) + default_spawn.x = tonumber(string.sub(default_spawn_settings, 0, pos1 - 1)) + pos2 = string.find(default_spawn_settings, ",", pos1 + 1) + default_spawn.y = tonumber(string.sub(default_spawn_settings, pos1 + 1, pos2 - 1)) + default_spawn.z = tonumber(string.sub(default_spawn_settings, pos2 + 1)) +end + +local last_time_spawns_read = "default" +local pilzadams_spawns = {} +local sethome_spawns = {} +function read_spawns() + -- read PilzAdams bed-mod positions + local pilzadams_file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r") + if pilzadams_file then + pilzadams_spawns = minetest.deserialize(pilzadams_file:read("*all")) + pilzadams_file:close() + end + -- read sethome-mod positions + if minetest.get_modpath('sethome') then + local sethome_file = io.open(minetest.get_modpath('sethome')..'/homes', "r") + if sethome_file then + while true do + local x = sethome_file:read("*n") + if x == nil then + break + end + local y = sethome_file:read("*n") + local z = sethome_file:read("*n") + local name = sethome_file:read("*l") + sethome_spawns[name:sub(2)] = {x = x, y = y, z = z} + end + io.close(sethome_file) + end + end +end + +minetest.register_globalstep(function(dtime) + if last_time_spawns_read ~= os.date("%M") then + last_time_spawns_read = os.date("%M") + read_spawns() + end + local players = minetest.get_connected_players() + for i,player in ipairs(players) do + -- try to get position from PilzAdams bed-mod spawn + local spawn = pilzadams_spawns[player:get_player_name()] + -- fallback to sethome position + if spawn == nil then + spawn = sethome_spawns[player:get_player_name()] + end + -- fallback to default + if spawn == nil then + spawn = default_spawn; + end + pos = player:getpos() + dir = player:get_look_yaw() + local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z)) + if angle_north < 0 then angle_north = angle_north + 360 end + angle_dir = 90 - math.deg(dir) + local angle_relative = (angle_north - angle_dir) % 360 + local compass_image = math.floor((angle_relative/30) + 0.5)%12 + + local wielded_item = player:get_wielded_item():get_name() + if string.sub(wielded_item, 0, 8) == "compass:" then + player:set_wielded_item("compass:"..compass_image) + else + if player:get_inventory() then + for i,stack in ipairs(player:get_inventory():get_list("main")) do + if i<9 and string.sub(stack:get_name(), 0, 8) == "compass:" then + player:get_inventory():remove_item("main", stack:get_name()) + player:get_inventory():add_item("main", "compass:"..compass_image) + end + end + end + end + end +end) + +local images = { + "compass_0.png", + "compass_1.png", + "compass_2.png", + "compass_3.png", + "compass_4.png", + "compass_5.png", + "compass_6.png", + "compass_7.png", + "compass_8.png", + "compass_9.png", + "compass_10.png", + "compass_11.png", +} + +local i +for i,img in ipairs(images) do + local inv = 1 + if i == 1 then + inv = 0 + end + minetest.register_tool("compass:"..(i-1), { + description = "Compass", + inventory_image = img, + wield_image = img, + groups = {not_in_creative_inventory=inv} + }) +end + +minetest.register_craft({ + output = 'compass:1', + recipe = { + {'', 'default:steel_ingot', ''}, + {'default:steel_ingot', 'default:mese_crystal_fragment', 'default:steel_ingot'}, + {'', 'default:steel_ingot', ''} + } +}) \ No newline at end of file diff --git a/mods/ui/compass/textures/compass_0.png b/mods/ui/compass/textures/compass_0.png new file mode 100644 index 00000000..bb33a804 Binary files /dev/null and b/mods/ui/compass/textures/compass_0.png differ diff --git a/mods/ui/compass/textures/compass_1.png b/mods/ui/compass/textures/compass_1.png new file mode 100644 index 00000000..f7646828 Binary files /dev/null and b/mods/ui/compass/textures/compass_1.png differ diff --git a/mods/ui/compass/textures/compass_10.png b/mods/ui/compass/textures/compass_10.png new file mode 100644 index 00000000..7b44a288 Binary files /dev/null and b/mods/ui/compass/textures/compass_10.png differ diff --git a/mods/ui/compass/textures/compass_11.png b/mods/ui/compass/textures/compass_11.png new file mode 100644 index 00000000..2cf7fc03 Binary files /dev/null and b/mods/ui/compass/textures/compass_11.png differ diff --git a/mods/ui/compass/textures/compass_2.png b/mods/ui/compass/textures/compass_2.png new file mode 100644 index 00000000..a4712f0d Binary files /dev/null and b/mods/ui/compass/textures/compass_2.png differ diff --git a/mods/ui/compass/textures/compass_3.png b/mods/ui/compass/textures/compass_3.png new file mode 100644 index 00000000..3b07e41f Binary files /dev/null and b/mods/ui/compass/textures/compass_3.png differ diff --git a/mods/ui/compass/textures/compass_4.png b/mods/ui/compass/textures/compass_4.png new file mode 100644 index 00000000..511497af Binary files /dev/null and b/mods/ui/compass/textures/compass_4.png differ diff --git a/mods/ui/compass/textures/compass_5.png b/mods/ui/compass/textures/compass_5.png new file mode 100644 index 00000000..8ea4db90 Binary files /dev/null and b/mods/ui/compass/textures/compass_5.png differ diff --git a/mods/ui/compass/textures/compass_6.png b/mods/ui/compass/textures/compass_6.png new file mode 100644 index 00000000..85b09ffe Binary files /dev/null and b/mods/ui/compass/textures/compass_6.png differ diff --git a/mods/ui/compass/textures/compass_7.png b/mods/ui/compass/textures/compass_7.png new file mode 100644 index 00000000..64797814 Binary files /dev/null and b/mods/ui/compass/textures/compass_7.png differ diff --git a/mods/ui/compass/textures/compass_8.png b/mods/ui/compass/textures/compass_8.png new file mode 100644 index 00000000..6b5a7115 Binary files /dev/null and b/mods/ui/compass/textures/compass_8.png differ diff --git a/mods/ui/compass/textures/compass_9.png b/mods/ui/compass/textures/compass_9.png new file mode 100644 index 00000000..5243b798 Binary files /dev/null and b/mods/ui/compass/textures/compass_9.png differ