diff --git a/mods/achievements/init.lua b/mods/achievements/init.lua index f8fff24..9a648d7 100644 --- a/mods/achievements/init.lua +++ b/mods/achievements/init.lua @@ -338,7 +338,7 @@ achievements.register_achievement( }) achievements.register_achievement( - "rockin'", + "rockin", { title = "Rockin'", description = "Mine 200 stone", diff --git a/mods/bed/depends.txt b/mods/bed/depends.txt index 441fbb7..ce095d2 100644 --- a/mods/bed/depends.txt +++ b/mods/bed/depends.txt @@ -1,3 +1,4 @@ +crafting default player_effects achievements diff --git a/mods/bed/init.lua b/mods/bed/init.lua index e034970..8f4be73 100644 --- a/mods/bed/init.lua +++ b/mods/bed/init.lua @@ -1,10 +1,243 @@ + -- -- Bed mod -- By PilzAdam, thefamilygrog66 -- Tweaked by Kaadmy, for Pixture -- -local players_in_bed = {} +bed = {} + +-- Per-user data table + +bed.userdata = {} + +local bed_file = minetest.get_worldpath() .. "/bed.dat" +local saving = false + +local timer = 0 + +local delay_daytime = false + +local function is_bed_node(pos) + if pos == nil then + return false + end + + local node = minetest.get_node(pos) + + if node.name == "bed:bed_foot" then + return true + end + + return false +end + +local function put_player_in_bed(player) + if player == nil then + return + end + + local name = player:get_player_name() + + if bed.userdata[name].slept + and not is_bed_node(bed.userdata[name].node_pos) then + return + end + + player:set_look_horizontal(bed.userdata[name].spawn_yaw) + player:setpos(bed.userdata[name].spawn_pos) + + player_effects.apply_effect(player, "inbed") + + player:set_eye_offset(vector.new(0, -13, 0), vector.new(0, -13, 0)) + player:set_local_animation( + {x=162, y=166}, + {x=162, y=166}, + {x=162, y=166}, + {x=162, y=168}, + 30) + + default.player_set_animation(player, "lay", 30) + + default.player_attached[name] = true + +end + +local function take_player_from_bed(player) + if player == nil then + return + end + + local name = player:get_player_name() + + player:setpos(bed.userdata[name].spawn_pos) + + player_effects.remove_effect(player, "inbed") + + player:set_eye_offset(vector.new(0, 0, 0), vector.new(0, 0, 0)) + player:set_local_animation( + {x=0, y=79}, + {x=168, y=187}, + {x=189, y=198}, + {x=200, y=219}, + 30) + + default.player_set_animation(player, "stand", 30) + + default.player_attached[name] = false +end + +local function save_bed() + local f = io.open(bed_file, "w") + + f:write(minetest.serialize(bed.userdata)) + + io.close(f) + + saving = false +end + +local function delayed_save() + if not saving then + saving = true + + minetest.after(40, save_bed) + end +end + +local function load_bed() + local f = io.open(bed_file, "r") + + if f then + bed.userdata = minetest.deserialize(f:read("*all")) + + io.close(f) + else + save_bed() + end +end + +local function on_load() + load_bed() +end + +local function on_shutdown() + save_bed() +end + +local function on_joinplayer(player) + local name = player:get_player_name() + + if not bed.userdata[name] then + bed.userdata[name] = { + in_bed = false, + + spawn_yaw = 0, + spawn_pos = nil, + + slept = false, + + node_pos = nil, + } + + delayed_save() + end + + if bed.userdata[name].in_bed then + minetest.after( + 0.1, + function() + put_player_in_bed(player) + end) + end +end + +local function on_respawnplayer(player) + local name = player:get_player_name() + + if bed.userdata[name] then + if not bed.userdata[name].slept then + if not is_bed_node(bed.userdata[name].node_pos) then + minetest.chat_send_player( + name, + minetest.colorize( + "#f00", "You don't have a bed")) + else + minetest.chat_send_player( + name, + minetest.colorize( + "#f00", "You haven't slept in a bed yet")) + end + + return + end + + bed.userdata[name].in_bed = false + + take_player_from_bed(player) + + return true + end +end + +local function on_globalstep(dtime) + timer = timer + dtime + + if timer < 2 then + return + end + + timer = 0 + + local sleeping_players = 0 + + for _, data in pairs(bed.userdata) do + if data.in_bed then + sleeping_players = sleeping_players + 1 + end + end + + local players = #minetest.get_connected_players() + + if players > 0 and (players / 2.0) < sleeping_players then + if minetest.get_timeofday() < 0.2 or minetest.get_timeofday() > 0.8 then + if not delay_daytime then + delay_daytime = true + + minetest.after( + 2, + function() + minetest.chat_send_all( + minetest.colorize( + "#0ff", + "*** " .. sleeping_players .. " of " .. players + .. " players slept, rise and shine!")) + + minetest.set_timeofday(0.23) + delay_daytime = false + + for _, player in ipairs(minetest.get_connected_players()) do + if bed.userdata[player:get_player_name()].in_bed then + bed.userdata[player:get_player_name()].slept = true + end + end + end) + + delayed_save() + end + end + end +end + +minetest.after(0, on_load) + +minetest.register_on_shutdown(on_shutdown) + +minetest.register_on_joinplayer(on_joinplayer) + +minetest.register_on_respawnplayer(on_respawnplayer) + +minetest.register_globalstep(on_globalstep) minetest.register_node( "bed:bed_foot", @@ -29,74 +262,75 @@ minetest.register_node( }, after_place_node = function(pos) - local node = minetest.get_node(pos) - local dir = minetest.facedir_to_dir(node.param2) - local head_pos = vector.add(pos, dir) - node.name = "bed:bed_head" - if minetest.registered_nodes[minetest.get_node(head_pos).name].buildable_to then - minetest.set_node(head_pos, node) - else - minetest.remove_node(pos) - end - end, + local node = minetest.get_node(pos) + local dir = minetest.facedir_to_dir(node.param2) + local head_pos = vector.add(pos, dir) + node.name = "bed:bed_head" + if minetest.registered_nodes[minetest.get_node(head_pos).name].buildable_to then + minetest.set_node(head_pos, node) + else + minetest.remove_node(pos) + end + end, on_destruct = function(pos) - local node = minetest.get_node(pos) - local dir = minetest.facedir_to_dir(node.param2) - local head_pos = vector.add(pos, dir) - if minetest.get_node(head_pos).name == "bed:bed_head" then - minetest.remove_node(head_pos) - end - end, + local node = minetest.get_node(pos) + local dir = minetest.facedir_to_dir(node.param2) + local head_pos = vector.add(pos, dir) + if minetest.get_node(head_pos).name == "bed:bed_head" then + minetest.remove_node(head_pos) + end + end, on_rightclick = function(pos, node, clicker) - if not clicker:is_player() or not minetest.setting_getbool("bed_enabled") then - return - end + if not clicker:is_player() then + return + end - local name = clicker:get_player_name() - local meta = minetest.get_meta(pos) - local put_pos = vector.add(pos, vector.divide(minetest.facedir_to_dir(node.param2), 2)) + local name = clicker:get_player_name() + local meta = minetest.get_meta(pos) + local put_pos = vector.add(pos, vector.divide( + minetest.facedir_to_dir(node.param2), 2)) - if clicker:get_player_name() == meta:get_string("player") then - put_pos.y = put_pos.y - 0.5 + if clicker:get_player_name() == meta:get_string("player") then + put_pos.y = put_pos.y - 0.5 - clicker:setpos(put_pos) - player_effects.remove_effect(clicker, "inbed") - clicker:set_eye_offset(vector.new(0, 0, 0), vector.new(0, 0, 0)) - clicker:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30) - default.player_set_animation(clicker, "stand", 30) + bed.userdata[name].in_bed = false - players_in_bed[name] = nil - default.player_attached[name] = false + take_player_from_bed(clicker) - meta:set_string("player", "") - elseif meta:get_string("player") == "" and not default.player_attached[name] and players_in_bed[name] == nil then - put_pos.y = put_pos.y + 0.6 + meta:set_string("player", "") + elseif meta:get_string("player") == "" and not default.player_attached[name] + and bed.userdata[name].in_bed == false then + if not minetest.setting_getbool("bed_enabled") then + return + end - clicker:setpos(put_pos) - player_effects.apply_effect(clicker, "inbed") - clicker:set_eye_offset(vector.new(0, -13, 0), vector.new(0, -13, 0)) - clicker:set_local_animation({x=162, y=166}, {x=162, y=166}, {x=162, y=166}, {x=162, y=168}, 30) - default.player_set_animation(clicker, "lay", 30) + put_pos.y = put_pos.y + 0.6 - if node.param2 == 2 then - clicker:set_look_yaw(0) - else - clicker:set_look_yaw(node.param2 / 2 * math.pi) - end + local yaw = 0 - players_in_bed[name] = true - default.player_attached[name] = true + if node.param2 ~= 2 then + yaw = (node.param2 / 2.0) * math.pi + end - meta:set_string("player", name) - end - end, + bed.userdata[name].in_bed = true + + bed.userdata[name].spawn_yaw = yaw + bed.userdata[name].spawn_pos = put_pos + + bed.userdata[name].node_pos = pos + + put_player_in_bed(clicker) + + meta:set_string("player", name) + end + end, can_dig = function(pos) - return minetest.get_meta(pos):get_string("player") == "" - end - }) + return minetest.get_meta(pos):get_string("player") == "" + end +}) minetest.register_node( "bed:bed_head", @@ -112,68 +346,18 @@ minetest.register_node( type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 2/16, 0.5} } - }) +}) minetest.register_alias("bed:bed", "bed:bed_foot") -minetest.register_craft( +crafting.register_craft( { output = "bed:bed", - recipe = { - {"group:fuzzy", "group:fuzzy", "group:fuzzy"}, - {"group:planks", "group:planks", "group:planks"} + items = { + "group:fuzzy 3", + "group:planks 3", } - }) - -bed_player_spawns = {} - -local file = io.open(minetest.get_worldpath().."/bed.dat", "r") -if file then - bed_player_spawns = minetest.deserialize(file:read("*all")) - file:close() -end - -local timer = 0 -local wait = false - -minetest.register_globalstep( - function(dtime) - if timer < 2 then - timer = timer + dtime - return - end - timer = 0 - - local sleeping_players = 0 - for _, i in pairs(players_in_bed) do - if i then - sleeping_players = sleeping_players + 1 - end - end - - local players = #minetest.get_connected_players() - if players > 0 and players * 0.5 < sleeping_players then - if minetest.get_timeofday() < 0.2 or minetest.get_timeofday() > 0.8 then - if not wait then - minetest.chat_send_all("[zzz] "..sleeping_players.." of "..players.." players slept, skipping to day.") - - wait = true - minetest.after(2, function() - minetest.set_timeofday(0.23) - wait = false - end) - - for _, player in ipairs(minetest.get_connected_players()) do - bed_player_spawns[player:get_player_name()] = player:getpos() - end - - local file = io.open(minetest.get_worldpath().."/bed.dat", "w") - file:write(minetest.serialize(bed_player_spawns)) - file:close() - end - end - end - end) +}) player_effects.register_effect( "inbed", @@ -186,20 +370,7 @@ player_effects.register_effect( jump = 0, gravity = 0, } - }) - -minetest.register_on_respawnplayer( - function(player) - local name = player:get_player_name() - if bed_player_spawns[name] then - player:setpos(bed_player_spawns[name]) - end - end) - -minetest.register_on_leaveplayer( - function(player) - players_in_bed[player:get_player_name()] = nil - end) +}) -- Achievements @@ -210,6 +381,6 @@ achievements.register_achievement( description = "Craft a bed", times = 1, craftitem = "bed:bed_foot", - }) +}) default.log("mod:bed", "loaded") diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 9010cb8..245cf42 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -845,7 +845,6 @@ minetest.register_node( "default:water_flowing", { description = "Water (flowing)", - inventory_image = minetest.inventorycube("default_water.png"), drawtype = "flowingliquid", tiles ={"default_water.png"}, special_tiles = { @@ -881,7 +880,6 @@ minetest.register_node( "default:water_source", { description = "Water", - inventory_image = minetest.inventorycube("default_water.png"), drawtype = "liquid", tiles ={"default_water.png"}, special_tiles = { @@ -911,7 +909,6 @@ minetest.register_node( "default:river_water_flowing", { description = "River Water (flowing)", - inventory_image = minetest.inventorycube("default_water.png"), drawtype = "flowingliquid", tiles ={"default_water.png"}, special_tiles = { @@ -949,7 +946,6 @@ minetest.register_node( "default:river_water_source", { description = "River Water", - inventory_image = minetest.inventorycube("default_water.png"), drawtype = "liquid", tiles ={"default_water.png"}, special_tiles = { @@ -981,7 +977,6 @@ minetest.register_node( "default:swamp_water_flowing", { description = "Swamp Water (flowing)", - inventory_image = minetest.inventorycube("default_swamp_water.png"), drawtype = "flowingliquid", tiles ={"default_swamp_water.png"}, special_tiles = { @@ -1019,7 +1014,6 @@ minetest.register_node( "default:swamp_water_source", { description = "Swamp Water", - inventory_image = minetest.inventorycube("default_swamp.png"), drawtype = "liquid", tiles ={"default_swamp_water.png"}, special_tiles = { diff --git a/mods/hunger/init.lua b/mods/hunger/init.lua index 623fc95..505065c 100644 --- a/mods/hunger/init.lua +++ b/mods/hunger/init.lua @@ -38,7 +38,7 @@ local function delayed_save() if not saving then saving = true - minetest.after(5, save_hunger) + minetest.after(40, save_hunger) end end @@ -83,6 +83,10 @@ local function on_load() load_hunger() end +local function on_shutdown() + save_hunger() +end + function hunger.update_bar(player) if not player then return @@ -220,7 +224,7 @@ local function on_item_eat(hpdata, replace_with_item, itemstack, player_effects.apply_effect(player, "hunger_eating") hunger.update_bar(player) - hunger.save_hunger() + delayed_save() itemstack:take_item(1) @@ -334,6 +338,10 @@ end if minetest.setting_getbool("hunger_enable") then + minetest.after(0, on_load) + + minetest.register_on_shutdown(on_shutdown) + minetest.register_on_dignode(on_dignode) minetest.register_on_placenode(on_placenode) diff --git a/mods/player_effects/init.lua b/mods/player_effects/init.lua index 29cb9f1..ba9bbed 100644 --- a/mods/player_effects/init.lua +++ b/mods/player_effects/init.lua @@ -248,13 +248,19 @@ player_effects.register_effect( speed = 2, } }) -minetest.register_privilege("uberspeed", "Can use /uberspeed command") +minetest.register_privilege( + "uberspeed", + { + description = "Can use /uberspeed command", + give_to_singleplayer = false +}) + minetest.register_chatcommand( "uberspeed", { params = "[on|off|cinematic]", description = "Set Uberspeed", - privs = {uberspeed = true}, + privs = {uberspeed = true, give_to_singleplayer = false}, func = function(name, param) local player=minetest.get_player_by_name(name) diff --git a/mods/util/init.lua b/mods/util/init.lua index 970b76c..4af28ac 100644 --- a/mods/util/init.lua +++ b/mods/util/init.lua @@ -27,7 +27,7 @@ function util.fixlight(pos1, pos2) local pos1, pos2 = util.sort_pos(pos1, pos2) --make area stay loaded - + local manip = minetest.get_voxel_manip() manip:read_from_map(pos1, pos2) @@ -41,8 +41,14 @@ function util.fixlight(pos1, pos2) return #nodes end + if minetest.setting_getbool("fixlight_command_enable") then - minetest.register_privilege("fixlight", "Can use /fixlight command") + minetest.register_privilege( + "fixlight", + { + description = "Can use /fixlight command", + give_to_singleplayer = false + }) minetest.register_chatcommand( "fixlight", @@ -83,7 +89,7 @@ function util.nodefunc(pos1, pos2, name, func, nomanip) local manip = minetest.get_voxel_manip() manip:read_from_map(pos1, pos2) end - + local nodes = minetest.find_nodes_in_area(pos1, pos2, name) for _, pos in ipairs(nodes) do func(pos) @@ -97,7 +103,7 @@ function util.getvoxelmanip(pos1, pos2) local manip = minetest.get_voxel_manip() manip:read_from_map(pos1, pos2) - + return manip end @@ -110,7 +116,7 @@ function util.remove_area(pos1, pos2, nomanip) local manip = minetest.get_voxel_manip() manip:read_from_map(pos1, pos2) end - + for i = pos1.x, pos2.x-1 do for j = pos1.y, pos2.y-1 do for k = pos1.z, pos2.z-1 do @@ -131,7 +137,7 @@ function util.areafunc(pos1, pos2, func, nomanip) local manip = minetest.get_voxel_manip() manip:read_from_map(pos1, pos2) end - + for i = pos1.x, pos2.x-1 do for j = pos1.y, pos2.y-1 do for k = pos1.z, pos2.z-1 do @@ -150,7 +156,7 @@ function util.reconstruct(pos1, pos2, nomanip) local manip = minetest.get_voxel_manip() manip:read_from_map(pos1, pos2) end - + -- fix chests local nodes = minetest.find_nodes_in_area(pos1, pos2, "default:chest") local node = minetest.registered_nodes["default:chest"] @@ -161,14 +167,14 @@ function util.reconstruct(pos1, pos2, nomanip) -- fix music players nodes = minetest.find_nodes_in_area(pos1, pos2, "music:player") node = minetest.registered_nodes["music:player"] - for _, pos in ipairs(nodes) do + for _, pos in ipairs(nodes) do node.on_construct(pos) end -- fix furnaces nodes = minetest.find_nodes_in_area(pos1, pos2, "default:furnace") node = minetest.registered_nodes["default:furnace"] - for _, pos in ipairs(nodes) do + for _, pos in ipairs(nodes) do node.on_construct(pos) end end @@ -177,7 +183,7 @@ function util.choice(tab, pr) -- return a random index of the given table local choices = {} - + for n, _ in pairs(tab) do table.insert(choices, n) end @@ -195,7 +201,7 @@ function util.choice_element(tab, pr) -- return a random element of the given table local choices = {} - + for _,n in pairs(tab) do table.insert(choices, n) end @@ -228,4 +234,4 @@ function util.split(str, tok) table.insert(arr, string.sub(str, pos)) return arr -end \ No newline at end of file +end diff --git a/mods/weather/init.lua b/mods/weather/init.lua index 84b5af7..dbd497b 100644 --- a/mods/weather/init.lua +++ b/mods/weather/init.lua @@ -155,14 +155,19 @@ minetest.register_globalstep( end ) -minetest.register_privilege("weather", "Can use /weather command") +minetest.register_privilege( + "weather", + { + description = "Can use /weather command", + give_to_singleplayer = false +}) minetest.register_chatcommand( "weather", { params = "[storm|snowstorm|clear]", description = "Set the weather to either clear, storm, or snowstorm", - privs = {weather= true}, + privs = {weather = true, give_to_singleplayer = false}, func = function(name, param) setweather_type(param) end