Skip to content

Commit

Permalink
Add beds
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Feb 24, 2015
1 parent 3b526a7 commit edb02e9
Show file tree
Hide file tree
Showing 24 changed files with 564 additions and 0 deletions.
36 changes: 36 additions & 0 deletions game_api.txt
Expand Up @@ -24,6 +24,42 @@ The bucket API allows registering new types of buckets for non-default liquids.
"Lava Bucket" -- Bucket description
)

Beds API
--------
beds.register_bed(
"beds:bed", -- Bed name
def: See [#Bed definition] -- Bed definition
)

beds.read_spawns() -- returns a table containing players respawn positions
beds.kick_players() -- forces all players to leave bed
beds.skip_night() -- sets world time to morning and saves respawn position of all players currently sleeping

#Bed definition
---------------
{
description = "Simple Bed",
inventory_image = "beds_bed.png",
wield_image = "beds_bed.png",
tiles = {
bottom = {[Tile definition],
^ the tiles of the bottom part of the bed
},
top = {[Tile definition],
^ the tiles of the bottom part of the bed
}
},
nodebox = {
bottom = regular nodebox, see [Node boxes], -- bottm part of bed
top = regular nodebox, see [Node boxes], -- top part of bed
},
selectionbox = regular nodebox, see [Node boxes], -- for both nodeboxes
recipe = { -- Craft recipe
{"group:wool", "group:wool", "group:wool"},
{"group:wood", "group:wood", "group:wood"}
}
}

Doors API
---------
The doors mod allows modders to register custom doors and trapdoors.
Expand Down
18 changes: 18 additions & 0 deletions mods/beds/Changelog.txt
@@ -0,0 +1,18 @@
1.0.1 beta
----------
- Add backwards compatibility with PilzAdam's beds mod
- Fix placement
- Fix small bugs
- Prevent possible crash

1.1
---
- Add fancy bed model (based on jp's model)
- Add API to register beds
- Allow players always to detach from bed (by donat-b)
- If more than 50% of players want sleep they can skip the night
- Don't show sleep dialog in singleplayer

1.1.1
-----
- Prevent possbile crash by trying to reposition leaving players
45 changes: 45 additions & 0 deletions mods/beds/README.txt
@@ -0,0 +1,45 @@
Minetest mod "Beds"
===================
by BlockMen (c) 2014-2015

Version: 1.1.1

About
~~~~~
This mod adds a bed to Minetest which allows to skip the night. To sleep rightclick the bed, if playing
in singleplayer mode the night gets skipped imideatly. If playing on server you get shown how many other
players are in bed too. If all players are sleeping the night gets skipped aswell. Also the night skip can be forced
if more than 50% of the players are lying in bed and use this option.

Another feature is a controled respawning. If you have slept in bed (not just lying in it) your respawn point
is set to the beds location. If dying you will respawn there.



You can craft two types of beds:


Simple shaped bed:

wool wool wool
wood wood wood

Fancy shaped bed:

wool wool stick
wood wood wood

Notice: You can use any color of wood or wool, mixing different is also possible.


License of source code, textures: WTFPL
---------------------------------------
(c) Copyright BlockMen (2014-2015)



This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://sam.zoy.org/wtfpl/COPYING for more details.
78 changes: 78 additions & 0 deletions mods/beds/api.lua
@@ -0,0 +1,78 @@
function beds.register_bed(name, def)
minetest.register_node(name .. "_bottom", {
description = def.description,
inventory_image = def.inventory_image,
wield_image = def.wield_image,
drawtype = "nodebox",
tiles = def.tiles.bottom,
paramtype = "light",
paramtype2 = "facedir",
stack_max = 1,
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 1},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = def.nodebox.bottom,
},
selection_box = {
type = "fixed",
fixed = def.selectionbox,

},
after_place_node = function(pos, placer, itemstack)
local n = minetest.get_node_or_nil(pos)
if not n or not n.param2 then
minetest.remove_node(pos)
return true
end
local dir = minetest.facedir_to_dir(n.param2)
local p = {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
local n2 = minetest.get_node_or_nil(p)
local def = minetest.registered_items[n2.name] or nil
if not n2 or not def or not def.buildable_to then
minetest.remove_node(pos)
return true
end
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
return false
end,
on_destruct = function(pos)
local n = minetest.get_node_or_nil(pos)
if not n then return end
local dir = minetest.facedir_to_dir(n.param2)
local p = {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
local n2 = minetest.get_node(p)
if minetest.get_item_group(n2.name, "bed") == 2 and n.param2 == n2.param2 then
minetest.remove_node(p)
end
end,
on_rightclick = function(pos, node, clicker)
beds.on_rightclick(pos, clicker)
end,
})

minetest.register_node(name .. "_top", {
drawtype = "nodebox",
tiles = def.tiles.top,
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 2},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = def.nodebox.top,
},
selection_box = {
type = "fixed",
fixed = {0, 0, 0, 0, 0, 0},
},
})

minetest.register_alias(name, name .. "_bottom")

-- register recipe
minetest.register_craft({
output = name,
recipe = def.recipe
})
end
104 changes: 104 additions & 0 deletions mods/beds/beds.lua
@@ -0,0 +1,104 @@
-- fancy shaped bed
beds.register_bed("beds:fancy_bed", {
description = "Fancy Bed",
inventory_image = "beds_bed_fancy.png",
wield_image = "beds_bed_fancy.png",
tiles = {
bottom = {
"beds_bed_top1.png",
"default_wood.png",
"beds_bed_side1.png",
"beds_bed_side1.png^[transformFX",
"default_wood.png",
"beds_bed_foot.png",
},
top = {
"beds_bed_top2.png",
"default_wood.png",
"beds_bed_side2.png",
"beds_bed_side2.png^[transformFX",
"beds_bed_head.png",
"default_wood.png",
}
},
nodebox = {
bottom = {
{-0.5, -0.5, -0.5, -0.375, -0.065, -0.4375},
{0.375, -0.5, -0.5, 0.5, -0.065, -0.4375},
{-0.5, -0.375, -0.5, 0.5, -0.125, -0.4375},
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
{-0.4375, -0.3125, -0.4375, 0.4375, -0.0625, 0.5},
},
top = {
{-0.5, -0.5, 0.4375, -0.375, 0.1875, 0.5},
{0.375, -0.5, 0.4375, 0.5, 0.1875, 0.5},
{-0.5, 0, 0.4375, 0.5, 0.125, 0.5},
{-0.5, -0.375, 0.4375, 0.5, -0.125, 0.5},
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
{-0.4375, -0.3125, -0.5, 0.4375, -0.0625, 0.4375},
}
},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
recipe = {
{"group:wool", "group:wool", "group:stick"},
{"group:wood", "group:wood", "group:wood"},
},
})

-- simple shaped bed
beds.register_bed("beds:bed", {
description = "Simple Bed",
inventory_image = "beds_bed.png",
wield_image = "beds_bed.png",
tiles = {
bottom = {
"beds_bed_top_bottom.png^[transformR90",
"default_wood.png",
"beds_bed_side_bottom_r.png",
"beds_bed_side_bottom_r.png^[transformfx",
"beds_transparent.png",
"beds_bed_side_bottom.png"
},
top = {
"beds_bed_top_top.png^[transformR90",
"default_wood.png",
"beds_bed_side_top_r.png",
"beds_bed_side_top_r.png^[transformfx",
"beds_bed_side_top.png",
"beds_transparent.png",
}
},
nodebox = {
bottom = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
top = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wood", "group:wood", "group:wood"}
},

})

-- aliases for PA's beds mod
minetest.register_alias("beds:bed_bottom_red", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_orange", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_yellow", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_green", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_blue", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_violet", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_black", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_grey", "beds:bed_bottom")
minetest.register_alias("beds:bed_bottom_white", "beds:bed_bottom")

minetest.register_alias("beds:bed_top_red", "beds:bed_top")
minetest.register_alias("beds:bed_top_orange", "beds:bed_top")
minetest.register_alias("beds:bed_top_yellow", "beds:bed_top")
minetest.register_alias("beds:bed_top_green", "beds:bed_top")
minetest.register_alias("beds:bed_top_blue", "beds:bed_top")
minetest.register_alias("beds:bed_top_violet", "beds:bed_top")
minetest.register_alias("beds:bed_top_black", "beds:bed_top")
minetest.register_alias("beds:bed_top_grey", "beds:bed_top")
minetest.register_alias("beds:bed_top_white", "beds:bed_top")
2 changes: 2 additions & 0 deletions mods/beds/depends.txt
@@ -0,0 +1,2 @@
default
wool

0 comments on commit edb02e9

Please sign in to comment.