[Mod] Quick bed mod

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

[Mod] Quick bed mod

by randomproof » 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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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 » Tue Jan 24, 2012 22:30

texture dimension ?
 

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

by randomproof » Tue Jan 24, 2012 22:53

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 » Tue Jan 24, 2012 22:57

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 » Tue Jan 24, 2012 23:30

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

Image
 

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

by randomproof » Wed Jan 25, 2012 01:04

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 » Wed Jan 25, 2012 01:18

what about this recipe:

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

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

by randomproof » Wed Jan 25, 2012 01:35

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

by randomproof » Wed Jan 25, 2012 01:37

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 » Wed Jan 25, 2012 01:54

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

by randomproof » Wed Jan 25, 2012 05:07

rinoux wrote:Image

Is that correct ?

No, generally textures are square. Look in data/default/textures for examples.
 

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

by xyz » Wed Jan 25, 2012 06:49

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.
 

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Wed Jan 25, 2012 08:27

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 » Wed Jan 25, 2012 08:27

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 » Wed Jan 25, 2012 08:54

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: 449
Joined: Thu Nov 10, 2011 14:25

by xyz » Wed Jan 25, 2012 08:58

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 » Wed Jan 25, 2012 09:00

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

by rahonejm » Wed Jan 25, 2012 09:36

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

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Wed Jan 25, 2012 12:26

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

by sdzen » Wed Jan 25, 2012 15:11

bed roll on the gorund could just be a flat thing like rails! :)
[h]Zen S.D.[/h] 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
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Wed Jan 25, 2012 15:42

sdzen wrote:bed roll on the gorund could just be a flat thing like rails! :)


e.g. japanese beds.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

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

by randomproof » Wed Jan 25, 2012 16:18

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 » Sun Jan 29, 2012 08:02

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 » Thu Feb 09, 2012 23:56

WHERE IS THE DL LINK !!??
 

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

by randomproof » Fri Feb 10, 2012 00:20

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.
 

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

by bulletrulz » Fri Feb 10, 2012 00:55

randomproof wrote:
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.

can u just help im kinda of a noob
 

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

by randomproof » Fri Feb 10, 2012 17:11

bulletrulz wrote:can u just help im kinda of a noob

Go to your mods folder and create a new folder called "beds" next create a new file in that folder called "init.lua" in that file you paste the code from the first post. Lastly, you have to change the node to use an already available texture or make your own. See the box below to see what you have to change:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("beds:bed", {
    description = "Bed",
    tile_images = {"beds_bed.png"},    <-- Change this to an already available texture or make your own
    is_ground_content = true,
    material = minetest.digprop_woodlike(0.75),
})
 

User avatar
csbeav
New member
 
Posts: 9
Joined: Sun Feb 05, 2012 02:36

by csbeav » Sun Feb 12, 2012 03:40

Someone earlier has built a mod for ladders. These ladders do not occupy a whole cube but only what is necessary for a ladder. Could this code be used to help shape the bed?
 

User avatar
dannydark
Member
 
Posts: 428
Joined: Fri Aug 12, 2011 21:28

by dannydark » Sun Feb 12, 2012 13:54

To get MC style beds I think your going to have to wait until Kahrl's new collision system is done and merged upstream.
 

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

by randomproof » Mon Feb 13, 2012 19:51

csbeav wrote:Someone earlier has built a mod for ladders. These ladders do not occupy a whole cube but only what is necessary for a ladder. Could this code be used to help shape the bed?

No. There are only a few draw types available.
 

Next

Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 51 guests

cron