blockmen's beds - bedsold is used as a temp dir before removal

master
Jordach 2014-08-07 18:57:33 +01:00
parent c0f5ef338a
commit ec38e32f7e
63 changed files with 671 additions and 254 deletions

6
mods/beds/Changelog.txt Normal file
View File

@ -0,0 +1,6 @@
1.0.1 beta
----------
- Add backwards compatibility with PilzAdam's beds mod
- Fix placement
- Fix small bugs
- Prevent possible crash

View File

@ -1,47 +1,35 @@
===BEDS MOD for MINETEST-C55===
by PilzAdam & thefamilygrog66
Minetest mod "Beds"
===================
by BlockMen (c) 2014
Introduction:
This mods brings beds to Minetest. You can use them to sleep at night
to prevent attacks by evil mobs.
Version: 1.0.1 Beta
How to install:
Unzip the archive an place it in minetest-base-directory/mods/minetest/
if you have a windows client or a linux run-in-place client. If you have
a linux system-wide instalation place it in ~/.minetest/mods/minetest/.
If you want to install this mod only in one world create the folder
worldmods/ in your worlddirectory.
For further information or help see:
http://wiki.minetest.com/wiki/Installing_Mods
About
~~~~~
This mod a bed to Minetest which helps 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.
How to use the mod:
Craft a bed like this:
white wool white wool white wool
stick stick
After placing it anywhere you can go to sleep with a leftklick with your
hand on the bed. If it is night a chatmessage wishs you "Good night" and
you sleep until the next morning. To go outside the bed it is recommended
to hit the bed again with a leftklick (it also works if you just go away
but its not so safe).
After dying the player will respawn at the last bed he has slept.
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.
License:
Sourcecode: WTFPL (see below)
Graphics: WTFPL (see below)
See also:
http://minetest.net/
To craft a bed you need 3 wood and 3 wool and place it in following shape:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
wool wool wool
wood wood wood
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Notice: You can use any color of wood or wool, mixing different is also possible.
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
License of source code, textures: WTFPL
---------------------------------------
(c) Copyright BlockMen (2014)
0. You just DO WHAT THE FUCK YOU WANT TO.
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.

View File

@ -1,2 +1,2 @@
default
wool
wool

View File

