From 5467af4b176c135dcd3bcd89e1f7f72ab4199829 Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 20 Mar 2020 20:48:19 +0100 Subject: [PATCH 1/9] Add files via upload --- locale/bell.es.tr | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 locale/bell.es.tr diff --git a/locale/bell.es.tr b/locale/bell.es.tr new file mode 100644 index 0000000..1561f97 --- /dev/null +++ b/locale/bell.es.tr @@ -0,0 +1,2 @@ +Bell=Campana +Small bell=Campana pequeña From 10c81da25cff1e4667e47a76d3257f77175293a9 Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 20 Mar 2020 20:49:38 +0100 Subject: [PATCH 2/9] Update init.lua --- init.lua | 783 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 783 insertions(+) diff --git a/init.lua b/init.lua index 2859744..bb6aae0 100644 --- a/init.lua +++ b/init.lua @@ -30,6 +30,42 @@ end --------------------------------------------------------- --- Persistence +local save_bell_positions = function() + + local str = minetest.serialize( ({ bell_data = bell_positions}) ) + + local file, err = io.open( BELL_SAVE_FILE, "wb")local S = minetest.get_translator(minetest.get_current_modname()) + +-- bell_positions are saved through server restart +-- bells ring every hour +-- they ring as many times as a bell ought to + +local RING_INTERVAL = 3600 --60*60 -- ring each hour + +local BELL_SAVE_FILE = minetest.get_worldpath().."/bell_positions.data" + +local bell_positions = {} + +local ring_big_bell = function(pos) + minetest.sound_play( "bell_bell", + { pos = pos, gain = 1.5, max_hear_distance = 300,}) +end +-- actually ring the bell +local ring_bell_once = function() + for i,v in ipairs( bell_positions ) do + ring_big_bell(v) + end +end + +local ring_bell_multiple = function(rings) + for i=1, rings do + minetest.after( (i-1)*5, ring_bell_once ) + end +end + +--------------------------------------------------------- +--- Persistence + local save_bell_positions = function() local str = minetest.serialize( ({ bell_data = bell_positions}) ) @@ -205,6 +241,379 @@ local ring_small_bell = function(pos) end +local small_bell_base = { + description = S("Small bell"), + paramtype = "light", + stack_max = 1, + on_punch = function (pos,node,puncher) + ring_small_bell(pos) + end, + groups = {cracky=2}, +} + +if minetest.get_modpath("mesecons") then + small_bell_base.mesecons = { + effector = { + action_on = ring_small_bell, + } + } +end + +---------------------------------------------------- + +if minetest.settings:get_bool("bell_enable_model", true) then +---------------- +-- Model-type bell + local bell_def = { + drawtype = "mesh", + mesh = "bell_bell.obj", + tiles = { + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "default_wood.png", backface_culling = true }, -- + }, + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + paramtype2 = "facedir", + drop = { + max_items = 1, + items = { + { + items = {"bell:bell"}, + }, + } + } + } + + for k, v in pairs(bell_base) do + bell_def[k] = v + end + + minetest.register_node("bell:bell", bell_def) + + local small_bell_def = + { drawtype = "mesh", + mesh = "bell_small_bell.obj", + tiles = { + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "default_wood.png", backface_culling = true }, -- + }, + collision_box = { + type = "fixed", + fixed = { + {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, + }, + }, + paramtype2 = "facedir", + drop = { + max_items = 1, + items = { + { + items = {"bell:bell_small"}, + }, + } + } + } + + for k, v in pairs(small_bell_base) do + small_bell_def[k] = v + end + + minetest.register_node("bell:bell_small", small_bell_def) + +else +-------------------- +-- Plantlike-type bell + local bell_def = { + tiles = {"bell_bell.png"}, + inventory_image = 'bell_bell.png', + wield_image = 'bell_bell.png', + drawtype = "plantlike", + } + for k, v in pairs(bell_base) do + bell_def[k] = v + end + + minetest.register_node("bell:bell", bell_def) + + local small_bell_def = { + tiles = {"bell_bell.png"}, + inventory_image = 'bell_bell.png', + wield_image = 'bell_bell.png', + drawtype = "plantlike", + } + for k, v in pairs(small_bell_base) do + small_bell_def[k] = v + end + + minetest.register_node("bell:bell_small", small_bell_def) +end + +--------------------------------------------------------- +--- Recipes + +if minetest.get_modpath("default") then + minetest.register_craft({ + output = "bell:bell_small", + recipe = { + {"", "default:goldblock", "" }, + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "", "default:goldblock"}, + }, + }) + minetest.register_craft({ + output = "bell:bell", + recipe = { + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "", "default:goldblock"}, + }, + }) +end + +if minetest.get_modpath("mcl_core") then + minetest.register_craft({ + output = "bell:bell_small", + recipe = { + {"", "mcl_core:goldblock", "" }, + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "", "mcl_core:goldblock"}, + }, + }) + minetest.register_craft({ + output = "bell:bell", + recipe = { + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "", "mcl_core:goldblock"}, + }, + }) +end + + +----------- +--Loot mod support +----------- + +if minetest.get_modpath("mcl_loot") then + + mcl_loot.get_loot({ + stacks_min = 1, + stacks_max = 1, + items = { -- Table of possible loot items. This function selects between stacks_min and stacks_max of these. + { + itemstring = "bell:bell", -- Which item to select + amount_min = 1, -- Minimum size of itemstack. Must not be larger than 6553. Optional (default: 1) + amount_max = 10, -- Maximum size of item stack. Must not be larger than item definition's stack_max or 6553. Optional (default: 1) + wear_min = 1, -- Minimum wear value. Must be at least 1. Optional (default: no wear) + wear_max = 1, -- Maxiumum wear value. Must be at least 1. Optional (default: no wear) + weight = 5, -- Likelihood of this item being selected (see below). Optional (default: 1) + }, + } +}) + +end + + + + + + + + + + + + + if (err ~= nil) then + minetest.log("error", "[bell] Could not save bell data") + return + end + file:write( str ) + file:flush() + file:close() + --minetest.chat_send_all("Wrote data to savefile "..tostring( BELL_SAVE_FILE )) +end + +local restore_bell_data = function() + + local bell_position_table + + local file, err = io.open(BELL_SAVE_FILE, "rb") + if (err ~= nil) then + minetest.log("warning", "[bell] Could not open bell data savefile (ignore this message on first start)") + return + end + local str = file:read() + file:close() + + local bell_positions_table = minetest.deserialize( str ) + if( bell_positions_table and bell_positions_table.bell_data ) then + bell_positions = bell_positions_table.bell_data + minetest.log("action", "[bell] Read positions of bells from savefile.") + end +end + +--------------------------------------------------------- +--- Local time handling + +local rings_at_dawn = tonumber(minetest.settings:get("bell_tolls_at_dawn")) or 0 +local rings_at_noon = tonumber(minetest.settings:get("bell_tolls_at_noon")) or 0 +local rings_at_dusk = tonumber(minetest.settings:get("bell_tolls_at_dusk")) or 0 +local rings_at_midnight = tonumber(minetest.settings:get("bell_tolls_at_midnight")) or 0 + +local ring_at_dawn = rings_at_dawn > 0 +local ring_at_noon = rings_at_noon > 0 +local ring_at_dusk = rings_at_dusk > 0 +local ring_at_midnight = rings_at_midnight > 0 +local local_time = ring_at_dawn or ring_at_noon or ring_at_dusk or ring_at_midnight + +local last_timeofday = 0 +local dawn = 0.2 -- day and night in Minetest isn't exactly even +local noon = 0.5 +local dusk = 0.8 + +if local_time then + minetest.register_globalstep(function(dtime) + local timeofday = minetest.get_timeofday() + if ring_at_dawn and timeofday >= dawn and last_timeofday < dawn then + ring_bell_multiple(rings_at_dawn) + last_timeofday = timeofday + return + end + if ring_at_noon and timeofday >= noon and last_timeofday < noon then + ring_bell_multiple(rings_at_noon) + last_timeofday = timeofday + return + end + if ring_at_dusk and timeofday >= dusk and last_timeofday < dusk then + ring_bell_multiple(rings_at_dusk) + last_timeofday = timeofday + return + end + if ring_at_midnight and timeofday < last_timeofday then + -- day rolled over, it's midnight + ring_bell_multiple(rings_at_midnight) + last_timeofday = timeofday + return + end + last_timeofday = timeofday + end) +end + +--------------------------------------------------------- +--- Global time handling + +local global_time = minetest.settings:get_bool("bell_tolls_at_server_hours", true) + +local ring_bell +ring_bell = function() + if not global_time then + return + end + + -- figure out if this is the right time to ring + local sekunde = tonumber( os.date( "%S")) + local minute = tonumber( os.date( "%M")) + local stunde = tonumber( os.date( "%I")) -- in 12h-format (a bell that rings 24x at once would not survive long...) + local delay = RING_INTERVAL + + --print("[bells]It is now H:"..tostring( stunde ).." M:"..tostring(minute).." S:"..tostring( sekunde )) + + --local datum = os.date( "Stunde:%l Minute:%M Sekunde:%S") + --print('[bells] ringing bells at '..tostring( datum )) + + delay = RING_INTERVAL - sekunde - (minute*60) + + -- make sure the bell rings the next hour + minetest.after( delay, ring_bell ) + + -- if no bells are around then don't ring + if( bell_positions == nil or #bell_positions < 1 ) then + return + end + + if( sekunde > 10 ) then +-- print("[bells] Too late. Waiting for "..tostring( delay ).." seconds.") + return + end + + -- ring the bell for each hour once + ring_bell_multiple(stunde) +end + +-- first call (after the server has been started) +minetest.after( 10, ring_bell ) +-- read data about bell positions +restore_bell_data() + +--------------------------------------------------------- +--- Node definitions + +local bell_base = { + paramtype = "light", + description = S("Bell"), + stack_max = 1, + + on_punch = function (pos,node,puncher) + ring_big_bell(pos) + end, + + on_construct = function(pos) + -- remember that there is a bell at that position + table.insert( bell_positions, pos ) + save_bell_positions() + end, + + on_destruct = function(pos) + local found = 0 + -- actually remove the bell from the list + for i,v in ipairs( bell_positions ) do + if(v ~= nil and vector.equals(v, pos)) then + table.remove( bell_positions, i) + save_bell_positions() + break + end + end + end, + + groups = {cracky=2}, +} + +if minetest.get_modpath("mesecons") then + bell_base.mesecons = { + effector = { + action_on = ring_big_bell, + } + } +end + + +local ring_small_bell = function(pos) + minetest.sound_play( "bell_small", + { pos = pos, gain = 1.5, max_hear_distance = 60,}) +end + + local small_bell_base = { description = S("Small bell"), paramtype = "light", @@ -337,3 +746,377 @@ if minetest.get_modpath("default") then }, }) end +local S = minetest.get_translator(minetest.get_current_modname()) + +-- bell_positions are saved through server restart +-- bells ring every hour +-- they ring as many times as a bell ought to + +local RING_INTERVAL = 3600 --60*60 -- ring each hour + +local BELL_SAVE_FILE = minetest.get_worldpath().."/bell_positions.data" + +local bell_positions = {} + +local ring_big_bell = function(pos) + minetest.sound_play( "bell_bell", + { pos = pos, gain = 1.5, max_hear_distance = 300,}) +end +-- actually ring the bell +local ring_bell_once = function() + for i,v in ipairs( bell_positions ) do + ring_big_bell(v) + end +end + +local ring_bell_multiple = function(rings) + for i=1, rings do + minetest.after( (i-1)*5, ring_bell_once ) + end +end + +--------------------------------------------------------- +--- Persistence + +local save_bell_positions = function() + + local str = minetest.serialize( ({ bell_data = bell_positions}) ) + + local file, err = io.open( BELL_SAVE_FILE, "wb") + if (err ~= nil) then + minetest.log("error", "[bell] Could not save bell data") + return + end + file:write( str ) + file:flush() + file:close() + --minetest.chat_send_all("Wrote data to savefile "..tostring( BELL_SAVE_FILE )) +end + +local restore_bell_data = function() + + local bell_position_table + + local file, err = io.open(BELL_SAVE_FILE, "rb") + if (err ~= nil) then + minetest.log("warning", "[bell] Could not open bell data savefile (ignore this message on first start)") + return + end + local str = file:read() + file:close() + + local bell_positions_table = minetest.deserialize( str ) + if( bell_positions_table and bell_positions_table.bell_data ) then + bell_positions = bell_positions_table.bell_data + minetest.log("action", "[bell] Read positions of bells from savefile.") + end +end + +--------------------------------------------------------- +--- Local time handling + +local rings_at_dawn = tonumber(minetest.settings:get("bell_tolls_at_dawn")) or 0 +local rings_at_noon = tonumber(minetest.settings:get("bell_tolls_at_noon")) or 0 +local rings_at_dusk = tonumber(minetest.settings:get("bell_tolls_at_dusk")) or 0 +local rings_at_midnight = tonumber(minetest.settings:get("bell_tolls_at_midnight")) or 0 + +local ring_at_dawn = rings_at_dawn > 0 +local ring_at_noon = rings_at_noon > 0 +local ring_at_dusk = rings_at_dusk > 0 +local ring_at_midnight = rings_at_midnight > 0 +local local_time = ring_at_dawn or ring_at_noon or ring_at_dusk or ring_at_midnight + +local last_timeofday = 0 +local dawn = 0.2 -- day and night in Minetest isn't exactly even +local noon = 0.5 +local dusk = 0.8 + +if local_time then + minetest.register_globalstep(function(dtime) + local timeofday = minetest.get_timeofday() + if ring_at_dawn and timeofday >= dawn and last_timeofday < dawn then + ring_bell_multiple(rings_at_dawn) + last_timeofday = timeofday + return + end + if ring_at_noon and timeofday >= noon and last_timeofday < noon then + ring_bell_multiple(rings_at_noon) + last_timeofday = timeofday + return + end + if ring_at_dusk and timeofday >= dusk and last_timeofday < dusk then + ring_bell_multiple(rings_at_dusk) + last_timeofday = timeofday + return + end + if ring_at_midnight and timeofday < last_timeofday then + -- day rolled over, it's midnight + ring_bell_multiple(rings_at_midnight) + last_timeofday = timeofday + return + end + last_timeofday = timeofday + end) +end + +--------------------------------------------------------- +--- Global time handling + +local global_time = minetest.settings:get_bool("bell_tolls_at_server_hours", true) + +local ring_bell +ring_bell = function() + if not global_time then + return + end + + -- figure out if this is the right time to ring + local sekunde = tonumber( os.date( "%S")) + local minute = tonumber( os.date( "%M")) + local stunde = tonumber( os.date( "%I")) -- in 12h-format (a bell that rings 24x at once would not survive long...) + local delay = RING_INTERVAL + + --print("[bells]It is now H:"..tostring( stunde ).." M:"..tostring(minute).." S:"..tostring( sekunde )) + + --local datum = os.date( "Stunde:%l Minute:%M Sekunde:%S") + --print('[bells] ringing bells at '..tostring( datum )) + + delay = RING_INTERVAL - sekunde - (minute*60) + + -- make sure the bell rings the next hour + minetest.after( delay, ring_bell ) + + -- if no bells are around then don't ring + if( bell_positions == nil or #bell_positions < 1 ) then + return + end + + if( sekunde > 10 ) then +-- print("[bells] Too late. Waiting for "..tostring( delay ).." seconds.") + return + end + + -- ring the bell for each hour once + ring_bell_multiple(stunde) +end + +-- first call (after the server has been started) +minetest.after( 10, ring_bell ) +-- read data about bell positions +restore_bell_data() + +--------------------------------------------------------- +--- Node definitions + +local bell_base = { + paramtype = "light", + description = S("Bell"), + stack_max = 1, + + on_punch = function (pos,node,puncher) + ring_big_bell(pos) + end, + + on_construct = function(pos) + -- remember that there is a bell at that position + table.insert( bell_positions, pos ) + save_bell_positions() + end, + + on_destruct = function(pos) + local found = 0 + -- actually remove the bell from the list + for i,v in ipairs( bell_positions ) do + if(v ~= nil and vector.equals(v, pos)) then + table.remove( bell_positions, i) + save_bell_positions() + break + end + end + end, + + groups = {cracky=2}, +} + +if minetest.get_modpath("mesecons") then + bell_base.mesecons = { + effector = { + action_on = ring_big_bell, + } + } +end + + +local ring_small_bell = function(pos) + minetest.sound_play( "bell_small", + { pos = pos, gain = 1.5, max_hear_distance = 60,}) +end + + +local small_bell_base = { + description = S("Small bell"), + paramtype = "light", + stack_max = 1, + on_punch = function (pos,node,puncher) + ring_small_bell(pos) + end, + groups = {cracky=2}, +} + +if minetest.get_modpath("mesecons") then + small_bell_base.mesecons = { + effector = { + action_on = ring_small_bell, + } + } +end + +---------------------------------------------------- + +if minetest.settings:get_bool("bell_enable_model", true) then +---------------- +-- Model-type bell + local bell_def = { + drawtype = "mesh", + mesh = "bell_bell.obj", + tiles = { + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "default_wood.png", backface_culling = true }, -- + }, + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + paramtype2 = "facedir", + drop = { + max_items = 1, + items = { + { + items = {"bell:bell"}, + }, + } + } + } + + for k, v in pairs(bell_base) do + bell_def[k] = v + end + + minetest.register_node("bell:bell", bell_def) + + local small_bell_def = + { drawtype = "mesh", + mesh = "bell_small_bell.obj", + tiles = { + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "default_wood.png", backface_culling = true }, -- + }, + collision_box = { + type = "fixed", + fixed = { + {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, + }, + }, + paramtype2 = "facedir", + drop = { + max_items = 1, + items = { + { + items = {"bell:bell_small"}, + }, + } + } + } + + for k, v in pairs(small_bell_base) do + small_bell_def[k] = v + end + + minetest.register_node("bell:bell_small", small_bell_def) + +else +-------------------- +-- Plantlike-type bell + local bell_def = { + tiles = {"bell_bell.png"}, + inventory_image = 'bell_bell.png', + wield_image = 'bell_bell.png', + drawtype = "plantlike", + } + for k, v in pairs(bell_base) do + bell_def[k] = v + end + + minetest.register_node("bell:bell", bell_def) + + local small_bell_def = { + tiles = {"bell_bell.png"}, + inventory_image = 'bell_bell.png', + wield_image = 'bell_bell.png', + drawtype = "plantlike", + } + for k, v in pairs(small_bell_base) do + small_bell_def[k] = v + end + + minetest.register_node("bell:bell_small", small_bell_def) +end + +--------------------------------------------------------- +--- Recipes + +if minetest.get_modpath("default") then + minetest.register_craft({ + output = "bell:bell_small", + recipe = { + {"", "default:goldblock", "" }, + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "", "default:goldblock"}, + }, + }) + minetest.register_craft({ + output = "bell:bell", + recipe = { + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "", "default:goldblock"}, + }, + }) +end + +if minetest.get_modpath("mcl_core") then + minetest.register_craft({ + output = "bell:bell_small", + recipe = { + {"", "mcl_core:goldblock", "" }, + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "", "mcl_core:goldblock"}, + }, + }) + minetest.register_craft({ + output = "bell:bell", + recipe = { + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "", "mcl_core:goldblock"}, + }, + }) +end From 589322b43e3837f58d17e940d7f9ef799cada0d7 Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 20 Mar 2020 20:50:05 +0100 Subject: [PATCH 3/9] Add files via upload --- depends.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 depends.txt diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..30bdd12 --- /dev/null +++ b/depends.txt @@ -0,0 +1,4 @@ +default? +mcl_core? +mcl_loot? +doc? From 67ca901f23e593449f25089faec5a380471e1d5d Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 20 Mar 2020 20:58:15 +0100 Subject: [PATCH 4/9] Update init.lua --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index bb6aae0..34c3a2d 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,4 @@ -S = minetest.get_translator("bell") +local S = minetest.get_translator(minetest.get_current_modname()) -- bell_positions are saved through server restart -- bells ring every hour From 28a11b1976627d30d898b45b0fddc5c5c8a8969d Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Sat, 21 Mar 2020 01:51:31 +0100 Subject: [PATCH 5/9] Update init.lua --- init.lua | 387 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 386 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 34c3a2d..82517a9 100644 --- a/init.lua +++ b/init.lua @@ -34,7 +34,392 @@ local save_bell_positions = function() local str = minetest.serialize( ({ bell_data = bell_positions}) ) - local file, err = io.open( BELL_SAVE_FILE, "wb")local S = minetest.get_translator(minetest.get_current_modname()) + local file, err = io.open( BELL_SAVE_FILE, "wb")local S = minetest.get_translator(minetest.get_current_modname())local S = minetest.get_translator(minetest.get_current_modname()) + +-- bell_positions are saved through server restart +-- bells ring every hour +-- they ring as many times as a bell ought to + +local RING_INTERVAL = 3600 --60*60 -- ring each hour + +local BELL_SAVE_FILE = minetest.get_worldpath().."/bell_positions.data" + +local bell_positions = {} + +local ring_big_bell = function(pos) + minetest.sound_play( "bell_bell", + { pos = pos, gain = 1.5, max_hear_distance = 300,}) +end +-- actually ring the bell +local ring_bell_once = function() + for i,v in ipairs( bell_positions ) do + ring_big_bell(v) + end +end + +local ring_bell_multiple = function(rings) + for i=1, rings do + minetest.after( (i-1)*5, ring_bell_once ) + end +end + +--------------------------------------------------------- +--- Persistence + +local save_bell_positions = function() + + local str = minetest.serialize( ({ bell_data = bell_positions}) ) + + local file, err = io.open( BELL_SAVE_FILE, "wb") + if (err ~= nil) then + minetest.log("error", "[bell] Could not save bell data") + return + end + file:write( str ) + file:flush() + file:close() + --minetest.chat_send_all("Wrote data to savefile "..tostring( BELL_SAVE_FILE )) +end + +local restore_bell_data = function() + + local bell_position_table + + local file, err = io.open(BELL_SAVE_FILE, "rb") + if (err ~= nil) then + minetest.log("warning", "[bell] Could not open bell data savefile (ignore this message on first start)") + return + end + local str = file:read() + file:close() + + local bell_positions_table = minetest.deserialize( str ) + if( bell_positions_table and bell_positions_table.bell_data ) then + bell_positions = bell_positions_table.bell_data + minetest.log("action", "[bell] Read positions of bells from savefile.") + end +end + +--------------------------------------------------------- +--- Local time handling + +local rings_at_dawn = tonumber(minetest.settings:get("bell_tolls_at_dawn")) or 0 +local rings_at_noon = tonumber(minetest.settings:get("bell_tolls_at_noon")) or 0 +local rings_at_dusk = tonumber(minetest.settings:get("bell_tolls_at_dusk")) or 0 +local rings_at_midnight = tonumber(minetest.settings:get("bell_tolls_at_midnight")) or 0 + +local ring_at_dawn = rings_at_dawn > 0 +local ring_at_noon = rings_at_noon > 0 +local ring_at_dusk = rings_at_dusk > 0 +local ring_at_midnight = rings_at_midnight > 0 +local local_time = ring_at_dawn or ring_at_noon or ring_at_dusk or ring_at_midnight + +local last_timeofday = 0 +local dawn = 0.2 -- day and night in Minetest isn't exactly even +local noon = 0.5 +local dusk = 0.8 + +if local_time then + minetest.register_globalstep(function(dtime) + local timeofday = minetest.get_timeofday() + if ring_at_dawn and timeofday >= dawn and last_timeofday < dawn then + ring_bell_multiple(rings_at_dawn) + last_timeofday = timeofday + return + end + if ring_at_noon and timeofday >= noon and last_timeofday < noon then + ring_bell_multiple(rings_at_noon) + last_timeofday = timeofday + return + end + if ring_at_dusk and timeofday >= dusk and last_timeofday < dusk then + ring_bell_multiple(rings_at_dusk) + last_timeofday = timeofday + return + end + if ring_at_midnight and timeofday < last_timeofday then + -- day rolled over, it's midnight + ring_bell_multiple(rings_at_midnight) + last_timeofday = timeofday + return + end + last_timeofday = timeofday + end) +end + +--------------------------------------------------------- +--- Global time handling + +local global_time = minetest.settings:get_bool("bell_tolls_at_server_hours", true) + +local ring_bell +ring_bell = function() + if not global_time then + return + end + + -- figure out if this is the right time to ring + local sekunde = tonumber( os.date( "%S")) + local minute = tonumber( os.date( "%M")) + local stunde = tonumber( os.date( "%I")) -- in 12h-format (a bell that rings 24x at once would not survive long...) + local delay = RING_INTERVAL + + --print("[bells]It is now H:"..tostring( stunde ).." M:"..tostring(minute).." S:"..tostring( sekunde )) + + --local datum = os.date( "Stunde:%l Minute:%M Sekunde:%S") + --print('[bells] ringing bells at '..tostring( datum )) + + delay = RING_INTERVAL - sekunde - (minute*60) + + -- make sure the bell rings the next hour + minetest.after( delay, ring_bell ) + + -- if no bells are around then don't ring + if( bell_positions == nil or #bell_positions < 1 ) then + return + end + + if( sekunde > 10 ) then +-- print("[bells] Too late. Waiting for "..tostring( delay ).." seconds.") + return + end + + -- ring the bell for each hour once + ring_bell_multiple(stunde) +end + +-- first call (after the server has been started) +minetest.after( 10, ring_bell ) +-- read data about bell positions +restore_bell_data() + +--------------------------------------------------------- +--- Node definitions + +local bell_base = { + paramtype = "light", + description = S("Bell"), + stack_max = 1, + + on_punch = function (pos,node,puncher) + ring_big_bell(pos) + end, + + on_construct = function(pos) + -- remember that there is a bell at that position + table.insert( bell_positions, pos ) + save_bell_positions() + end, + + on_destruct = function(pos) + local found = 0 + -- actually remove the bell from the list + for i,v in ipairs( bell_positions ) do + if(v ~= nil and vector.equals(v, pos)) then + table.remove( bell_positions, i) + save_bell_positions() + break + end + end + end, + + groups = {cracky=2}, +} + +if minetest.get_modpath("mesecons") then + bell_base.mesecons = { + effector = { + action_on = ring_big_bell, + } + } +end + + +local ring_small_bell = function(pos) + minetest.sound_play( "bell_small", + { pos = pos, gain = 1.5, max_hear_distance = 60,}) +end + + +local small_bell_base = { + description = S("Small bell"), + paramtype = "light", + stack_max = 1, + on_punch = function (pos,node,puncher) + ring_small_bell(pos) + end, + groups = {cracky=2}, +} + +if minetest.get_modpath("mesecons") then + small_bell_base.mesecons = { + effector = { + action_on = ring_small_bell, + } + } +end + +---------------------------------------------------- + +if minetest.settings:get_bool("bell_enable_model", true) then +---------------- +-- Model-type bell + local bell_def = { + drawtype = "mesh", + mesh = "bell_bell.obj", + tiles = { + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "default_wood.png", backface_culling = true }, -- + }, + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + paramtype2 = "facedir", + drop = { + max_items = 1, + items = { + { + items = {"bell:bell"}, + }, + } + } + } + + for k, v in pairs(bell_base) do + bell_def[k] = v + end + + minetest.register_node("bell:bell", bell_def) + + local small_bell_def = + { drawtype = "mesh", + mesh = "bell_small_bell.obj", + tiles = { + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "bell_hull.png", backface_culling = true }, -- + { name = "default_wood.png", backface_culling = true }, -- + }, + collision_box = { + type = "fixed", + fixed = { + {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, + }, + }, + paramtype2 = "facedir", + drop = { + max_items = 1, + items = { + { + items = {"bell:bell_small"}, + }, + } + } + } + + for k, v in pairs(small_bell_base) do + small_bell_def[k] = v + end + + minetest.register_node("bell:bell_small", small_bell_def) + +else +-------------------- +-- Plantlike-type bell + local bell_def = { + tiles = {"bell_bell.png"}, + inventory_image = 'bell_bell.png', + wield_image = 'bell_bell.png', + drawtype = "plantlike", + } + for k, v in pairs(bell_base) do + bell_def[k] = v + end + + minetest.register_node("bell:bell", bell_def) + + local small_bell_def = { + tiles = {"bell_bell.png"}, + inventory_image = 'bell_bell.png', + wield_image = 'bell_bell.png', + drawtype = "plantlike", + } + for k, v in pairs(small_bell_base) do + small_bell_def[k] = v + end + + minetest.register_node("bell:bell_small", small_bell_def) +end + +--------------------------------------------------------- +--- Recipes + +if minetest.get_modpath("default") then + minetest.register_craft({ + output = "bell:bell_small", + recipe = { + {"", "default:goldblock", "" }, + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "", "default:goldblock"}, + }, + }) + minetest.register_craft({ + output = "bell:bell", + recipe = { + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "default:goldblock", "default:goldblock"}, + {"default:goldblock", "", "default:goldblock"}, + }, + }) +end + +if minetest.get_modpath("mcl_core") then + minetest.register_craft({ + output = "bell:bell_small", + recipe = { + {"", "mcl_core:goldblock", "" }, + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "", "mcl_core:goldblock"}, + }, + }) + minetest.register_craft({ + output = "bell:bell", + recipe = { + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, + {"mcl_core:goldblock", "", "mcl_core:goldblock"}, + }, + }) +end + + + + + + + + + + + + -- bell_positions are saved through server restart -- bells ring every hour From e3aa67eb46e9dff724c542acb78d88ad2a316693 Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Sat, 21 Mar 2020 02:32:05 +0100 Subject: [PATCH 6/9] Update init.lua --- init.lua | 1133 ------------------------------------------------------ 1 file changed, 1133 deletions(-) diff --git a/init.lua b/init.lua index 82517a9..6903120 100644 --- a/init.lua +++ b/init.lua @@ -30,1139 +30,6 @@ end --------------------------------------------------------- --- Persistence -local save_bell_positions = function() - - local str = minetest.serialize( ({ bell_data = bell_positions}) ) - - local file, err = io.open( BELL_SAVE_FILE, "wb")local S = minetest.get_translator(minetest.get_current_modname())local S = minetest.get_translator(minetest.get_current_modname()) - --- bell_positions are saved through server restart --- bells ring every hour --- they ring as many times as a bell ought to - -local RING_INTERVAL = 3600 --60*60 -- ring each hour - -local BELL_SAVE_FILE = minetest.get_worldpath().."/bell_positions.data" - -local bell_positions = {} - -local ring_big_bell = function(pos) - minetest.sound_play( "bell_bell", - { pos = pos, gain = 1.5, max_hear_distance = 300,}) -end --- actually ring the bell -local ring_bell_once = function() - for i,v in ipairs( bell_positions ) do - ring_big_bell(v) - end -end - -local ring_bell_multiple = function(rings) - for i=1, rings do - minetest.after( (i-1)*5, ring_bell_once ) - end -end - ---------------------------------------------------------- ---- Persistence - -local save_bell_positions = function() - - local str = minetest.serialize( ({ bell_data = bell_positions}) ) - - local file, err = io.open( BELL_SAVE_FILE, "wb") - if (err ~= nil) then - minetest.log("error", "[bell] Could not save bell data") - return - end - file:write( str ) - file:flush() - file:close() - --minetest.chat_send_all("Wrote data to savefile "..tostring( BELL_SAVE_FILE )) -end - -local restore_bell_data = function() - - local bell_position_table - - local file, err = io.open(BELL_SAVE_FILE, "rb") - if (err ~= nil) then - minetest.log("warning", "[bell] Could not open bell data savefile (ignore this message on first start)") - return - end - local str = file:read() - file:close() - - local bell_positions_table = minetest.deserialize( str ) - if( bell_positions_table and bell_positions_table.bell_data ) then - bell_positions = bell_positions_table.bell_data - minetest.log("action", "[bell] Read positions of bells from savefile.") - end -end - ---------------------------------------------------------- ---- Local time handling - -local rings_at_dawn = tonumber(minetest.settings:get("bell_tolls_at_dawn")) or 0 -local rings_at_noon = tonumber(minetest.settings:get("bell_tolls_at_noon")) or 0 -local rings_at_dusk = tonumber(minetest.settings:get("bell_tolls_at_dusk")) or 0 -local rings_at_midnight = tonumber(minetest.settings:get("bell_tolls_at_midnight")) or 0 - -local ring_at_dawn = rings_at_dawn > 0 -local ring_at_noon = rings_at_noon > 0 -local ring_at_dusk = rings_at_dusk > 0 -local ring_at_midnight = rings_at_midnight > 0 -local local_time = ring_at_dawn or ring_at_noon or ring_at_dusk or ring_at_midnight - -local last_timeofday = 0 -local dawn = 0.2 -- day and night in Minetest isn't exactly even -local noon = 0.5 -local dusk = 0.8 - -if local_time then - minetest.register_globalstep(function(dtime) - local timeofday = minetest.get_timeofday() - if ring_at_dawn and timeofday >= dawn and last_timeofday < dawn then - ring_bell_multiple(rings_at_dawn) - last_timeofday = timeofday - return - end - if ring_at_noon and timeofday >= noon and last_timeofday < noon then - ring_bell_multiple(rings_at_noon) - last_timeofday = timeofday - return - end - if ring_at_dusk and timeofday >= dusk and last_timeofday < dusk then - ring_bell_multiple(rings_at_dusk) - last_timeofday = timeofday - return - end - if ring_at_midnight and timeofday < last_timeofday then - -- day rolled over, it's midnight - ring_bell_multiple(rings_at_midnight) - last_timeofday = timeofday - return - end - last_timeofday = timeofday - end) -end - ---------------------------------------------------------- ---- Global time handling - -local global_time = minetest.settings:get_bool("bell_tolls_at_server_hours", true) - -local ring_bell -ring_bell = function() - if not global_time then - return - end - - -- figure out if this is the right time to ring - local sekunde = tonumber( os.date( "%S")) - local minute = tonumber( os.date( "%M")) - local stunde = tonumber( os.date( "%I")) -- in 12h-format (a bell that rings 24x at once would not survive long...) - local delay = RING_INTERVAL - - --print("[bells]It is now H:"..tostring( stunde ).." M:"..tostring(minute).." S:"..tostring( sekunde )) - - --local datum = os.date( "Stunde:%l Minute:%M Sekunde:%S") - --print('[bells] ringing bells at '..tostring( datum )) - - delay = RING_INTERVAL - sekunde - (minute*60) - - -- make sure the bell rings the next hour - minetest.after( delay, ring_bell ) - - -- if no bells are around then don't ring - if( bell_positions == nil or #bell_positions < 1 ) then - return - end - - if( sekunde > 10 ) then --- print("[bells] Too late. Waiting for "..tostring( delay ).." seconds.") - return - end - - -- ring the bell for each hour once - ring_bell_multiple(stunde) -end - --- first call (after the server has been started) -minetest.after( 10, ring_bell ) --- read data about bell positions -restore_bell_data() - ---------------------------------------------------------- ---- Node definitions - -local bell_base = { - paramtype = "light", - description = S("Bell"), - stack_max = 1, - - on_punch = function (pos,node,puncher) - ring_big_bell(pos) - end, - - on_construct = function(pos) - -- remember that there is a bell at that position - table.insert( bell_positions, pos ) - save_bell_positions() - end, - - on_destruct = function(pos) - local found = 0 - -- actually remove the bell from the list - for i,v in ipairs( bell_positions ) do - if(v ~= nil and vector.equals(v, pos)) then - table.remove( bell_positions, i) - save_bell_positions() - break - end - end - end, - - groups = {cracky=2}, -} - -if minetest.get_modpath("mesecons") then - bell_base.mesecons = { - effector = { - action_on = ring_big_bell, - } - } -end - - -local ring_small_bell = function(pos) - minetest.sound_play( "bell_small", - { pos = pos, gain = 1.5, max_hear_distance = 60,}) -end - - -local small_bell_base = { - description = S("Small bell"), - paramtype = "light", - stack_max = 1, - on_punch = function (pos,node,puncher) - ring_small_bell(pos) - end, - groups = {cracky=2}, -} - -if minetest.get_modpath("mesecons") then - small_bell_base.mesecons = { - effector = { - action_on = ring_small_bell, - } - } -end - ----------------------------------------------------- - -if minetest.settings:get_bool("bell_enable_model", true) then ----------------- --- Model-type bell - local bell_def = { - drawtype = "mesh", - mesh = "bell_bell.obj", - tiles = { - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "default_wood.png", backface_culling = true }, -- - }, - collision_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - }, - paramtype2 = "facedir", - drop = { - max_items = 1, - items = { - { - items = {"bell:bell"}, - }, - } - } - } - - for k, v in pairs(bell_base) do - bell_def[k] = v - end - - minetest.register_node("bell:bell", bell_def) - - local small_bell_def = - { drawtype = "mesh", - mesh = "bell_small_bell.obj", - tiles = { - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "default_wood.png", backface_culling = true }, -- - }, - collision_box = { - type = "fixed", - fixed = { - {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, - }, - }, - paramtype2 = "facedir", - drop = { - max_items = 1, - items = { - { - items = {"bell:bell_small"}, - }, - } - } - } - - for k, v in pairs(small_bell_base) do - small_bell_def[k] = v - end - - minetest.register_node("bell:bell_small", small_bell_def) - -else --------------------- --- Plantlike-type bell - local bell_def = { - tiles = {"bell_bell.png"}, - inventory_image = 'bell_bell.png', - wield_image = 'bell_bell.png', - drawtype = "plantlike", - } - for k, v in pairs(bell_base) do - bell_def[k] = v - end - - minetest.register_node("bell:bell", bell_def) - - local small_bell_def = { - tiles = {"bell_bell.png"}, - inventory_image = 'bell_bell.png', - wield_image = 'bell_bell.png', - drawtype = "plantlike", - } - for k, v in pairs(small_bell_base) do - small_bell_def[k] = v - end - - minetest.register_node("bell:bell_small", small_bell_def) -end - ---------------------------------------------------------- ---- Recipes - -if minetest.get_modpath("default") then - minetest.register_craft({ - output = "bell:bell_small", - recipe = { - {"", "default:goldblock", "" }, - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "", "default:goldblock"}, - }, - }) - minetest.register_craft({ - output = "bell:bell", - recipe = { - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "", "default:goldblock"}, - }, - }) -end - -if minetest.get_modpath("mcl_core") then - minetest.register_craft({ - output = "bell:bell_small", - recipe = { - {"", "mcl_core:goldblock", "" }, - {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, - {"mcl_core:goldblock", "", "mcl_core:goldblock"}, - }, - }) - minetest.register_craft({ - output = "bell:bell", - recipe = { - {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, - {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, - {"mcl_core:goldblock", "", "mcl_core:goldblock"}, - }, - }) -end - - - - - - - - - - - - - --- bell_positions are saved through server restart --- bells ring every hour --- they ring as many times as a bell ought to - -local RING_INTERVAL = 3600 --60*60 -- ring each hour - -local BELL_SAVE_FILE = minetest.get_worldpath().."/bell_positions.data" - -local bell_positions = {} - -local ring_big_bell = function(pos) - minetest.sound_play( "bell_bell", - { pos = pos, gain = 1.5, max_hear_distance = 300,}) -end --- actually ring the bell -local ring_bell_once = function() - for i,v in ipairs( bell_positions ) do - ring_big_bell(v) - end -end - -local ring_bell_multiple = function(rings) - for i=1, rings do - minetest.after( (i-1)*5, ring_bell_once ) - end -end - ---------------------------------------------------------- ---- Persistence - -local save_bell_positions = function() - - local str = minetest.serialize( ({ bell_data = bell_positions}) ) - - local file, err = io.open( BELL_SAVE_FILE, "wb") - if (err ~= nil) then - minetest.log("error", "[bell] Could not save bell data") - return - end - file:write( str ) - file:flush() - file:close() - --minetest.chat_send_all("Wrote data to savefile "..tostring( BELL_SAVE_FILE )) -end - -local restore_bell_data = function() - - local bell_position_table - - local file, err = io.open(BELL_SAVE_FILE, "rb") - if (err ~= nil) then - minetest.log("warning", "[bell] Could not open bell data savefile (ignore this message on first start)") - return - end - local str = file:read() - file:close() - - local bell_positions_table = minetest.deserialize( str ) - if( bell_positions_table and bell_positions_table.bell_data ) then - bell_positions = bell_positions_table.bell_data - minetest.log("action", "[bell] Read positions of bells from savefile.") - end -end - ---------------------------------------------------------- ---- Local time handling - -local rings_at_dawn = tonumber(minetest.settings:get("bell_tolls_at_dawn")) or 0 -local rings_at_noon = tonumber(minetest.settings:get("bell_tolls_at_noon")) or 0 -local rings_at_dusk = tonumber(minetest.settings:get("bell_tolls_at_dusk")) or 0 -local rings_at_midnight = tonumber(minetest.settings:get("bell_tolls_at_midnight")) or 0 - -local ring_at_dawn = rings_at_dawn > 0 -local ring_at_noon = rings_at_noon > 0 -local ring_at_dusk = rings_at_dusk > 0 -local ring_at_midnight = rings_at_midnight > 0 -local local_time = ring_at_dawn or ring_at_noon or ring_at_dusk or ring_at_midnight - -local last_timeofday = 0 -local dawn = 0.2 -- day and night in Minetest isn't exactly even -local noon = 0.5 -local dusk = 0.8 - -if local_time then - minetest.register_globalstep(function(dtime) - local timeofday = minetest.get_timeofday() - if ring_at_dawn and timeofday >= dawn and last_timeofday < dawn then - ring_bell_multiple(rings_at_dawn) - last_timeofday = timeofday - return - end - if ring_at_noon and timeofday >= noon and last_timeofday < noon then - ring_bell_multiple(rings_at_noon) - last_timeofday = timeofday - return - end - if ring_at_dusk and timeofday >= dusk and last_timeofday < dusk then - ring_bell_multiple(rings_at_dusk) - last_timeofday = timeofday - return - end - if ring_at_midnight and timeofday < last_timeofday then - -- day rolled over, it's midnight - ring_bell_multiple(rings_at_midnight) - last_timeofday = timeofday - return - end - last_timeofday = timeofday - end) -end - ---------------------------------------------------------- ---- Global time handling - -local global_time = minetest.settings:get_bool("bell_tolls_at_server_hours", true) - -local ring_bell -ring_bell = function() - if not global_time then - return - end - - -- figure out if this is the right time to ring - local sekunde = tonumber( os.date( "%S")) - local minute = tonumber( os.date( "%M")) - local stunde = tonumber( os.date( "%I")) -- in 12h-format (a bell that rings 24x at once would not survive long...) - local delay = RING_INTERVAL - - --print("[bells]It is now H:"..tostring( stunde ).." M:"..tostring(minute).." S:"..tostring( sekunde )) - - --local datum = os.date( "Stunde:%l Minute:%M Sekunde:%S") - --print('[bells] ringing bells at '..tostring( datum )) - - delay = RING_INTERVAL - sekunde - (minute*60) - - -- make sure the bell rings the next hour - minetest.after( delay, ring_bell ) - - -- if no bells are around then don't ring - if( bell_positions == nil or #bell_positions < 1 ) then - return - end - - if( sekunde > 10 ) then --- print("[bells] Too late. Waiting for "..tostring( delay ).." seconds.") - return - end - - -- ring the bell for each hour once - ring_bell_multiple(stunde) -end - --- first call (after the server has been started) -minetest.after( 10, ring_bell ) --- read data about bell positions -restore_bell_data() - ---------------------------------------------------------- ---- Node definitions - -local bell_base = { - paramtype = "light", - description = S("Bell"), - stack_max = 1, - - on_punch = function (pos,node,puncher) - ring_big_bell(pos) - end, - - on_construct = function(pos) - -- remember that there is a bell at that position - table.insert( bell_positions, pos ) - save_bell_positions() - end, - - on_destruct = function(pos) - local found = 0 - -- actually remove the bell from the list - for i,v in ipairs( bell_positions ) do - if(v ~= nil and vector.equals(v, pos)) then - table.remove( bell_positions, i) - save_bell_positions() - break - end - end - end, - - groups = {cracky=2}, -} - -if minetest.get_modpath("mesecons") then - bell_base.mesecons = { - effector = { - action_on = ring_big_bell, - } - } -end - - -local ring_small_bell = function(pos) - minetest.sound_play( "bell_small", - { pos = pos, gain = 1.5, max_hear_distance = 60,}) -end - - -local small_bell_base = { - description = S("Small bell"), - paramtype = "light", - stack_max = 1, - on_punch = function (pos,node,puncher) - ring_small_bell(pos) - end, - groups = {cracky=2}, -} - -if minetest.get_modpath("mesecons") then - small_bell_base.mesecons = { - effector = { - action_on = ring_small_bell, - } - } -end - ----------------------------------------------------- - -if minetest.settings:get_bool("bell_enable_model", true) then ----------------- --- Model-type bell - local bell_def = { - drawtype = "mesh", - mesh = "bell_bell.obj", - tiles = { - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "default_wood.png", backface_culling = true }, -- - }, - collision_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - }, - paramtype2 = "facedir", - drop = { - max_items = 1, - items = { - { - items = {"bell:bell"}, - }, - } - } - } - - for k, v in pairs(bell_base) do - bell_def[k] = v - end - - minetest.register_node("bell:bell", bell_def) - - local small_bell_def = - { drawtype = "mesh", - mesh = "bell_small_bell.obj", - tiles = { - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "default_wood.png", backface_culling = true }, -- - }, - collision_box = { - type = "fixed", - fixed = { - {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, - }, - }, - paramtype2 = "facedir", - drop = { - max_items = 1, - items = { - { - items = {"bell:bell_small"}, - }, - } - } - } - - for k, v in pairs(small_bell_base) do - small_bell_def[k] = v - end - - minetest.register_node("bell:bell_small", small_bell_def) - -else --------------------- --- Plantlike-type bell - local bell_def = { - tiles = {"bell_bell.png"}, - inventory_image = 'bell_bell.png', - wield_image = 'bell_bell.png', - drawtype = "plantlike", - } - for k, v in pairs(bell_base) do - bell_def[k] = v - end - - minetest.register_node("bell:bell", bell_def) - - local small_bell_def = { - tiles = {"bell_bell.png"}, - inventory_image = 'bell_bell.png', - wield_image = 'bell_bell.png', - drawtype = "plantlike", - } - for k, v in pairs(small_bell_base) do - small_bell_def[k] = v - end - - minetest.register_node("bell:bell_small", small_bell_def) -end - ---------------------------------------------------------- ---- Recipes - -if minetest.get_modpath("default") then - minetest.register_craft({ - output = "bell:bell_small", - recipe = { - {"", "default:goldblock", "" }, - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "", "default:goldblock"}, - }, - }) - minetest.register_craft({ - output = "bell:bell", - recipe = { - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "", "default:goldblock"}, - }, - }) -end - -if minetest.get_modpath("mcl_core") then - minetest.register_craft({ - output = "bell:bell_small", - recipe = { - {"", "mcl_core:goldblock", "" }, - {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, - {"mcl_core:goldblock", "", "mcl_core:goldblock"}, - }, - }) - minetest.register_craft({ - output = "bell:bell", - recipe = { - {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, - {"mcl_core:goldblock", "mcl_core:goldblock", "mcl_core:goldblock"}, - {"mcl_core:goldblock", "", "mcl_core:goldblock"}, - }, - }) -end - - ------------ ---Loot mod support ------------ - -if minetest.get_modpath("mcl_loot") then - - mcl_loot.get_loot({ - stacks_min = 1, - stacks_max = 1, - items = { -- Table of possible loot items. This function selects between stacks_min and stacks_max of these. - { - itemstring = "bell:bell", -- Which item to select - amount_min = 1, -- Minimum size of itemstack. Must not be larger than 6553. Optional (default: 1) - amount_max = 10, -- Maximum size of item stack. Must not be larger than item definition's stack_max or 6553. Optional (default: 1) - wear_min = 1, -- Minimum wear value. Must be at least 1. Optional (default: no wear) - wear_max = 1, -- Maxiumum wear value. Must be at least 1. Optional (default: no wear) - weight = 5, -- Likelihood of this item being selected (see below). Optional (default: 1) - }, - } -}) - -end - - - - - - - - - - - - - if (err ~= nil) then - minetest.log("error", "[bell] Could not save bell data") - return - end - file:write( str ) - file:flush() - file:close() - --minetest.chat_send_all("Wrote data to savefile "..tostring( BELL_SAVE_FILE )) -end - -local restore_bell_data = function() - - local bell_position_table - - local file, err = io.open(BELL_SAVE_FILE, "rb") - if (err ~= nil) then - minetest.log("warning", "[bell] Could not open bell data savefile (ignore this message on first start)") - return - end - local str = file:read() - file:close() - - local bell_positions_table = minetest.deserialize( str ) - if( bell_positions_table and bell_positions_table.bell_data ) then - bell_positions = bell_positions_table.bell_data - minetest.log("action", "[bell] Read positions of bells from savefile.") - end -end - ---------------------------------------------------------- ---- Local time handling - -local rings_at_dawn = tonumber(minetest.settings:get("bell_tolls_at_dawn")) or 0 -local rings_at_noon = tonumber(minetest.settings:get("bell_tolls_at_noon")) or 0 -local rings_at_dusk = tonumber(minetest.settings:get("bell_tolls_at_dusk")) or 0 -local rings_at_midnight = tonumber(minetest.settings:get("bell_tolls_at_midnight")) or 0 - -local ring_at_dawn = rings_at_dawn > 0 -local ring_at_noon = rings_at_noon > 0 -local ring_at_dusk = rings_at_dusk > 0 -local ring_at_midnight = rings_at_midnight > 0 -local local_time = ring_at_dawn or ring_at_noon or ring_at_dusk or ring_at_midnight - -local last_timeofday = 0 -local dawn = 0.2 -- day and night in Minetest isn't exactly even -local noon = 0.5 -local dusk = 0.8 - -if local_time then - minetest.register_globalstep(function(dtime) - local timeofday = minetest.get_timeofday() - if ring_at_dawn and timeofday >= dawn and last_timeofday < dawn then - ring_bell_multiple(rings_at_dawn) - last_timeofday = timeofday - return - end - if ring_at_noon and timeofday >= noon and last_timeofday < noon then - ring_bell_multiple(rings_at_noon) - last_timeofday = timeofday - return - end - if ring_at_dusk and timeofday >= dusk and last_timeofday < dusk then - ring_bell_multiple(rings_at_dusk) - last_timeofday = timeofday - return - end - if ring_at_midnight and timeofday < last_timeofday then - -- day rolled over, it's midnight - ring_bell_multiple(rings_at_midnight) - last_timeofday = timeofday - return - end - last_timeofday = timeofday - end) -end - ---------------------------------------------------------- ---- Global time handling - -local global_time = minetest.settings:get_bool("bell_tolls_at_server_hours", true) - -local ring_bell -ring_bell = function() - if not global_time then - return - end - - -- figure out if this is the right time to ring - local sekunde = tonumber( os.date( "%S")) - local minute = tonumber( os.date( "%M")) - local stunde = tonumber( os.date( "%I")) -- in 12h-format (a bell that rings 24x at once would not survive long...) - local delay = RING_INTERVAL - - --print("[bells]It is now H:"..tostring( stunde ).." M:"..tostring(minute).." S:"..tostring( sekunde )) - - --local datum = os.date( "Stunde:%l Minute:%M Sekunde:%S") - --print('[bells] ringing bells at '..tostring( datum )) - - delay = RING_INTERVAL - sekunde - (minute*60) - - -- make sure the bell rings the next hour - minetest.after( delay, ring_bell ) - - -- if no bells are around then don't ring - if( bell_positions == nil or #bell_positions < 1 ) then - return - end - - if( sekunde > 10 ) then --- print("[bells] Too late. Waiting for "..tostring( delay ).." seconds.") - return - end - - -- ring the bell for each hour once - ring_bell_multiple(stunde) -end - --- first call (after the server has been started) -minetest.after( 10, ring_bell ) --- read data about bell positions -restore_bell_data() - ---------------------------------------------------------- ---- Node definitions - -local bell_base = { - paramtype = "light", - description = S("Bell"), - stack_max = 1, - - on_punch = function (pos,node,puncher) - ring_big_bell(pos) - end, - - on_construct = function(pos) - -- remember that there is a bell at that position - table.insert( bell_positions, pos ) - save_bell_positions() - end, - - on_destruct = function(pos) - local found = 0 - -- actually remove the bell from the list - for i,v in ipairs( bell_positions ) do - if(v ~= nil and vector.equals(v, pos)) then - table.remove( bell_positions, i) - save_bell_positions() - break - end - end - end, - - groups = {cracky=2}, -} - -if minetest.get_modpath("mesecons") then - bell_base.mesecons = { - effector = { - action_on = ring_big_bell, - } - } -end - - -local ring_small_bell = function(pos) - minetest.sound_play( "bell_small", - { pos = pos, gain = 1.5, max_hear_distance = 60,}) -end - - -local small_bell_base = { - description = S("Small bell"), - paramtype = "light", - stack_max = 1, - on_punch = function (pos,node,puncher) - ring_small_bell(pos) - end, - groups = {cracky=2}, -} - -if minetest.get_modpath("mesecons") then - small_bell_base.mesecons = { - effector = { - action_on = ring_small_bell, - } - } -end - ----------------------------------------------------- - -if minetest.settings:get_bool("bell_enable_model", true) then ----------------- --- Model-type bell - local bell_def = { - drawtype = "mesh", - mesh = "bell_bell.obj", - tiles = { - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "default_wood.png", backface_culling = true }, -- - }, - collision_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, - }, - }, - paramtype2 = "facedir", - } - - for k, v in pairs(bell_base) do - bell_def[k] = v - end - - minetest.register_node("bell:bell", bell_def) - - local small_bell_def = - { drawtype = "mesh", - mesh = "bell_small_bell.obj", - tiles = { - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "bell_hull.png", backface_culling = true }, -- - { name = "default_wood.png", backface_culling = true }, -- - }, - collision_box = { - type = "fixed", - fixed = { - {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.375, -0.25, -0.375, 0.375, 0.5, 0.375}, - }, - }, - paramtype2 = "facedir", - } - - for k, v in pairs(small_bell_base) do - small_bell_def[k] = v - end - - minetest.register_node("bell:bell_small", small_bell_def) - -else --------------------- --- Plantlike-type bell - local bell_def = { - tiles = {"bell_bell.png"}, - inventory_image = 'bell_bell.png', - wield_image = 'bell_bell.png', - drawtype = "plantlike", - } - for k, v in pairs(bell_base) do - bell_def[k] = v - end - - minetest.register_node("bell:bell", bell_def) - - local small_bell_def = { - tiles = {"bell_bell.png"}, - inventory_image = 'bell_bell.png', - wield_image = 'bell_bell.png', - drawtype = "plantlike", - } - for k, v in pairs(small_bell_base) do - small_bell_def[k] = v - end - - minetest.register_node("bell:bell_small", small_bell_def) -end - ---------------------------------------------------------- ---- Recipes - -if minetest.get_modpath("default") then - minetest.register_craft({ - output = "bell:bell_small", - recipe = { - {"", "default:goldblock", "" }, - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "", "default:goldblock"}, - }, - }) - minetest.register_craft({ - output = "bell:bell", - recipe = { - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "default:goldblock", "default:goldblock"}, - {"default:goldblock", "", "default:goldblock"}, - }, - }) -end -local S = minetest.get_translator(minetest.get_current_modname()) - --- bell_positions are saved through server restart --- bells ring every hour --- they ring as many times as a bell ought to - -local RING_INTERVAL = 3600 --60*60 -- ring each hour - -local BELL_SAVE_FILE = minetest.get_worldpath().."/bell_positions.data" - -local bell_positions = {} - -local ring_big_bell = function(pos) - minetest.sound_play( "bell_bell", - { pos = pos, gain = 1.5, max_hear_distance = 300,}) -end --- actually ring the bell -local ring_bell_once = function() - for i,v in ipairs( bell_positions ) do - ring_big_bell(v) - end -end - -local ring_bell_multiple = function(rings) - for i=1, rings do - minetest.after( (i-1)*5, ring_bell_once ) - end -end - ---------------------------------------------------------- ---- Persistence - local save_bell_positions = function() local str = minetest.serialize( ({ bell_data = bell_positions}) ) From 28b051c3a278ed15dbcf2936c879fff6cf0abda8 Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 10 Apr 2020 20:29:02 +0200 Subject: [PATCH 7/9] Update mod.conf --- mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.conf b/mod.conf index d30c1ee..7bf130e 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = bell description = Adds a bell the player can ring and a bell that auto-tolls on the hour. -optional_depends = default, mesecons \ No newline at end of file +optional_depends = default, mcl_core, mcl_loot, doc From fe172953c3c6ed945fd058ccdb62c3532002aae4 Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 10 Apr 2020 20:29:34 +0200 Subject: [PATCH 8/9] Update mod.conf --- mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.conf b/mod.conf index 7bf130e..22767bc 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = bell description = Adds a bell the player can ring and a bell that auto-tolls on the hour. -optional_depends = default, mcl_core, mcl_loot, doc +optional_depends = default, mcl_core, mcl_loot, mesecons, doc From fc20b29d63fae6ab1965058e758eb795b3fbb16e Mon Sep 17 00:00:00 2001 From: wuniversales <48658161+wuniversales@users.noreply.github.com> Date: Fri, 10 Apr 2020 20:29:48 +0200 Subject: [PATCH 9/9] Delete depends.txt --- depends.txt | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 depends.txt diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 30bdd12..0000000 --- a/depends.txt +++ /dev/null @@ -1,4 +0,0 @@ -default? -mcl_core? -mcl_loot? -doc?