41 lines
1.3 KiB
Lua
Raw Normal View History

local S = minetest.get_translator_auto({"ru"})
2020-08-09 21:12:17 +02:00
2020-05-26 19:10:04 +02:00
for hour = 0, 12 do
local img = hour ~= 0 and "watch_" .. hour or "blank"
minetest.register_tool("watch:" .. hour, {
2020-08-09 21:12:17 +02:00
description = S"Watch",
2020-05-26 19:10:04 +02:00
inventory_image = "watch_watch.png^" .. img .. ".png",
2021-10-28 17:05:07 +02:00
wield_image = "watch_watch.png^" .. img .. ".png",
2020-05-26 19:10:04 +02:00
groups = {watch = hour, not_in_creative_inventory = (hour == 0 and 0) or 1}
})
end
minetest.register_craft({
output = "watch:0",
recipe = {
{"", "default:gold_ingot", ""},
{"default:gold_ingot", "bluestone:dust", "default:gold_ingot"},
2020-05-26 19:10:04 +02:00
{"", "default:gold_ingot", ""}
}
})
local floor = math.floor
local get_timeofday = minetest.get_timeofday
local registered_tools = minetest.registered_tools
local get_player_by_name = minetest.get_player_by_name
minetest.register_playerstep(function(_, playernames)
local now = floor((get_timeofday() * 24) % 12)
for _, name in pairs(playernames) do
local player = get_player_by_name(name)
if not player or not player:is_player() then return end
local inv = player:get_inventory()
for i, stack in pairs(inv:get_list("main")) do
local tools = registered_tools[stack:get_name()]
if tools and tools.groups.watch and tools.groups.watch ~= now then
inv:set_stack("main", i, "watch:" .. now)
end
end
end
end)