@ -1,237 +1,196 @@
beds = {}
beds.player = {}
beds.pos = {}
beds.spawn = {}
local form = "size[8,15;true]"..
"bgcolor[#080808BB; true]"..
"button_exit[2,12;4,0.75;leave;Leave Bed]"
local player_in_bed = 0
local beds_list = {
{ "Red Bed", "red"},
{ "Orange Bed", "orange"},
{ "Yellow Bed", "yellow"},
{ "Green Bed", "green"},
{ "Blue Bed", "blue"},
{ "Violet Bed", "violet"},
{ "Black Bed", "black"},
{ "Grey Bed", "grey"},
{ "White Bed", "white"},
}
for i in ipairs(beds_list) do
local beddesc = beds_list[i][1]
local colour = beds_list[i][2]
-- help functions
minetest.register_node("beds:bed_bottom_"..colour, {
description = beddesc,
drawtype = "nodebox",
tiles = {"beds_bed_top_bottom_"..colour..".png", "deco_wood_oak_planks.png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png"},
paramtype = "light",
paramtype2 = "facedir",
stack_max = 1,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3125, 0.5},
-- legs
{-0.5, -0.5, -0.5, -0.4, 0.0, -0.4},
{0.4, 0.0, -0.4, 0.5, -0.5, -0.5},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.3125, 1.5},
}
},
local function get_look_yaw(pos)
local n = minetest.get_node(pos)
if n.param2 == 1 then
return 7.9, n.param2
elseif n.param2 == 3 then
return 4.75, n.param2
elseif n.param2 == 0 then
return 3.15, n.param2
else
return 6.28, n.param2
end
end
after_place_node = function(pos, placer, itemstack)
local node = minetest.env:get_node(pos)
local p = {x=pos.x, y=pos.y, z=pos.z}
local param2 = node.param2
node.name = "beds:bed_top_"..colour
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if minetest.registered_nodes[minetest.env:get_node(pos).name].buildable_to then
minetest.env:set_node(pos, node)
else
minetest.env:remove_node(p)
return true
end
end,
on_destruct = function(pos)
local node = minetest.env:get_node(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).name == "beds:bed_top_"..colour ) then
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).param2 == param2 ) then
minetest.env:remove_node(pos)
end
end
end,
on_rightclick = function(pos, node, clicker)
if not clicker:is_player() then
return
end
local meta = minetest.env:get_meta(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if clicker:get_player_name() == meta:get_string("player") then
if param2 == 0 then
pos.x = pos.x-1
elseif param2 == 1 then
pos.z = pos.z+1
elseif param2 == 2 then
pos.x = pos.x+1
elseif param2 == 3 then
pos.z = pos.z-1
end
pos.y = pos.y-0.5
clicker:set_physics_override(1, 1, 1)
clicker:setpos(pos)
meta:set_string("player", "")
player_in_bed = player_in_bed-1
elseif meta:get_string("player") == "" then
clicker:set_physics_override(0, 0, 0, false, false)
--pos.y = pos.y-0.75
clicker:setpos(pos)
if param2 == 0 then
clicker:set_look_yaw(math.pi)
elseif param2 == 1 then
clicker:set_look_yaw(0.5*math.pi)
elseif param2 == 2 then
clicker:set_look_yaw(0)
elseif param2 == 3 then
clicker:set_look_yaw(1.5*math.pi)
end
meta:set_string("player", clicker:get_player_name())
player_in_bed = player_in_bed+1
end
local function check_in_beds(players)
local in_bed = beds.player
if not players then
players = minetest.get_connected_players()
end
for n, player in ipairs(players) do
local name = player:get_player_name()
if not in_bed[name] then
return false
end
})
minetest.register_node("beds:bed_top_"..colour, {
drawtype = "nodebox",
tiles = {"beds_bed_top_top_"..colour..".png", "deco_wood_oak_planks.png", "beds_bed_side_top_r_"..colour..".png", "beds_bed_side_top_l_"..colour..".png", "beds_bed_top_front.png", "beds_bed_side_"..colour..".png"},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3125, 0.5},
{-0.4375, 0.3125, 0.1, 0.4375, 0.4375, 0.5},
-- legs
{-0.4, 0.0, 0.4, -0.5, -0.5, 0.5},
{0.5, -0.5, 0.5, 0.4, 0.0, 0.4},
}
},
selection_box = {
type = "fixed",
fixed = {
{0, 0, 0, 0, 0, 0},
}
},
})
minetest.register_alias("beds:bed_"..colour, "beds:bed_bottom_"..colour)
minetest.register_craft({
output = "beds:bed_"..colour,
recipe = {
{"wool:"..colour, "wool:"..colour, "wool:white", },
{"tools:stick", "", "tools:stick", }
}
})
minetest.register_craft({
output = "beds:bed_"..colour,
recipe = {
{"wool:white", "wool:"..colour, "wool:"..colour, },
{"tools:stick", "", "tools:stick", }
}
})
end
return true
end
minetest.register_alias("beds:bed_bottom", "beds:bed_bottom_blue")
minetest.register_alias("beds:bed_top", "beds:bed_top_blue")
minetest.register_alias("beds:bed", "beds:bed_bottom_blue")
local function lay_down(player, pos, bed_pos, state)
local name = player:get_player_name()
local hud_flags = player:hud_get_flags()
beds_player_spawns = {}
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r")
if file then
beds_player_spawns = minetest.deserialize(file:read("*all"))
file:close()
end
local timer = 0
local wait = false
minetest.register_globalstep(function(dtime)
if timer<2 then
timer = timer+dtime
if not player or not name then
return
end
timer = 0
local players = #minetest.get_connected_players()
if players == player_in_bed and players ~= 0 then
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.805 then
if not wait then
minetest.chat_send_all("Good night!!!")
minetest.after(2, function()
minetest.env:set_timeofday(0.23)
wait = false
end)
wait = true
for _,player in ipairs(minetest.get_connected_players()) do
beds_player_spawns[player:get_player_name()] = player:getpos()
end
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "w")
if file then
file:write(minetest.serialize(beds_player_spawns))
file:close()
end
end
-- stand up
if state ~= nil and not state then
local p = beds.pos[name] or nil
if beds.player[name] ~= nil then
beds.player[name] = nil
player_in_bed = player_in_bed - 1
end
if p then
player:setpos(p)
end
-- physics, eye_offset, etc
player:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
player:set_look_yaw(math.random(1, 180)/100)
default.player_attached[name] = false
player:set_physics_override(1, 1, 1)
hud_flags.wielditem = true
default.player_set_animation(player, "stand" , 30)
-- lay down
else
beds.player[name] = 1
beds.pos[name] = pos
player_in_bed = player_in_bed + 1
-- physics, eye_offset, etc
player:set_eye_offset({x=0,y=-13,z=0}, {x=0,y=0,z=0})
local yaw, param2 = get_look_yaw(bed_pos)
player:set_look_yaw(yaw)
local dir = minetest.facedir_to_dir(param2)
local p = {x=bed_pos.x+dir.x/2,y=bed_pos.y,z=bed_pos.z+dir.z/2}
player:set_physics_override(0, 0, 0)
player:setpos(p)
default.player_attached[name] = true
hud_flags.wielditem = false
default.player_set_animation(player, "lay" , 0)
end
player:hud_set_flags(hud_flags)
end
local function update_formspecs(finished)
local ges = #minetest.get_connected_players()
local form_n = ""
if finished then
form_n = form ..
"label[2.7,11; Good morning.]"
else
form_n = form ..
"label[2.2,11;"..tostring(player_in_bed).." of "..tostring(ges).." players are in bed]"
end
for name,_ in pairs(beds.player) do
minetest.show_formspec(name, "beds_form", form_n)
end
end
-- public functions
function beds.kick_players()
for name,_ in pairs(beds.player) do
local player = minetest.get_player_by_name(name)
lay_down(player, nil, nil, false)
end
end
function beds.skip_night()
minetest.set_timeofday(0.23)
beds.set_spawns()
end
function beds.on_rightclick(pos, player)
local name = player:get_player_name()
local ppos = player:getpos()
local tod = minetest.get_timeofday()
if tod > 0.2 and tod < 0.805 then
minetest.chat_send_player(name, "You can only sleep at night.")
return
end
-- move to bed
if not beds.player[name] then
lay_down(player, ppos, pos)
else
lay_down(player, nil, nil, false)
end
update_formspecs(false)
-- skip the night and let all stand up
if check_in_beds() then
minetest.after(2, function()
beds.skip_night()
update_formspecs(true)
beds.kick_players()
end)
end
end
-- callbacks
minetest.register_on_joinplayer(function(player)
beds.read_spawns()
end)
minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
if beds_player_spawns[name] then
player:setpos(beds_player_spawns[name])
local pos = beds.spawn[name] or nil
if pos then
player:setpos(pos)
return true
end
end)
if minetest.setting_get("log_mods") then
minetest.log("action", "beds loaded")
end
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
lay_down(player, nil, nil, false)
beds.player[name] = nil
if check_in_beds() then
minetest.after(2, function()
beds.skip_night()
update_formspecs(true)
beds.kick_players()
end)
end
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "beds_form" then
return
end
if fields.quit or fields.leave then
lay_down(player, nil, nil, false)
update_formspecs(false)
end
end)
-- nodes and respawn function
dofile(minetest.get_modpath("beds").."/nodes.lua")
dofile(minetest.get_modpath("beds").."/spawns.lua")

