[Mod] Quick bed mod

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

[Mod] Quick bed mod

by randomproof » Post

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
})
Last edited by randomproof on Thu Mar 22, 2012 23:32, edited 1 time in total.

User avatar
rinoux
Member
Posts: 184
Joined: Tue Dec 27, 2011 12:15

by rinoux » Post

texture dimension ?

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

rinoux wrote:texture dimension ?
It is a standard node cube, so whatever.

User avatar
MrThebuilder3
Member
Posts: 104
Joined: Sat Nov 19, 2011 18:26

by MrThebuilder3 » Post

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)

User avatar
rinoux
Member
Posts: 184
Joined: Tue Dec 27, 2011 12:15

by rinoux » Post

quick bed texture... same size as mincraft one.

Image

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

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.

User avatar
rinoux
Member
Posts: 184
Joined: Tue Dec 27, 2011 12:15

by rinoux » Post

what about this recipe:

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

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

rinoux wrote:what about this recipe:

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

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

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.

User avatar
rinoux
Member
Posts: 184
Joined: Tue Dec 27, 2011 12:15

by rinoux » Post

Image

Is that correct ?

[Edit] Wool ? from amimal's mod's sheep
Last edited by rinoux on Wed Jan 25, 2012 01:56, edited 1 time in total.

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

rinoux wrote:Image

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

User avatar
xyz
Member
Posts: 450
Joined: Thu Nov 10, 2011 14:25

by xyz » Post

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.

User avatar
celeron55
Administrator
Posts: 532
Joined: Tue Apr 19, 2011 10:10
GitHub: celeron55
IRC: celeron55

by celeron55 » Post

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.

User avatar
rinoux
Member
Posts: 184
Joined: Tue Dec 27, 2011 12:15

by rinoux » Post

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.

Nemo08
Member
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Post

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!! ((

User avatar
xyz
Member
Posts: 450
Joined: Thu Nov 10, 2011 14:25

by xyz » Post

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.

Nemo08
Member
Posts: 132
Joined: Mon Dec 26, 2011 04:59

by Nemo08 » Post

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!

rahonejm
Member
Posts: 88
Joined: Wed Dec 28, 2011 01:58
Location: Brazil

by rahonejm » Post

We never get so close of beds in minetest! xD
Sorry for possible language mistakes

User avatar
Calinou
Moderator
Posts: 3169
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou
Location: Troyes, France
Contact:

by Calinou » Post

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. :)

User avatar
sdzen
Member
Posts: 1170
Joined: Fri Aug 05, 2011 22:33
Location: Paradise (your not allowed)

by sdzen » Post

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

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

sdzen wrote:bed roll on the gorund could just be a flat thing like rails! :)
e.g. japanese beds.

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

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.

darian_gossman
New member
Posts: 2
Joined: Tue Oct 18, 2011 00:52

by darian_gossman » Post

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.

bulletrulz
Member
Posts: 66
Joined: Fri Dec 23, 2011 18:59

by bulletrulz » Post

WHERE IS THE DL LINK !!??

randomproof
Member
Posts: 214
Joined: Thu Nov 17, 2011 06:31
Location: California, USA

by randomproof » Post

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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 18 guests