[Mod] Quick bed mod
Posted: Tue Jan 24, 2012 22:26
Quick bed mod
Here is my quickly done beds mod. It needs someone to made a texture for the bed. There is also no crafting recipe as I couldn't think of a good one for this.
It works by having players standing on top of the bed and the system will count you as being "in bed". Every globalstep the mod will see if everyone is "in bed" if yes then it will set the time to dawn. Only thing is that things like furnaces won't step with the time change. It only affects the sun.
License: WTFPL
Please remember that this is not a full mod. This is code to show you how to do something like this.
Here is my quickly done beds mod. It needs someone to made a texture for the bed. There is also no crafting recipe as I couldn't think of a good one for this.
It works by having players standing on top of the bed and the system will count you as being "in bed". Every globalstep the mod will see if everyone is "in bed" if yes then it will set the time to dawn. Only thing is that things like furnaces won't step with the time change. It only affects the sun.
License: WTFPL
Please remember that this is not a full mod. This is code to show you how to do something like this.
Code: Select all
sleeping_players = {}
function AllPlayersInBed()
local ret = false
for k, v in pairs(minetest.object_refs) do
if v:get_player_name() ~= nil then
if sleeping_players[v:get_player_name()] == nil then
return false
end
ret = true
end
end
return ret
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer >= 10 then
timer = timer - 10
else
return
end
if AllPlayersInBed() then
minetest.debug("[beds] Everyone in bed. Setting time to dawn.")
-- set time to dawn
minetest.env:set_timeofday(0.24)
-- remove everyone from bed so this doesn't run constantly
sleeping_players = {}
end
end)
minetest.register_node("beds:bed", {
description = "Bed",
tile_images = {"beds_bed.png"},
is_ground_content = true,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
})
minetest.register_abm({
nodenames = { "beds:bed" },
interval = 10,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
for name, in_bed in pairs(sleeping_players) do
if in_bed ~= nil then
if in_bed.x == pos.x and in_bed.y == pos.y and in_bed.z == pos.z then
sleeping_players[name] = nil
end
end
end
objs = minetest.env:get_objects_inside_radius(pos, 1)
for _, o in pairs(objs) do
name = o:get_player_name()
if name ~= nil then
minetest.debug("[beds] " .. name .. " added to bed at " .. minetest.pos_to_string(pos))
sleeping_players[name] = pos
end
end
end
})