115
mods/beds/nodes.lua Normal file
View File

@ -0,0 +1,115 @@
-- help functions
local function remove_top(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
local function add_top(pos)
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="beds:bed_top", param2 = n.param2})
return false
end
-- register nodes
minetest.register_node("beds:bed_bottom", {
description = "Bed",
inventory_image = "beds_bed.png",
wield_image = "beds_bed.png",
drawtype = "nodebox",
tiles = {"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"},
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 = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
},
after_place_node = function(pos, placer, itemstack)
return add_top(pos)
end,
on_destruct = function(pos)
remove_top(pos)
end,
on_rightclick = function(pos, node, clicker)
beds.on_rightclick(pos, clicker)
end,
})
minetest.register_node("beds:bed_top", {
drawtype = "nodebox",
tiles = {"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"},
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 = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
},
selection_box = {
type = "fixed",
fixed = {0, 0, 0, 0, 0, 0},
},
})
minetest.register_alias("beds:bed", "beds:bed_bottom")
-- register recipe
minetest.register_craft({
output = "beds:bed",
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")

63
mods/beds/spawns.lua Normal file
View File

@ -0,0 +1,63 @@
local world_path = minetest.get_worldpath()
local org_file = world_path .. "/beds_spawns"
local file = world_path .. "/beds_spawns"
local bkwd = false
local writing = true
-- check for PA's beds mod spawns
local cf = io.open(world_path .. "/beds_player_spawns", "r")
if cf ~= nil then
io.close(cf)
file = world_path .. "/beds_player_spawns"
bkwd = true
end
writing = false
function beds.read_spawns()
while writing do
-- wait until spawns are safed
end
local spawns = beds.spawn
local input = io.open(file, "r")
if input and not bkwd then
repeat
local x = input:read("*n")
if x == nil then
break
end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*l")
spawns[name:sub(2)] = {x = x, y = y, z = z}
until input:read(0) == nil
io.close(input)
elseif input and bkwd then
beds.spawn = minetest.deserialize(input:read("*all"))
input:close()
beds.save_spawns()
os.rename(file, file .. ".backup")
file = org_file
else
spawns = {}
end
end
function beds.save_spawns()
writing = true
local output = io.open(org_file, "w")
for i, v in pairs(beds.spawn) do
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
end
io.close(output)
writing = false
end
function beds.set_spawns()
for name,_ in pairs(beds.player) do
local player = minetest.get_player_by_name(name)
local p = player:getpos()
beds.spawn[name] = p
end
beds.save_spawns()
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

47
mods/bedsold/README.txt Normal file
View File

@ -0,0 +1,47 @@
===BEDS MOD for MINETEST-C55===
by PilzAdam & thefamilygrog66
Introduction:
This mods brings beds to Minetest. You can use them to sleep at night
to prevent attacks by evil mobs.
How to install:
Unzip the archive an place it in minetest-base-directory/mods/minetest/
if you have a windows client or a linux run-in-place client. If you have
a linux system-wide instalation place it in ~/.minetest/mods/minetest/.
If you want to install this mod only in one world create the folder
worldmods/ in your worlddirectory.
For further information or help see:
http://wiki.minetest.com/wiki/Installing_Mods
How to use the mod:
Craft a bed like this:
white wool white wool white wool
stick stick
After placing it anywhere you can go to sleep with a leftklick with your
hand on the bed. If it is night a chatmessage wishs you "Good night" and
you sleep until the next morning. To go outside the bed it is recommended
to hit the bed again with a leftklick (it also works if you just go away
but its not so safe).
After dying the player will respawn at the last bed he has slept.
License:
Sourcecode: WTFPL (see below)
Graphics: WTFPL (see below)
See also:
http://minetest.net/
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

2
mods/bedsold/depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
wool

237
mods/bedsold/init.lua Normal file
View File

@ -0,0 +1,237 @@
local player_in_bed = 0
local beds_list = {
{ "Red Bed", "red"},
{ "Orange Bed", "orange"},
{ "Yellow Bed", "yellow"},
{ "Green Bed", "green"},
{ "Blue Bed", "blue"},
{ "Violet Bed", "violet"},
{ "Black Bed", "black"},
{ "Grey Bed", "grey"},
{ "White Bed", "white"},
}
for i in ipairs(beds_list) do
local beddesc = beds_list[i][1]
local colour = beds_list[i][2]
minetest.register_node("beds:bed_bottom_"..colour, {
description = beddesc,
drawtype = "nodebox",
tiles = {"beds_bed_top_bottom_"..colour..".png", "deco_wood_oak_planks.png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png"},
paramtype = "light",
paramtype2 = "facedir",
stack_max = 1,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3125, 0.5},
-- legs
{-0.5, -0.5, -0.5, -0.4, 0.0, -0.4},
{0.4, 0.0, -0.4, 0.5, -0.5, -0.5},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.3125, 1.5},
}
},
after_place_node = function(pos, placer, itemstack)
local node = minetest.env:get_node(pos)
local p = {x=pos.x, y=pos.y, z=pos.z}
local param2 = node.param2
node.name = "beds:bed_top_"..colour
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if minetest.registered_nodes[minetest.env:get_node(pos).name].buildable_to then
minetest.env:set_node(pos, node)
else
minetest.env:remove_node(p)
return true
end
end,
on_destruct = function(pos)
local node = minetest.env:get_node(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).name == "beds:bed_top_"..colour ) then
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).param2 == param2 ) then
minetest.env:remove_node(pos)
end
end
end,
on_rightclick = function(pos, node, clicker)
if not clicker:is_player() then
return
end
local meta = minetest.env:get_meta(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if clicker:get_player_name() == meta:get_string("player") then
if param2 == 0 then
pos.x = pos.x-1
elseif param2 == 1 then
pos.z = pos.z+1
elseif param2 == 2 then
pos.x = pos.x+1
elseif param2 == 3 then
pos.z = pos.z-1
end
pos.y = pos.y-0.5
clicker:set_physics_override(1, 1, 1)
clicker:setpos(pos)
meta:set_string("player", "")
player_in_bed = player_in_bed-1
elseif meta:get_string("player") == "" then
clicker:set_physics_override(0, 0, 0, false, false)
--pos.y = pos.y-0.75
clicker:setpos(pos)
if param2 == 0 then
clicker:set_look_yaw(math.pi)
elseif param2 == 1 then
clicker:set_look_yaw(0.5*math.pi)
elseif param2 == 2 then
clicker:set_look_yaw(0)
elseif param2 == 3 then
clicker:set_look_yaw(1.5*math.pi)
end
meta:set_string("player", clicker:get_player_name())
player_in_bed = player_in_bed+1
end
end
})
minetest.register_node("beds:bed_top_"..colour, {
drawtype = "nodebox",
tiles = {"beds_bed_top_top_"..colour..".png", "deco_wood_oak_planks.png", "beds_bed_side_top_r_"..colour..".png", "beds_bed_side_top_l_"..colour..".png", "beds_bed_top_front.png", "beds_bed_side_"..colour..".png"},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3125, 0.5},
{-0.4375, 0.3125, 0.1, 0.4375, 0.4375, 0.5},
-- legs
{-0.4, 0.0, 0.4, -0.5, -0.5, 0.5},
{0.5, -0.5, 0.5, 0.4, 0.0, 0.4},
}
},
selection_box = {
type = "fixed",
fixed = {
{0, 0, 0, 0, 0, 0},
}
},
})
minetest.register_alias("beds:bed_"..colour, "beds:bed_bottom_"..colour)
minetest.register_craft({
output = "beds:bed_"..colour,
recipe = {
{"wool:"..colour, "wool:"..colour, "wool:white", },
{"tools:stick", "", "tools:stick", }
}
})
minetest.register_craft({
output = "beds:bed_"..colour,
recipe = {
{"wool:white", "wool:"..colour, "wool:"..colour, },
{"tools:stick", "", "tools:stick", }
}
})
end
minetest.register_alias("beds:bed_bottom", "beds:bed_bottom_blue")
minetest.register_alias("beds:bed_top", "beds:bed_top_blue")
minetest.register_alias("beds:bed", "beds:bed_bottom_blue")
beds_player_spawns = {}
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r")
if file then
beds_player_spawns = minetest.deserialize(file:read("*all"))
file:close()
end
local timer = 0
local wait = false
minetest.register_globalstep(function(dtime)
if timer<2 then
timer = timer+dtime
return
end
timer = 0
local players = #minetest.get_connected_players()
if players == player_in_bed and players ~= 0 then
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.805 then
if not wait then
minetest.chat_send_all("Good night!!!")
minetest.after(2, function()
minetest.env:set_timeofday(0.23)
wait = false
end)
wait = true
for _,player in ipairs(minetest.get_connected_players()) do
beds_player_spawns[player:get_player_name()] = player:getpos()
end
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "w")
if file then
file:write(minetest.serialize(beds_player_spawns))
file:close()
end
end
end
end
end)
minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
if beds_player_spawns[name] then
player:setpos(beds_player_spawns[name])
return true
end
end)
if minetest.setting_get("log_mods") then
minetest.log("action", "beds loaded")
end

