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")
|
||||
|
||||
--[[
|
||||
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
|
||||
]]--
|
||||
|
@ -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
|
||||
mcl_clock.stereotype = "mcl_clock:clock"
|
||||
|
||||
local watch = {}
|
||||
watch.old_time = -1
|
||||
mcl_clock.old_time = -1
|
||||
|
||||
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)
|
||||
|
||||
-- Image of all possible faces
|
||||
watch.images = {}
|
||||
mcl_clock.images = {}
|
||||
for frame=0, clock_frames-1 do
|
||||
local sframe = tostring(frame)
|
||||
if string.len(sframe) == 1 then
|
||||
sframe = "0" .. sframe
|
||||
end
|
||||
table.insert(watch.images, "mcl_clock_clock_"..sframe..".png")
|
||||
table.insert(mcl_clock.images, "mcl_clock_clock_"..sframe..".png")
|
||||
end
|
||||
|
||||
local function round(num)
|
||||
return math.floor(num + 0.5)
|
||||
end
|
||||
|
||||
function watch.get_clock_frame()
|
||||
function mcl_clock.get_clock_frame()
|
||||
local t = clock_frames * minetest.get_timeofday()
|
||||
t = round(t)
|
||||
if t == clock_frames then t = 0 end
|
||||
|
@ -45,7 +44,7 @@ end
|
|||
local doc_mod = minetest.get_modpath("doc") ~= nil
|
||||
|
||||
-- Register items
|
||||
function watch.register_item(name, image, creative, frame)
|
||||
function mcl_clock.register_item(name, image, creative, frame)
|
||||
local g = 1
|
||||
if creative then
|
||||
g = 0
|
||||
|
@ -78,7 +77,7 @@ end
|
|||
local force_clock_update_timer = 0
|
||||
|
||||
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
|
||||
random_timer = random_timer + dtime
|
||||
-- This causes the random spinning of the clock
|
||||
|
@ -87,12 +86,12 @@ minetest.register_globalstep(function(dtime)
|
|||
random_timer = 0
|
||||
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
|
||||
end
|
||||
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 s, stack in pairs(player:get_inventory():get_list("main")) do
|
||||
|
@ -117,7 +116,7 @@ end)
|
|||
-- Immediately set correct clock time after crafting
|
||||
minetest.register_on_craft(function(itemstack)
|
||||
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)
|
||||
|
||||
|
@ -132,7 +131,7 @@ minetest.register_craft({
|
|||
})
|
||||
|
||||
-- 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
|
||||
for a=0,clock_frames-1,1 do
|
||||
|
@ -142,6 +141,6 @@ for a=0,clock_frames-1,1 do
|
|||
else
|
||||
b = b + 32
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue