From 3f26b5431d52ffc561a82cee0b48c5e966d3e793 Mon Sep 17 00:00:00 2001 From: KaadmY Date: Thu, 11 May 2017 21:24:54 -0700 Subject: [PATCH] Standardize database naming across mods along with numerous minor fixes --- mods/achievements/init.lua | 28 ++++++++++- mods/bed/init.lua | 4 +- mods/hunger/init.lua | 40 +++++++-------- mods/player_effects/init.lua | 6 +-- mods/pm/init.lua | 70 +++++++++++++-------------- mods/village/generate.lua | 2 +- mods/weather/init.lua | 94 ++---------------------------------- 7 files changed, 92 insertions(+), 152 deletions(-) diff --git a/mods/achievements/init.lua b/mods/achievements/init.lua index 3d6a6be..f66f035 100644 --- a/mods/achievements/init.lua +++ b/mods/achievements/init.lua @@ -9,7 +9,8 @@ achievements.achievements = {} achievements.registered_achievements = {} achievements.registered_achievements_list = {} -local achievements_file = minetest.get_worldpath() .. "/achievements" +local achievements_file = minetest.get_worldpath() .. "/achievements.dat" +local saving = false function achievements.register_achievement(name, def) local rd = { @@ -30,17 +31,32 @@ local function save_achievements() f:write(minetest.serialize(achievements.achievements)) + print("Save: " .. dump(achievements.achievements)) + + saving = false + io.close(f) end +local function delayed_save() + if not saving then + saving = true + + minetest.after(60, save_achievements) + end +end + local function load_achievements() local f = io.open(achievements_file, "r") if f then achievements.achievements = minetest.deserialize(f:read("*all")) + print("Load: " .. dump(achievements.achievements)) + io.close(f) else + print("Firstload...") save_achievements() end end @@ -76,7 +92,7 @@ function achievements.trigger_achievement(player, aname, times) end) end - save_achievements() + delayed_save() end -- Load achievements table @@ -85,6 +101,12 @@ local function on_load() load_achievements() end +-- Save achievements table + +local function on_shutdown() + save_achievements() +end + -- New player local function on_newplayer(player) @@ -146,6 +168,8 @@ end minetest.after(0, on_load) +minetest.register_on_shutdown(on_shutdown) + minetest.register_on_newplayer(on_newplayer) minetest.register_on_craft(on_craft) diff --git a/mods/bed/init.lua b/mods/bed/init.lua index 4aea96c..e034970 100644 --- a/mods/bed/init.lua +++ b/mods/bed/init.lua @@ -127,7 +127,7 @@ minetest.register_craft( bed_player_spawns = {} -local file = io.open(minetest.get_worldpath().."/bed.txt", "r") +local file = io.open(minetest.get_worldpath().."/bed.dat", "r") if file then bed_player_spawns = minetest.deserialize(file:read("*all")) file:close() @@ -167,7 +167,7 @@ minetest.register_globalstep( bed_player_spawns[player:get_player_name()] = player:getpos() end - local file = io.open(minetest.get_worldpath().."/bed.txt", "w") + local file = io.open(minetest.get_worldpath().."/bed.dat", "w") file:write(minetest.serialize(bed_player_spawns)) file:close() end diff --git a/mods/hunger/init.lua b/mods/hunger/init.lua index dafa576..a7e1666 100644 --- a/mods/hunger/init.lua +++ b/mods/hunger/init.lua @@ -16,7 +16,7 @@ local player_step = {} local player_health_step = {} local player_bar = {} local base_interval = tonumber(minetest.setting_get("hunger_step")) or 3.0 -- seconds per hunger update, 2.0 is slightly fast -local file = minetest.get_worldpath() .. "/hunger" +local file = minetest.get_worldpath() .. "/hunger.dat" function hunger.save_hunger() local output = io.open(file, "w") @@ -44,7 +44,7 @@ local function load_hunger() hunger.hunger[name] = hnger hunger.saturation[name] = sat --- minetest.log("action", name.." has "..hnger.." hunger and is saturated to "..sat.."%") + -- minetest.log("action", name.." has "..hnger.." hunger and is saturated to "..sat.."%") until input:read(0) == nil io.close(input) else @@ -69,7 +69,7 @@ function hunger.update_bar(player) dir = 0, size = {x=16, y=16}, offset = {x=64, y=-(48+24+16)}, - }) + }) end end @@ -83,7 +83,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge physics = { speed = 0.6, } - }) + }) -- Prevent players from starving while afk (<--joke) minetest.register_on_dignode( @@ -91,14 +91,14 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge if not player then return end local name = player:get_player_name() hunger.active[name] = hunger.active[name]+ 2 - end) + end) minetest.register_on_placenode( function(pos, node, player) if not player then return end local name = player:get_player_name() hunger.active[name] = hunger.active[name]+ 2 - end) + end) minetest.register_on_joinplayer( function(player) @@ -113,16 +113,16 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge dir = 0, size = {x=16, y=16}, offset = {x=64, y=-(48+24+16)}, - }) - + }) + hunger.update_bar(player) - end) + end) minetest.register_on_leaveplayer( function(player) local name = player:get_player_name() player_bar[name] = nil - end) + end) minetest.register_on_respawnplayer( function(player) @@ -130,7 +130,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge hunger.hunger[name] = 20 hunger.update_bar(player) hunger.save_hunger() - end) + end) minetest.register_on_item_eat( function(hpdata, replace_with_item, itemstack, player, pointed_thing) @@ -139,7 +139,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge local hp_change = 0 local saturation = 2 - + if type(hpdata) == "number" then hp_change = hpdata else @@ -178,7 +178,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge minsize = 0.5, maxsize = 2, texture = "magicpuff.png" - }) + }) minetest.after(0.15, function() minetest.delete_particlespawner(particlespawners[name]) end) @@ -190,7 +190,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge itemstack:take_item(1) return itemstack - end) + end) -- Main function local timer = 0 @@ -221,7 +221,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge hunger.moving[name] = moving end - + timer = timer + dtime if timer < base_interval then return end @@ -252,9 +252,9 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge if hunger.hunger[name] <= 0 and hp >= 0 then player:set_hp(hp - 1) hunger.hunger[name] = 0 - + local pos_sound = player:getpos() - minetest.chat_send_player(name, "You are hungry.") + minetest.chat_send_player(name, minetest.colorize("#f00", "You are hungry.")) end end end @@ -272,7 +272,7 @@ if minetest.setting_getbool("enable_damage") and minetest.setting_getbool("hunge end hunger.save_hunger() - end) + end) else minetest.register_on_item_eat( function(hpdata, replace_with_item, itemstack, player, pointed_thing) @@ -283,5 +283,5 @@ else itemstack:take_item(1) return itemstack - end) -end \ No newline at end of file + end) +end diff --git a/mods/player_effects/init.lua b/mods/player_effects/init.lua index f904fa0..c4e977c 100644 --- a/mods/player_effects/init.lua +++ b/mods/player_effects/init.lua @@ -10,7 +10,7 @@ player_effects.registered_effects = {} local update_time = 1 -- update every second local timer = 10 -local effects_file = minetest.get_worldpath() .. "/player_effects" +local effects_file = minetest.get_worldpath() .. "/player_effects.dat" local function save_effects() local f = io.open(effects_file, "w") @@ -45,7 +45,7 @@ end function player_effects.get_registered_effect(ename) local e = player_effects.registered_effects[ename] - + if not e then default.log("[mod:player_effects] Cannot find registered player effect " .. ename, "error") @@ -267,4 +267,4 @@ minetest.register_chatcommand( end }) -default.log("mod:player_effects", "loaded") \ No newline at end of file +default.log("mod:player_effects", "loaded") diff --git a/mods/pm/init.lua b/mods/pm/init.lua index 868bd69..cd944f8 100644 --- a/mods/pm/init.lua +++ b/mods/pm/init.lua @@ -15,55 +15,55 @@ minetest.register_chatcommand( description = "Send somebody a private message", privs = {shout=true}, func = function(name, param) - local sendto, message = param:match("^(%S+)%s(.+)$") + local sendto, message = param:match("^(%S+)%s(.+)$") - if not sendto then return false, "Invalid usage, see /help pm." end + if not sendto then return false, "Invalid usage, see /help pm." end - if not minetest.get_player_by_name(sendto) then - if enable_saving then - if messages[sendto] == nil then messages[sendto] = {} end - table.insert(messages[sendto], name .. ": " .. message) + if not minetest.get_player_by_name(sendto) then + if enable_saving then + if messages[sendto] == nil then messages[sendto] = {} end + table.insert(messages[sendto], name .. ": " .. message) - return false, "The player " .. sendto - .. " is not online, saving message instead." - else - return false, "The player " .. sendto - .. " is not online, and PM saving is disabled." - end - end + return false, "The player " .. sendto + .. " is not online, saving message instead." + else + return false, "The player " .. sendto + .. " is not online, and PM saving is disabled." + end + end - minetest.log("action", "PM from " .. name .. " to " .. sendto - .. ": " .. message) - minetest.chat_send_player(sendto, "PM from " .. name .. ": " - .. message) - return true, "PM sent." - end - }) + minetest.log("action", "PM from " .. name .. " to " .. sendto + .. ": " .. message) + minetest.chat_send_player(sendto, "PM from " .. name .. ": " + .. message) + return true, "PM sent." + end +}) minetest.register_chatcommand( "pms", { description = "Show saved private messages", func = function(name, param) - if not enable_saving then return false, "PM saving is disabled." end - if messages[name] == nil then return false, "No saved PMs." end + if not enable_saving then return false, "PM saving is disabled." end + if messages[name] == nil then return false, "No saved PMs." end - minetest.chat_send_player(name, "Saved PMs:") + minetest.chat_send_player(name, "Saved PMs:") - local str = "" - local amt_pms = 0 - for _, msg in pairs(messages[name]) do - amt_pms = amt_pms + 1 - str = str .. " " .. msg .. "\n" - end + local str = "" + local amt_pms = 0 + for _, msg in pairs(messages[name]) do + amt_pms = amt_pms + 1 + str = str .. " " .. msg .. "\n" + end - minetest.chat_send_player(name, str) + minetest.chat_send_player(name, str) - messages[name] = nil + messages[name] = nil - return true, amt_pms .. " saved PMs" - end - }) + return true, amt_pms .. " saved PMs" + end +}) if enable_saving then minetest.register_on_joinplayer( @@ -77,7 +77,7 @@ if enable_saving then minetest.chat_send_player(name, minetest.colorize("#0ff", "You have no saved PMs. Send PMs with the /pm command.")) return true end - end) + end) end default.log("mod:pm", "loaded") diff --git a/mods/village/generate.lua b/mods/village/generate.lua index 90c4294..de8939a 100644 --- a/mods/village/generate.lua +++ b/mods/village/generate.lua @@ -6,7 +6,7 @@ local mp = minetest.get_modpath("village") village.villages = {} -local village_file = minetest.get_worldpath() .. "/villages" +local village_file = minetest.get_worldpath() .. "/villages.dat" function village.get_id(name, pos) return name .. minetest.hash_node_position(pos) diff --git a/mods/weather/init.lua b/mods/weather/init.lua index 120c6d0..84b5af7 100644 --- a/mods/weather/init.lua +++ b/mods/weather/init.lua @@ -143,6 +143,7 @@ minetest.register_globalstep( minsize = 3, maxsize = 4, collisiondetection = true, + collision_removal = true, vertical = false, texture = "weather_snowflake.png", playername = player:get_player_name() @@ -154,92 +155,7 @@ minetest.register_globalstep( end ) -minetest.register_abm( - { - nodenames = {"weather:ice"}, - interval = 4, - chance = 80, - action = function(pos, node, active_object_count, active_object_count_wider) - if weather.weather ~= "snowstorm" then - minetest.remove_node(pos) - end - end - }) - ---[[minetest.register_abm( - { - nodenames = {"air"}, - interval = 2, - chance = 80, - action = function(pos, node, active_object_count, active_object_count_wider) - if minetest.get_node_light(pos) ~= 15 then return end - - local under_nodepos={x=pos.x, y=pos.y-1, z=pos.z} - local under_node=minetest.get_node(under_nodepos) - - if under_node.name == "air" then return end - - local under_nodedef=minetest.registered_nodes[under_node.name] - - if under_node.name == "default:water_source" and weather.weather == "snowstorm" then - minetest.set_node(under_nodepos, {name = "weather:ice"}) - else - if under_node.name ~= "weather:snow" then - if weather.weather == "snowstorm" then - if under_node.name ~= "default:heated_dirt_path" then - if under_nodedef.walkable then - minetest.set_node(pos, {name = "weather:snow"}) - elseif under_nodedef.drawtype ~= "airlike" and under_nodedef.buildable_to and math.random(0, 20) <= 1 then - minetest.set_node(under_nodepos, {name = "weather:snow"}) - end - end - end - else - if weather.weather ~= "snowstorm" then - minetest.remove_node(under_nodepos) - end - end - end - end, - })--]] - -minetest.register_node( - "weather:snow", - { - description = "Snow", - tiles ={"weather_snow.png"}, - drawtype = "nodebox", - paramtype = "light", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(1/8), 0.5}, - }, - groups = {crumbly=3, falling_node=1, snow=1, fall_damage_add_percent=-10}, - sounds = default.node_sound_snow_defaults(), - }) - -minetest.register_node( - "weather:ice", - { - description = "Ice", - drawtype = "glasslike", - tiles ={"weather_ice.png"}, - use_texture_alpha = true, - paramtype = "light", - groups = {snappy=3, ice=1, fall_damage_add_percent=10}, - sounds = default.node_sound_glass_defaults(), - on_destruct = function(pos) - local function add_water() - minetest.set_node(pos, {name = "default:water_source"}) - end - - if minetest.find_node_near(pos, 1, {"weather:ice", "default:water_source"}) then - minetest.after(0, add_water) - end - end - }) - -minetest.register_privilege("weather", "Can use /weather.weather command") +minetest.register_privilege("weather", "Can use /weather command") minetest.register_chatcommand( "weather", @@ -248,9 +164,9 @@ minetest.register_chatcommand( description = "Set the weather to either clear, storm, or snowstorm", privs = {weather= true}, func = function(name, param) - setweather_type(param) - end - }) + setweather_type(param) + end +}) setweather_type("clear")