View File

Before

Width:  |  Height:  |  Size: 477 B

After

Width:  |  Height:  |  Size: 477 B

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 494 B

View File

Before

Width:  |  Height:  |  Size: 485 B

After

Width:  |  Height:  |  Size: 485 B

View File

Before

Width:  |  Height:  |  Size: 526 B

After

Width:  |  Height:  |  Size: 526 B

View File

Before

Width:  |  Height:  |  Size: 497 B

After

Width:  |  Height:  |  Size: 497 B

View File

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

View File

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 483 B

View File

Before

Width:  |  Height:  |  Size: 477 B

After

Width:  |  Height:  |  Size: 477 B

View File

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 483 B

View File

Before

Width:  |  Height:  |  Size: 507 B

After

Width:  |  Height:  |  Size: 507 B

View File

Before

Width:  |  Height:  |  Size: 498 B

After

Width:  |  Height:  |  Size: 498 B

View File

Before

Width:  |  Height:  |  Size: 493 B

After

Width:  |  Height:  |  Size: 493 B

View File

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

View File

Before

Width:  |  Height:  |  Size: 476 B

After

Width:  |  Height:  |  Size: 476 B

View File

Before

Width:  |  Height:  |  Size: 484 B

After

Width:  |  Height:  |  Size: 484 B

