forked from MineClone5/MineClone5
Globalize mcl_clock API
This commit is contained in:
parent
ecc2010fe5
commit
74e3c6555d
|
@ -1,7 +1,7 @@
|
||||||
local S = minetest.get_translator("mcl_clock")
|
local S = minetest.get_translator("mcl_clock")
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
mcl_clock, renew of the renew of the watch mod
|
mcl_clock, renew of the renew of the mcl_clock mod
|
||||||
|
|
||||||
Original from Echo, here: http://forum.minetest.net/viewtopic.php?id=3795
|
Original from Echo, here: http://forum.minetest.net/viewtopic.php?id=3795
|
||||||
]]--
|
]]--
|
||||||
|
@ -11,8 +11,7 @@ mcl_clock = {}
|
||||||
-- This is the itemstring of the default clock item. It is used for the default inventory image, help entries, and the like
|
-- This is the itemstring of the default clock item. It is used for the default inventory image, help entries, and the like
|
||||||
mcl_clock.stereotype = "mcl_clock:clock"
|
mcl_clock.stereotype = "mcl_clock:clock"
|
||||||
|
|
||||||
local watch = {}
|
mcl_clock.old_time = -1
|
||||||
watch.old_time = -1
|
|
||||||
|
|
||||||
local clock_frames = 64
|
local clock_frames = 64
|
||||||
|
|
||||||
|
@ -22,20 +21,20 @@ local random_timer_trigger = 1.0 -- random clock spinning tick in seconds. Incre
|
||||||
local random_frame = math.random(0, clock_frames-1)
|
local random_frame = math.random(0, clock_frames-1)
|
||||||
|
|
||||||
-- Image of all possible faces
|
-- Image of all possible faces
|
||||||
watch.images = {}
|
mcl_clock.images = {}
|
||||||
for frame=0, clock_frames-1 do
|
for frame=0, clock_frames-1 do
|
||||||
local sframe = tostring(frame)
|
local sframe = tostring(frame)
|
||||||
if string.len(sframe) == 1 then
|
if string.len(sframe) == 1 then
|
||||||
sframe = "0" .. sframe
|
sframe = "0" .. sframe
|
||||||
end
|
end
|
||||||
table.insert(watch.images, "mcl_clock_clock_"..sframe..".png")
|
table.insert(mcl_clock.images, "mcl_clock_clock_"..sframe..".png")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function round(num)
|
local function round(num)
|
||||||
return math.floor(num + 0.5)
|
return math.floor(num + 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
function watch.get_clock_frame()
|
function mcl_clock.get_clock_frame()
|
||||||
local t = clock_frames * minetest.get_timeofday()
|
local t = clock_frames * minetest.get_timeofday()
|
||||||
t = round(t)
|
t = round(t)
|
||||||
if t == clock_frames then t = 0 end
|
if t == clock_frames then t = 0 end
|
||||||
|
@ -45,7 +44,7 @@ end
|
||||||
local doc_mod = minetest.get_modpath("doc") ~= nil
|
local doc_mod = minetest.get_modpath("doc") ~= nil
|
||||||
|
|
||||||
-- Register items
|
-- Register items
|
||||||
function watch.register_item(name, image, creative, frame)
|
function mcl_clock.register_item(name, image, creative, frame)
|
||||||
local g = 1
|
local g = 1
|
||||||
if creative then
|
if creative then
|
||||||
g = 0
|
g = 0
|
||||||
|
@ -78,7 +77,7 @@ end
|
||||||
local force_clock_update_timer = 0
|
local force_clock_update_timer = 0
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
local now = watch.get_clock_frame()
|
local now = mcl_clock.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
|
random_timer = random_timer + dtime
|
||||||
-- This causes the random spinning of the clock
|
-- This causes the random spinning of the clock
|
||||||
|
@ -87,12 +86,12 @@ minetest.register_globalstep(function(dtime)
|
||||||
random_timer = 0
|
random_timer = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if watch.old_time == now and force_clock_update_timer < 60 then
|
if mcl_clock.old_time == now and force_clock_update_timer < 60 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
force_clock_update_timer = 0
|
force_clock_update_timer = 0
|
||||||
|
|
||||||
watch.old_time = now
|
mcl_clock.old_time = now
|
||||||
|
|
||||||
for p, player in pairs(minetest.get_connected_players()) do
|
for p, player in pairs(minetest.get_connected_players()) do
|
||||||
for s, stack in pairs(player:get_inventory():get_list("main")) do
|
for s, stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
|
@ -117,7 +116,7 @@ end)
|
||||||
-- Immediately set correct clock time after crafting
|
-- Immediately set correct clock time after crafting
|
||||||
minetest.register_on_craft(function(itemstack)
|
minetest.register_on_craft(function(itemstack)
|
||||||
if itemstack:get_name() == mcl_clock.stereotype then
|
if itemstack:get_name() == mcl_clock.stereotype then
|
||||||
itemstack:set_name("mcl_clock:clock_"..watch.get_clock_frame())
|
itemstack:set_name("mcl_clock:clock_"..mcl_clock.get_clock_frame())
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -132,7 +131,7 @@ minetest.register_craft({
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Clock tool
|
-- Clock tool
|
||||||
watch.register_item(mcl_clock.stereotype, watch.images[1], true, 1)
|
mcl_clock.register_item(mcl_clock.stereotype, mcl_clock.images[1], true, 1)
|
||||||
|
|
||||||
-- Faces
|
-- Faces
|
||||||
for a=0,clock_frames-1,1 do
|
for a=0,clock_frames-1,1 do
|
||||||
|
@ -142,6 +141,6 @@ for a=0,clock_frames-1,1 do
|
||||||
else
|
else
|
||||||
b = b + 32
|
b = b + 32
|
||||||
end
|
end
|
||||||
watch.register_item("mcl_clock:clock_"..tostring(a), watch.images[b+1], false, a+1)
|
mcl_clock.register_item("mcl_clock:clock_"..tostring(a), mcl_clock.images[b+1], false, a+1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue