mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-23 00:19:32 +01:00
Fix lodestone compass meta handling.
* The nature of a compass was being determined by looking at its meta. This caused lodestone compasses with unset meta to turn into regular compasses. Fixed by using string matching on the itemname. * Changed lodestone rightclick handler to explicitly set the correct name and frame of the compass used on it instead of waiting for globalstep to do this.
This commit is contained in:
parent
8ae605165b
commit
14c882f982
1 changed files with 13 additions and 7 deletions
|
@ -35,6 +35,7 @@ local m_atan2 = math.atan2
|
|||
local m_floor = math.floor
|
||||
local m_rnd = math.random
|
||||
local vec_new = vector.new
|
||||
local string_find = string.find
|
||||
local string_to_pos = minetest.string_to_pos
|
||||
local get_connected_players = minetest.get_connected_players
|
||||
local get_item_group = minetest.get_item_group
|
||||
|
@ -90,8 +91,7 @@ end
|
|||
-- itemstack: the compass including its optional lodestone metadata.
|
||||
--
|
||||
local function get_compass_frame(pos, dir, itemstack)
|
||||
local lpos_str = itemstack:get_meta():get_string("pointsto")
|
||||
if lpos_str == "" then -- normal compass
|
||||
if not string_find(itemstack:get_name(), "_lodestone") then -- normal compass
|
||||
-- Compasses only work in the overworld
|
||||
if compass_works(pos) then
|
||||
local spawn_pos = setting_get_pos("static_spawnpoint")
|
||||
|
@ -101,6 +101,7 @@ local function get_compass_frame(pos, dir, itemstack)
|
|||
return random_frame
|
||||
end
|
||||
else -- lodestone compass
|
||||
local lpos_str = itemstack:get_meta():get_string("pointsto")
|
||||
local lpos = string_to_pos(lpos_str)
|
||||
if not lpos then
|
||||
minetest.log("warning", "mcl_compass: invalid lodestone position!")
|
||||
|
@ -185,10 +186,11 @@ minetest.register_globalstep(function(dtime)
|
|||
-- check if current compass image still matches true orientation
|
||||
compass_frame = get_compass_frame(pos, dir, stack)
|
||||
if compass_nr - 1 ~= compass_frame then
|
||||
if stack:get_meta():get_string("pointsto") == "" then
|
||||
stack:set_name("mcl_compass:" .. compass_frame)
|
||||
else
|
||||
|
||||
if string_find(stack:get_name(), "_lodestone") then
|
||||
stack:set_name("mcl_compass:" .. compass_frame .. "_lodestone")
|
||||
else
|
||||
stack:set_name("mcl_compass:" .. compass_frame)
|
||||
end
|
||||
inv:set_stack("main", j, stack)
|
||||
end
|
||||
|
@ -251,9 +253,13 @@ minetest.register_alias("mcl_compass:compass", "mcl_compass:" .. stereotype_fram
|
|||
minetest.register_node("mcl_compass:lodestone",{
|
||||
description=S("Lodestone"),
|
||||
on_rightclick = function(pos, node, player, itemstack)
|
||||
if itemstack.get_name(itemstack).match(itemstack.get_name(itemstack),"mcl_compass:") then
|
||||
if itemstack.get_name(itemstack) ~= "mcl_compass:lodestone" then
|
||||
local name = itemstack.get_name(itemstack)
|
||||
if string_find(name,"mcl_compass:") then
|
||||
if name ~= "mcl_compass:lodestone" then
|
||||
itemstack:get_meta():set_string("pointsto", minetest.pos_to_string(pos))
|
||||
local dir = player:get_look_horizontal()
|
||||
local frame = get_compass_frame(pos, dir, itemstack)
|
||||
itemstack:set_name("mcl_compass:" .. frame .. "_lodestone")
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
|
Loading…
Reference in a new issue