View File

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

View File

Before

Width:  |  Height:  |  Size: 488 B

After

Width:  |  Height:  |  Size: 488 B

View File

Before

Width:  |  Height:  |  Size: 484 B

After

Width:  |  Height:  |  Size: 484 B

View File

Before

Width:  |  Height:  |  Size: 509 B

After

Width:  |  Height:  |  Size: 509 B

View File

Before

Width:  |  Height:  |  Size: 505 B

After

Width:  |  Height:  |  Size: 505 B

View File

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 494 B

View File

Before

Width:  |  Height:  |  Size: 479 B

After

Width:  |  Height:  |  Size: 479 B

View File

Before

Width:  |  Height:  |  Size: 470 B

After

Width:  |  Height:  |  Size: 470 B

View File

Before

Width:  |  Height:  |  Size: 505 B

After

Width:  |  Height:  |  Size: 505 B

View File

Before

Width:  |  Height:  |  Size: 479 B

After

Width:  |  Height:  |  Size: 479 B

View File

Before

Width:  |  Height:  |  Size: 468 B

After

Width:  |  Height:  |  Size: 468 B

View File

Before

Width:  |  Height:  |  Size: 328 B

After

Width:  |  Height:  |  Size: 328 B

View File

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

View File

Before

Width:  |  Height:  |  Size: 330 B

