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
This commit is contained in:
chmodsayshello 2022-03-26 18:57:40 +00:00
parent 08988b341d
commit 98f2bd1a20
1 changed files with 45 additions and 15 deletions

View File

@ -18,21 +18,51 @@ local random_frame = math.random(0, compass_frames-1)
function mcl_compass.get_compass_image(pos, dir, x, y, z) function mcl_compass.get_compass_image(pos, dir, x, y, z)
-- Compasses do not work in certain zones -- Compasses do not work in certain zones
if mcl_worlds.compass_works(pos) then if mcl_worlds.compass_works(pos) then
local spawn = {x=x,y=y,z=z} local _, dim = mcl_worlds.y_to_layer(y)
local ssp = minetest.setting_get_pos("static_spawnpoint") local _, playerdim = mcl_worlds.y_to_layer(pos.y)
if ssp then
spawn = ssp 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.
if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then local spawn = {x=x,y=y,z=z}
spawn = {x=0,y=0,z=0} local ssp = minetest.setting_get_pos("static_spawnpoint")
end if ssp then
end spawn = ssp
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z)) if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then
if angle_north < 0 then angle_north = angle_north + 360 end spawn = {x=0,y=0,z=0}
local angle_dir = -math.deg(dir) end
local angle_relative = (angle_north - angle_dir + 180) % 360 end
return math.floor((angle_relative/11.25) + 0.5) % compass_frames 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 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
end end
@ -193,4 +223,4 @@ minetest.register_node("mcl_compass:lodestone",{
_mcl_hardness = 1.5, _mcl_hardness = 1.5,
_mcl_blast_resistance = 6, _mcl_blast_resistance = 6,
sounds = mcl_sounds.node_sound_stone_defaults() sounds = mcl_sounds.node_sound_stone_defaults()
}) })