Randomly spin compass and clock in VoidNetherEnd
This commit is contained in:
parent
c7fc3845c1
commit
39f4573294
|
@ -12,10 +12,17 @@ mcl_clock.stereotype = "mcl_clock:clock"
|
||||||
local watch = {}
|
local watch = {}
|
||||||
watch.old_time = -1
|
watch.old_time = -1
|
||||||
|
|
||||||
-- Image of all 64 possible faces
|
local clock_frames = 64
|
||||||
|
|
||||||
|
-- Timer for random clock spinning
|
||||||
|
local random_timer = 0.0
|
||||||
|
local random_timer_trigger = 1.0 -- random clock spinning tick in seconds. Increase if there are performance problems
|
||||||
|
local random_frame = math.random(0, clock_frames-1)
|
||||||
|
|
||||||
|
-- Image of all possible faces
|
||||||
watch.images = {}
|
watch.images = {}
|
||||||
for frame=0,63 do
|
for frame=0, clock_frames-1 do
|
||||||
table.insert(watch.images, "mcl_clock_clock.png^[verticalframe:64:"..frame)
|
table.insert(watch.images, "mcl_clock_clock.png^[verticalframe:"..clock_frames..":"..frame)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function round(num)
|
local function round(num)
|
||||||
|
@ -23,9 +30,9 @@ local function round(num)
|
||||||
end
|
end
|
||||||
|
|
||||||
function watch.get_clock_frame()
|
function watch.get_clock_frame()
|
||||||
local t = 64 * minetest.get_timeofday()
|
local t = clock_frames * minetest.get_timeofday()
|
||||||
t = round(t)
|
t = round(t)
|
||||||
if t == 64 then t = 0 end
|
if t == clock_frames then t = 0 end
|
||||||
return tostring(t)
|
return tostring(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,6 +72,12 @@ local force_clock_update_timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
local now = watch.get_clock_frame()
|
local now = watch.get_clock_frame()
|
||||||
force_clock_update_timer = force_clock_update_timer + dtime
|
force_clock_update_timer = force_clock_update_timer + dtime
|
||||||
|
random_timer = random_timer + dtime
|
||||||
|
-- This causes the random spinning of the clock
|
||||||
|
if random_timer >= random_timer_trigger then
|
||||||
|
random_frame = (random_frame + math.random(-4, 4)) % clock_frames
|
||||||
|
random_timer = 0
|
||||||
|
end
|
||||||
|
|
||||||
if watch.old_time == now and force_clock_update_timer < 60 then
|
if watch.old_time == now and force_clock_update_timer < 60 then
|
||||||
return
|
return
|
||||||
|
@ -77,14 +90,18 @@ minetest.register_globalstep(function(dtime)
|
||||||
for p, player in ipairs(players) do
|
for p, player in ipairs(players) do
|
||||||
for s, stack in ipairs(player:get_inventory():get_list("main")) do
|
for s, stack in ipairs(player:get_inventory():get_list("main")) do
|
||||||
local _, dim = mcl_util.y_to_layer(player:getpos().y)
|
local _, dim = mcl_util.y_to_layer(player:getpos().y)
|
||||||
|
local frame
|
||||||
-- Clocks do not work in the End, Nether or the Void
|
-- Clocks do not work in the End, Nether or the Void
|
||||||
if dim ~= "end" and dim ~= "nether" and dim ~= "void" then
|
if dim == "end" or dim == "nether" or dim == "void" then
|
||||||
local count = stack:get_count()
|
frame = random_frame
|
||||||
if stack:get_name() == mcl_clock.stereotype then
|
else
|
||||||
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..now.." "..count)
|
frame = now
|
||||||
elseif string.sub(stack:get_name(), 1, 16) == "mcl_clock:clock_" then
|
end
|
||||||
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..now.." "..count)
|
local count = stack:get_count()
|
||||||
end
|
if stack:get_name() == mcl_clock.stereotype then
|
||||||
|
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)
|
||||||
|
elseif minetest.get_item_group(stack:get_name(), "clock") ~= 0 then
|
||||||
|
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -111,7 +128,7 @@ minetest.register_craft({
|
||||||
watch.register_item(mcl_clock.stereotype, watch.images[1], true, 1)
|
watch.register_item(mcl_clock.stereotype, watch.images[1], true, 1)
|
||||||
|
|
||||||
-- Faces
|
-- Faces
|
||||||
for a=0,63,1 do
|
for a=0,clock_frames-1,1 do
|
||||||
local b = a
|
local b = a
|
||||||
if b > 31 then
|
if b > 31 then
|
||||||
b = b - 32
|
b = b - 32
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
mcl_compass = {}
|
mcl_compass = {}
|
||||||
|
|
||||||
|
local compass_frames = 32
|
||||||
|
|
||||||
local default_spawn_settings = minetest.settings:get("static_spawnpoint")
|
local default_spawn_settings = minetest.settings:get("static_spawnpoint")
|
||||||
|
|
||||||
|
-- Timer for random compass spinning
|
||||||
|
local random_timer = 0
|
||||||
|
local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Increase if there are performance problems
|
||||||
|
|
||||||
|
local random_frame = math.random(0, compass_frames-1)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
random_timer = random_timer + dtime
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
|
|
||||||
|
if random_timer >= random_timer_trigger then
|
||||||
|
random_frame = (random_frame + math.random(-1, 1)) % compass_frames
|
||||||
|
random_timer = 0
|
||||||
|
end
|
||||||
for i,player in ipairs(players) do
|
for i,player in ipairs(players) do
|
||||||
local function has_compass(player)
|
local function has_compass(player)
|
||||||
for _,stack in ipairs(player:get_inventory():get_list("main")) do
|
for _,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||||
|
@ -14,34 +28,37 @@ minetest.register_globalstep(function(dtime)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if has_compass(player) then
|
if has_compass(player) then
|
||||||
local spawn = {x=0,y=0,z=0}
|
|
||||||
local s = minetest.settings:get("static_spawnpoint")
|
|
||||||
if s then
|
|
||||||
local numbers = string.split(s, ",")
|
|
||||||
spawn.x = tonumber(numbers[1])
|
|
||||||
spawn.y = tonumber(numbers[2])
|
|
||||||
spawn.z = tonumber(numbers[3])
|
|
||||||
if type(spawn.x) ~= "number" and type(spawn.y) ~= "number" and type(spawn.z) ~= "number" then
|
|
||||||
spawn = {x=0,y=0,z=0}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
local _, dim = mcl_util.y_to_layer(pos.y)
|
local _, dim = mcl_util.y_to_layer(pos.y)
|
||||||
|
local compass_image
|
||||||
-- Compasses do not work in the End, Nether or the Void
|
-- Compasses do not work in the End, Nether or the Void
|
||||||
if dim ~= "end" and dim ~= "nether" and dim ~= "void" then
|
if dim == "end" or dim == "nether" or dim == "void" then
|
||||||
|
compass_image = random_frame
|
||||||
|
else
|
||||||
|
local spawn = {x=0,y=0,z=0}
|
||||||
|
local s = minetest.settings:get("static_spawnpoint")
|
||||||
|
if s then
|
||||||
|
local numbers = string.split(s, ",")
|
||||||
|
spawn.x = tonumber(numbers[1])
|
||||||
|
spawn.y = tonumber(numbers[2])
|
||||||
|
spawn.z = tonumber(numbers[3])
|
||||||
|
if type(spawn.x) ~= "number" and type(spawn.y) ~= "number" and type(spawn.z) ~= "number" then
|
||||||
|
spawn = {x=0,y=0,z=0}
|
||||||
|
end
|
||||||
|
end
|
||||||
local dir = player:get_look_horizontal()
|
local dir = player:get_look_horizontal()
|
||||||
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
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
|
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||||
local angle_dir = -math.deg(dir)
|
local angle_dir = -math.deg(dir)
|
||||||
local angle_relative = (angle_north - angle_dir + 180) % 360
|
local angle_relative = (angle_north - angle_dir + 180) % 360
|
||||||
local compass_image = math.floor((angle_relative/11.25) + 0.5)%32
|
compass_image = math.floor((angle_relative/11.25) + 0.5) % compass_frames
|
||||||
|
end
|
||||||
|
|
||||||
for j,stack in ipairs(player:get_inventory():get_list("main")) do
|
for j,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||||
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
|
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
|
||||||
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
|
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
|
||||||
local count = stack:get_count()
|
local count = stack:get_count()
|
||||||
player:get_inventory():set_stack("main", j, ItemStack("mcl_compass:"..compass_image.." "..count))
|
player:get_inventory():set_stack("main", j, ItemStack("mcl_compass:"..compass_image.." "..count))
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,7 +66,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local images = {}
|
local images = {}
|
||||||
for frame=0,31 do
|
for frame = 0, compass_frames-1 do
|
||||||
local s = string.format("%02d", frame)
|
local s = string.format("%02d", frame)
|
||||||
table.insert(images, "mcl_compass_compass_"..s..".png")
|
table.insert(images, "mcl_compass_compass_"..s..".png")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user