forked from VoxeLibre/VoxeLibre
add force laod cooldown
This commit is contained in:
parent
3e152db05a
commit
3a08ba6f78
|
@ -7,11 +7,23 @@ mcl_compass = {}
|
||||||
|
|
||||||
local compass_frames = 32
|
local compass_frames = 32
|
||||||
|
|
||||||
local function get_far_node(pos) --code from minetest dev wiki: https://dev.minetest.net/minetest.get_node
|
local function get_far_node(pos, itemstack) --code from minetest dev wiki: https://dev.minetest.net/minetest.get_node, some edits have been made to add a cooldown for force loads
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if node.name == "ignore" then
|
if node.name == "ignore" then
|
||||||
|
tstamp = tonumber(itemstack:get_meta():get_string("last_forceload"))
|
||||||
|
if tstamp == nil then --this is only relevant for new lodestone compasses, the ones that have never performes a forceload yet
|
||||||
|
itemstack:get_meta():set_string("last_forceload", tostring(os.time(os.date("!*t"))))
|
||||||
|
tstamp = tonumber(os.time(os.date("!*t")))
|
||||||
|
end
|
||||||
|
if tonumber(os.time(os.date("!*t"))) - tstamp > 180 then --current time in secounds - old time in secounds, if it is over 180 (3 mins): forceload
|
||||||
|
itemstack:get_meta():set_string("last_forceload", tostring(os.time(os.date("!*t"))))
|
||||||
minetest.get_voxel_manip():read_from_map(pos, pos)
|
minetest.get_voxel_manip():read_from_map(pos, pos)
|
||||||
node = minetest.get_node(pos)
|
node = minetest.get_node(pos)
|
||||||
|
minetest.log("forceloaded, cooldown reset!")
|
||||||
|
else
|
||||||
|
minetest.log("cooldown not over yet")
|
||||||
|
node = {name="mcl_compass:lodestone"} --cooldown not over yet, pretend like there is something...
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
|
@ -40,7 +52,7 @@ function mcl_compass.get_compass_image(pos, dir, itemstack)
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
if get_far_node(lodestone_pos).name == "mcl_compass:lodestone" then --check if lodestone still exists
|
if get_far_node(lodestone_pos, itemstack).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))
|
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
|
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||||
local angle_dir = -math.deg(dir)
|
local angle_dir = -math.deg(dir)
|
||||||
|
@ -99,6 +111,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), stack)
|
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 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
|
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
|
local itemname = "mcl_compass:"..compass_image
|
||||||
|
--minetest.log(os.time(os.date("!*t")))
|
||||||
stack:set_name(itemname)
|
stack:set_name(itemname)
|
||||||
player:get_inventory():set_stack("main", j, stack)
|
player:get_inventory():set_stack("main", j, stack)
|
||||||
end
|
end
|
||||||
|
@ -191,7 +204,6 @@ minetest.register_node("mcl_compass:lodestone",{
|
||||||
if itemstack.get_name(itemstack).match(itemstack.get_name(itemstack),"mcl_compass:") then
|
if itemstack.get_name(itemstack).match(itemstack.get_name(itemstack),"mcl_compass:") then
|
||||||
if itemstack.get_name(itemstack) ~= "mcl_compass:lodestone" then
|
if itemstack.get_name(itemstack) ~= "mcl_compass:lodestone" then
|
||||||
itemstack:get_meta():set_string("pointsto", minetest.pos_to_string(pos))
|
itemstack:get_meta():set_string("pointsto", minetest.pos_to_string(pos))
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue