From 98f2bd1a20fbc9a6f5127d344868d3cf5f891249 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sat, 26 Mar 2022 18:57:40 +0000 Subject: [PATCH] fixed critical issue, see description for details This commit fixes lodestone compasses not working in any dimension except from the overworld, it also changes the behavior so that lodestone compasses only work in the dimension they were clicked at --- mods/ITEMS/mcl_compass/init.lua | 60 ++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_compass/init.lua b/mods/ITEMS/mcl_compass/init.lua index 47e8d43d9..b0015c9a7 100644 --- a/mods/ITEMS/mcl_compass/init.lua +++ b/mods/ITEMS/mcl_compass/init.lua @@ -18,21 +18,51 @@ local random_frame = math.random(0, compass_frames-1) function mcl_compass.get_compass_image(pos, dir, x, y, z) -- Compasses do not work in certain zones if mcl_worlds.compass_works(pos) then - local spawn = {x=x,y=y,z=z} - local ssp = minetest.setting_get_pos("static_spawnpoint") - if ssp then - spawn = ssp - if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then - spawn = {x=0,y=0,z=0} - end - end - 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 - local angle_dir = -math.deg(dir) - local angle_relative = (angle_north - angle_dir + 180) % 360 - return math.floor((angle_relative/11.25) + 0.5) % compass_frames + local _, dim = mcl_worlds.y_to_layer(y) + local _, playerdim = mcl_worlds.y_to_layer(pos.y) + + if dim == playerdim then --"chmod, why are you checking this, someone already checked if the diemension is valid above" Thats right, but that only checks if a player is in the overworld, this if statement checks if the player and the compass target are in the same diemension, so a lodestone compass from the end or the nether wouldn't work in the overworld etc. + local spawn = {x=x,y=y,z=z} + local ssp = minetest.setting_get_pos("static_spawnpoint") + if ssp then + spawn = ssp + if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then + spawn = {x=0,y=0,z=0} + end + end + 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 + local angle_dir = -math.deg(dir) + local angle_relative = (angle_north - angle_dir + 180) % 360 + return math.floor((angle_relative/11.25) + 0.5) % compass_frames + else + return random_frame + end else - return random_frame + if x ~= 0 and y ~= 0 and z~= 0 then + local _, dim = mcl_worlds.y_to_layer(y) + local _, playerdim = mcl_worlds.y_to_layer(pos.y) + if dim == playerdim then --already explained that very same if statement above + local spawn = {x=x,y=y,z=z} + local ssp = minetest.setting_get_pos("static_spawnpoint") + if ssp then + spawn = ssp + if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then + spawn = {x=0,y=0,z=0} + end + end + 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 + local angle_dir = -math.deg(dir) + local angle_relative = (angle_north - angle_dir + 180) % 360 + return math.floor((angle_relative/11.25) + 0.5) % compass_frames + else + return random_frame + end + + else + return random_frame + end end end @@ -193,4 +223,4 @@ minetest.register_node("mcl_compass:lodestone",{ _mcl_hardness = 1.5, _mcl_blast_resistance = 6, sounds = mcl_sounds.node_sound_stone_defaults() -}) +}) \ No newline at end of file