forked from VoxeLibre/VoxeLibre
merge lodestone in new branch #2
|
@ -14,46 +14,53 @@ local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Inc
|
|||
local random_frame = math.random(0, compass_frames-1)
|
||||
|
||||
function mcl_compass.get_compass_image(pos, dir, itemstack)
|
||||
local lodestone_pos = minetest.string_to_pos(itemstack:get_meta():get_string("pointsto"))
|
||||
local lodestone_pos = minetest.string_to_pos(itemstack:get_meta():get_string("pointsto"))
|
||||
|
||||
if lodestone_pos then --lodestone meta present
|
||||
local _, dim = mcl_worlds.y_to_layer(lodestone_pos.y)
|
||||
local _, playerdim = mcl_worlds.y_to_layer(pos.y)
|
||||
|
||||
if dim == playerdim then --Check if player and compass target are in the same dimension, above check is just if the diemension is valid for the non lodestone compass
|
||||
local function get_far_node(pos) --code from minetest dev wiki: https://dev.minetest.net/minetest.get_node
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "ignore" then
|
||||
minetest.get_voxel_manip():read_from_map(pos, pos)
|
||||
node = minetest.get_node(pos)
|
||||
end
|
||||
return node
|
||||
end
|
||||
local function get_far_node(pos) --code from minetest dev wiki: https://dev.minetest.net/minetest.get_node
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "ignore" then
|
||||
minetest.get_voxel_manip():read_from_map(pos, pos)
|
||||
node = minetest.get_node(pos)
|
||||
end
|
||||
return node
|
||||
end
|
||||
|
||||
if get_far_node(lodestone_pos).name == "mcl_compass:lodestone" then --check if lodestone still exists
|
||||
local angle_north = math.deg(math.atan2(lodestone_pos.x - pos.x, lodestone_pos.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 .. "_lodestone"
|
||||
local angle_north = math.deg(math.atan2(lodestone_pos.x - pos.x, lodestone_pos.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 .. "_lodestone"
|
||||
else -- lodestone got destroyed
|
||||
return random_frame .. "_lodestone"
|
||||
end
|
||||
end
|
||||
else
|
||||
return random_frame .. "_lodestone"
|
||||
end
|
||||
else --no lodestone meta, normal compass....
|
||||
local spawn = {x = 0, y=0, z=0} --before you guys tell me that the normal compass no points to real spawn, it always pointed to 0 0
|
||||
local spawn = {x = 0, y=0, z=0} --before you guys tell me that the normal compass no points to real spawn, it always pointed to 0 0
|
||||
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
|
||||
|
||||
if mcl_worlds.compass_works(pos) then --is the player in the overworld?
|
||||
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
||||
if mcl_worlds.compass_works(pos) then --is the player in the overworld?
|
||||
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
|
||||
|
@ -78,14 +85,14 @@ minetest.register_globalstep(function(dtime)
|
|||
local pos = player:get_pos()
|
||||
|
||||
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
||||
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
|
||||
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), stack)
|
||||
if minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
|
||||
local itemname = "mcl_compass:"..compass_image
|
||||
stack:set_name(itemname)
|
||||
player:get_inventory():set_stack("main", j, stack)
|
||||
end
|
||||
end
|
||||
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
|
||||
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), stack)
|
||||
if minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
|
||||
local itemname = "mcl_compass:"..compass_image
|
||||
stack:set_name(itemname)
|
||||
player:get_inventory():set_stack("main", j, stack)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue