Page 1 of 3

[Mod] Quick bed mod

Posted: Tue Jan 24, 2012 22:26
by randomproof
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.

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
})

Posted: Tue Jan 24, 2012 22:30
by rinoux
texture dimension ?

Posted: Tue Jan 24, 2012 22:53
by randomproof
rinoux wrote:texture dimension ?
It is a standard node cube, so whatever.

Posted: Tue Jan 24, 2012 22:57
by MrThebuilder3
16:59:23: ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: ....dev-20120122-1-win32\bin\..\data\mods\beds\init.lua:34: attempt to call method 'set_timeofday' (a nil value)
16:59:23: ERROR[ServerThread]: stack traceback:

In thread 16f4:
C:\tmp\minetest\src\server.cpp:113: ServerThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 1e8:
#0 main
(Leftover data: #1 Server::step)
(Leftover data: #2 Client::ReceiveAll)
(Leftover data: #3 Client::Receive)
DEBUG STACK FOR THREAD 16f4:
#0 ServerThread::Thread
(Leftover data: #1 Server::AsyncRunStep)
(Leftover data: #2 ServerEnvironment::step)

Posted: Tue Jan 24, 2012 23:30
by rinoux
quick bed texture... same size as mincraft one.

Image

Posted: Wed Jan 25, 2012 01:04
by randomproof
MrThebuilder3 wrote:16:59:23: ERROR[ServerThread]: ERROR: An unhandled exception occurred: LuaError: error: ....dev-20120122-1-win32\bin\..\data\mods\beds\init.lua:34: attempt to call method 'set_timeofday' (a nil value)
16:59:23: ERROR[ServerThread]: stack traceback:

In thread 16f4:
C:\tmp\minetest\src\server.cpp:113: ServerThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 1e8:
#0 main
(Leftover data: #1 Server::step)
(Leftover data: #2 Client::ReceiveAll)
(Leftover data: #3 Client::Receive)
DEBUG STACK FOR THREAD 16f4:
#0 ServerThread::Thread
(Leftover data: #1 Server::AsyncRunStep)
(Leftover data: #2 ServerEnvironment::step)
You must be using the latest git version.

Posted: Wed Jan 25, 2012 01:18
by rinoux
what about this recipe:

wool,wool,wool
wood,wood,wood
wood,nothing,wood

Posted: Wed Jan 25, 2012 01:35
by randomproof
rinoux wrote:what about this recipe:

wool,wool,wool
wood,wood,wood
wood,nothing,wood
Where do you get wool?

Posted: Wed Jan 25, 2012 01:37
by randomproof
rinoux wrote:quick bed texture... same size as mincraft one.

Image
If you could convert that in to the format used by minetest for textures, that would be great.

Posted: Wed Jan 25, 2012 01:54
by rinoux
Image

Is that correct ?

[Edit] Wool ? from amimal's mod's sheep

Posted: Wed Jan 25, 2012 05:07
by randomproof
rinoux wrote:Image

Is that correct ?
No, generally textures are square. Look in data/default/textures for examples.

Posted: Wed Jan 25, 2012 06:49
by xyz
rinoux wrote:Image

Is that correct ?

[Edit] Wool ? from amimal's mod's sheep
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.

Posted: Wed Jan 25, 2012 08:27
by celeron55
xyz wrote:
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.

Posted: Wed Jan 25, 2012 08:27
by rinoux
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:Image

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.

Posted: Wed Jan 25, 2012 08:54
by Nemo08
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!! ((

Posted: Wed Jan 25, 2012 08:58
by xyz
rinoux wrote:
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:Image

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.
Your bed may consist of 2 nodes, not one.

Posted: Wed Jan 25, 2012 09:00
by Nemo08
xyz wrote: Your bed may consist of 2 nodes, not one.
all the same, bed is cubic and not distinguishable from any desk or from any other node!

Posted: Wed Jan 25, 2012 09:36
by rahonejm
We never get so close of beds in minetest! xD

Posted: Wed Jan 25, 2012 12:26
by Calinou
Wool crafting idea:
X = junglegrass
X
X

Crafts one string (like in bow mod).

X = string
X X
X X

Crafts one wool. Like in Minecraft. :)

Posted: Wed Jan 25, 2012 15:11
by sdzen
bed roll on the gorund could just be a flat thing like rails! :)

Posted: Wed Jan 25, 2012 15:42
by Jordach
sdzen wrote:bed roll on the gorund could just be a flat thing like rails! :)
e.g. japanese beds.

Posted: Wed Jan 25, 2012 16:18
by randomproof
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.

Posted: Sun Jan 29, 2012 08:02
by darian_gossman
Here's an idea for wool

p=papyrus, s=stone
ss
pp
pp

The stone crushes the papyrus and makes wool I guess. Its all I got.

Posted: Thu Feb 09, 2012 23:56
by bulletrulz
WHERE IS THE DL LINK !!??

Posted: Fri Feb 10, 2012 00:20
by randomproof
bulletrulz wrote:WHERE IS THE DL LINK !!??
There isn't one. You can copy and paste the file from the first post. This is a proof of concept mod. Feel free to edit it to fit your needs.