various fixes

This commit is contained in:
chmodsayshello 2022-04-26 19:24:58 +00:00
parent 1735343c5e
commit 09193b4907
1 changed files with 22 additions and 13 deletions

View File

@ -1,9 +1,22 @@
local stereotype_frame = 18
local S = minetest.get_translator(minetest.get_current_modname())
mcl_compass = {}
local compass_frames = 32
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
--Not sure spawn point should be dymanic (is it in mc?)
--local default_spawn_settings = minetest.settings:get("static_spawnpoint")
@ -14,6 +27,11 @@ 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)
if not itemstack then
return random_frame --no itemstack! random frame
minetest.log("WARNING: mcl_compass.get_compass_image() was called without itemstack, returning random frame!")
end
local lodestone_pos = minetest.string_to_pos(itemstack:get_meta():get_string("pointsto"))
if lodestone_pos then --lodestone meta present
@ -21,14 +39,6 @@ function mcl_compass.get_compass_image(pos, dir, itemstack)
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
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))
@ -72,7 +82,7 @@ minetest.register_globalstep(function(dtime)
random_frame = (random_frame + math.random(-1, 1)) % compass_frames
random_timer = 0
end
for i,player in pairs(minetest.get_connected_players()) do
for _,player in pairs(minetest.get_connected_players()) do
local function has_compass(player)
for _,stack in pairs(player:get_inventory():get_list("main")) do
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
@ -87,7 +97,7 @@ minetest.register_globalstep(function(dtime)
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
if minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image and minetest.get_item_group(stack:get_name(), "compass")-1 .. "_lodestone" ~=compass_image then --Explaination: First check for normal compasses, secound check for lodestone ones
local itemname = "mcl_compass:"..compass_image
stack:set_name(itemname)
player:get_inventory():set_stack("main", j, stack)
@ -107,7 +117,6 @@ end
local doc_mod = minetest.get_modpath("doc")
local stereotype_frame = 18
for i,img in ipairs(images) do
local inv = 1
if i == stereotype_frame then