After

Width:  |  Height:  |  Size: 330 B

View File

Before

Width:  |  Height:  |  Size: 319 B

After

Width:  |  Height:  |  Size: 319 B

View File

Before

Width:  |  Height:  |  Size: 362 B

After

Width:  |  Height:  |  Size: 362 B

View File

Before

Width:  |  Height:  |  Size: 361 B

After

Width:  |  Height:  |  Size: 361 B

View File

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 351 B

View File

Before

Width:  |  Height:  |  Size: 331 B

After

Width:  |  Height:  |  Size: 331 B

View File

Before

Width:  |  Height:  |  Size: 302 B

After

Width:  |  Height:  |  Size: 302 B

View File

Before

Width:  |  Height:  |  Size: 442 B

After

Width:  |  Height:  |  Size: 442 B

View File

Before

Width:  |  Height:  |  Size: 455 B

After

Width:  |  Height:  |  Size: 455 B

View File

Before

Width:  |  Height:  |  Size: 475 B

After

Width:  |  Height:  |  Size: 475 B

View File

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 462 B

View File

Before

Width:  |  Height:  |  Size: 455 B

After

Width:  |  Height:  |  Size: 455 B

View File

Before

Width:  |  Height:  |  Size: 506 B

After

Width:  |  Height:  |  Size: 506 B

View File

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

View File

Before

Width:  |  Height:  |  Size: 497 B

After

Width:  |  Height:  |  Size: 497 B

View File

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 457 B

View File

Before

Width:  |  Height:  |  Size: 449 B

After

Width:  |  Height:  |  Size: 449 B