0
0
Fork 0

Make compasses work in itemframes

This commit is contained in:
Lizzy Fleckenstein 2021-05-03 11:22:47 +02:00
parent f528b31d48
commit ecc2010fe5
3 changed files with 26 additions and 22 deletions

View File

@ -12,6 +12,27 @@ 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)
-- Compasses do not work in certain zones
if mcl_worlds.compass_works(pos) then
local spawn = {x=0,y=0,z=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
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
end
minetest.register_globalstep(function(dtime)
random_timer = random_timer + dtime
@ -30,27 +51,7 @@ minetest.register_globalstep(function(dtime)
end
if has_compass(player) then
local pos = player:get_pos()
local dim = mcl_worlds.pos_to_dimension(pos)
local compass_image
-- Compasses do not work in certain zones
if not mcl_worlds.compass_works(pos) then
compass_image = random_frame
else
local spawn = {x=0,y=0,z=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
local dir = player:get_look_horizontal()
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
compass_image = math.floor((angle_relative/11.25) + 0.5) % compass_frames
end
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal())
for j,stack in pairs(player:get_inventory():get_list("main")) do
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and

View File

@ -188,6 +188,9 @@ minetest.register_node("mcl_itemframes:item_frame",{
end
local put_itemstack = ItemStack(itemstack)
put_itemstack:set_count(1)
if minetest.get_item_group(put_itemstack:get_name(), "compass") > 0 then
put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2))))
end
inv:set_stack("main", 1, put_itemstack)
update_item_entity(pos, node)
-- Add node infotext when item has been named

View File

@ -1,3 +1,3 @@
name = mcl_itemframes
depends = mcl_core, mcl_sounds
depends = mcl_core, mcl_sounds, mcl_compass
optional_depends = screwdriver