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.
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
})
Last edited by randomproof on Thu Mar 22, 2012 23:32, edited 1 time in total.
That small mod should not depend on huge animals mod just because of wool.
randomproof, Also, register_globalstep calls every 0.03-0.05 seconds, so your AllPlayersInBed check should be called rarely. And you can make this check faster if you'll check only count of players.
rinoux wrote:
[Edit] Wool ? from amimal's mod's sheep
That small mod should not depend on huge animals mod just because of wool.
I think the correct way to handle this would be to have a mod that defines general materials and nothing else and depends only on the default mod, on which animals and this mod would then depend on.
It should be called "animalmaterials" or something like that, and it should have zero bias towards any mods (eg. the animals mod or this mod). It should be as simple as possible without any fancy stuff. Just generic common animal-sourced materials like wool and leather, horns, some common meats. That would be the kind of mod that is well suited for pulling into upstream in the future.
xyz wrote:That small mod should not depend on huge animals mod just because of wool.
so...
XXX,XXX,XXX
wood,wood,wood
wood,XXXX,wood
randomproof wrote:
rinoux wrote:
Is that correct ?
No, generally textures are square. Look in data/default/textures for examples.
? I can't, and don't want make a bed in a square ! that will never look like a bed, and it will be too small (same size as the furnace etc.) not for me sorry.
rinoux wrote:
? I can't, and don't want make a bed in a square ! that will never look like a bed, and it will be too small (same size as the furnace etc.) not for me sorry.
+1
it's too bad that we are limited only by the shape of a cube, you can not do very many things, it is very annoying!! ((
xyz wrote:That small mod should not depend on huge animals mod just because of wool.
so...
XXX,XXX,XXX
wood,wood,wood
wood,XXXX,wood
randomproof wrote:
rinoux wrote:
Is that correct ?
No, generally textures are square. Look in data/default/textures for examples.
? I can't, and don't want make a bed in a square ! that will never look like a bed, and it will be too small (same size as the furnace etc.) not for me sorry.
bed roll on the gorund could just be a flat thing like rails!
Zen S.D.
The next generation of tranquility!
malheureusement mon français n'est pas bon :<
Owner of the Zelo's
In game name: MuadTralk, spdtainted, sdzen, sd zen, sdzeno
xyz wrote:
randomproof, Also, register_globalstep calls every 0.03-0.05 seconds, so your AllPlayersInBed check should be called rarely. And you can make this check faster if you'll check only count of players.
I agree. I will add something so it only checks every 10-30 seconds. I would love to check just players but i don't see a way of getting a list of just players. I thought of adding them to a list when they connect but there isn't a callback for that. That is also why I can't just check a count of players. Someone could join and I wouldn't know until I looped through all entities.
Last edited by randomproof on Wed Jan 25, 2012 16:21, edited 1 time in total.