Update beds

also had to edit in no spawning on protected areas that arent yours, and edited out the physics override, since it messes up 3d_armors speed feature.
This commit is contained in:
Elkien3 2018-01-12 16:45:12 -06:00
parent 18d7e97707
commit c95281a04d
6 changed files with 218 additions and 91 deletions

View File

@ -1,30 +1,26 @@
Minetest Game mod: beds Minetest Game mod: beds
======================= =======================
by BlockMen (c) 2014-2015 See license.txt for license information.
Version: 1.1.1 Authors of source code
----------------------
Originally by BlockMen (MIT)
Various Minetest developers and contributors (MIT)
About Authors of media (textures)
~~~~~ ---------------------------
This mod adds a bed to Minetest which allows to skip the night. To sleep rightclick the bed, if playing BlockMen (CC BY-SA 3.0)
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 This mod adds a bed to Minetest which allows to skip the night.
is set to the beds location and you will respawn there after death. To sleep, rightclick the bed. If playing in singleplayer mode the night gets skipped
You can disable the respawn at beds by setting "enable_bed_respawn = false" in minetest.conf immediately. If playing multiplayer you get shown how many other players are in bed too,
You can also disable the night skip feature by setting "enable_bed_night_skip = false" in minetest.conf or by using if all players are sleeping the night gets skipped. The night skip can be forced if more
the /set command ingame. than 50% of the players are lying in bed and use this option.
Another feature is a controlled respawning. If you have slept in bed (not just lying in
License of source code, textures: WTFPL it) your respawn point is set to the beds location and you will respawn there after
--------------------------------------- death.
(c) Copyright BlockMen (2014-2015) You can disable the respawn at beds by setting "enable_bed_respawn = false" in
minetest.conf.
You can disable the night skip feature by setting "enable_bed_night_skip = false" in
This program is free software. It comes without any warranty, to minetest.conf or by using the /set command in-game.
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,3 +1,27 @@
local reverse = true
local function destruct_bed(pos, n)
local node = minetest.get_node(pos)
local other
if n == 2 then
local dir = minetest.facedir_to_dir(node.param2)
other = vector.subtract(pos, dir)
elseif n == 1 then
local dir = minetest.facedir_to_dir(node.param2)
other = vector.add(pos, dir)
end
if reverse then
reverse = not reverse
minetest.remove_node(other)
minetest.check_for_falling(other)
else
reverse = not reverse
end
end
function beds.register_bed(name, def) function beds.register_bed(name, def)
minetest.register_node(name .. "_bottom", { minetest.register_node(name .. "_bottom", {
description = def.description, description = def.description,
@ -9,8 +33,8 @@ function beds.register_bed(name, def)
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
stack_max = 1, stack_max = 1,
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 1}, groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 1},
sounds = default.node_sound_wood_defaults(), sounds = def.sounds or default.node_sound_wood_defaults(),
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = def.nodebox.bottom, fixed = def.nodebox.bottom,
@ -20,37 +44,65 @@ function beds.register_bed(name, def)
fixed = def.selectionbox, fixed = def.selectionbox,
}, },
after_place_node = function(pos, placer, itemstack) on_place = function(itemstack, placer, pointed_thing)
local n = minetest.get_node_or_nil(pos) local under = pointed_thing.under
if not n or not n.param2 then local node = minetest.get_node(under)
minetest.remove_node(pos) local udef = minetest.registered_nodes[node.name]
return true if udef and udef.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end end
local dir = minetest.facedir_to_dir(n.param2)
local p = vector.add(pos, dir) local pos
local n2 = minetest.get_node_or_nil(p) if minetest.registered_items[minetest.get_node(under).name].buildable_to then
local def = n2 and minetest.registered_items[n2.name] pos = under
if not def or not def.buildable_to then else
minetest.remove_node(pos) pos = pointed_thing.above
return true
end end
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
return false if minetest.is_protected(pos, placer:get_player_name()) and
not minetest.check_player_privs(placer, "protection_bypass") then
minetest.record_protection_violation(pos, placer:get_player_name())
return itemstack
end
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def or not node_def.buildable_to then
return itemstack
end
local dir = minetest.dir_to_facedir(placer:get_look_dir())
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
if minetest.is_protected(botpos, placer:get_player_name()) and
not minetest.check_player_privs(placer, "protection_bypass") then
minetest.record_protection_violation(botpos, placer:get_player_name())
return itemstack
end
local botdef = minetest.registered_nodes[minetest.get_node(botpos).name]
if not botdef or not botdef.buildable_to then
return itemstack
end
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
if not (creative and creative.is_enabled_for
and creative.is_enabled_for(placer:get_player_name())) then
itemstack:take_item()
end
return itemstack
end, end,
on_destruct = function(pos) on_destruct = function(pos)
local n = minetest.get_node_or_nil(pos) destruct_bed(pos, 1)
if not n then return end
local dir = minetest.facedir_to_dir(n.param2)
local p = vector.add(pos, dir)
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, end,
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
beds.on_rightclick(pos, clicker) beds.on_rightclick(pos, clicker)
return itemstack
end, end,
on_rotate = function(pos, node, user, mode, new_param2) on_rotate = function(pos, node, user, mode, new_param2)
@ -70,8 +122,8 @@ function beds.register_bed(name, def)
end end
local newp = vector.add(pos, minetest.facedir_to_dir(new_param2)) local newp = vector.add(pos, minetest.facedir_to_dir(new_param2))
local node3 = minetest.get_node_or_nil(newp) local node3 = minetest.get_node_or_nil(newp)
local def = node3 and minetest.registered_nodes[node3.name] local node_def = node3 and minetest.registered_nodes[node3.name]
if not def or not def.buildable_to then if not node_def or not node_def.buildable_to then
return false return false
end end
if minetest.is_protected(newp, user:get_player_name()) then if minetest.is_protected(newp, user:get_player_name()) then
@ -79,9 +131,10 @@ function beds.register_bed(name, def)
return false return false
end end
node.param2 = new_param2 node.param2 = new_param2
minetest.swap_node(pos, node) -- do not remove_node here - it will trigger destroy_bed()
minetest.remove_node(p) minetest.set_node(p, {name = "air"})
minetest.set_node(newp, {name = node.name:gsub("%_bottom", "_top"), param2 = new_param2}) minetest.set_node(pos, node)
minetest.set_node(newp, {name = name .. "_top", param2 = new_param2})
return true return true
end, end,
}) })
@ -93,12 +146,16 @@ function beds.register_bed(name, def)
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
pointable = false, pointable = false,
groups = {snappy = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 2}, groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 2},
sounds = default.node_sound_wood_defaults(), sounds = def.sounds or default.node_sound_wood_defaults(),
drop = name .. "_bottom",
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = def.nodebox.top, fixed = def.nodebox.top,
}, },
on_destruct = function(pos)
destruct_bed(pos, 2)
end,
}) })
minetest.register_alias(name, name .. "_bottom") minetest.register_alias(name, name .. "_bottom")

View File

@ -88,3 +88,17 @@ beds.register_bed("beds:bed", {
minetest.register_alias("beds:bed_bottom_red", "beds:bed_bottom") minetest.register_alias("beds:bed_bottom_red", "beds:bed_bottom")
minetest.register_alias("beds:bed_top_red", "beds:bed_top") minetest.register_alias("beds:bed_top_red", "beds:bed_top")
-- Fuel
minetest.register_craft({
type = "fuel",
recipe = "beds:fancy_bed_bottom",
burntime = 13,
})
minetest.register_craft({
type = "fuel",
recipe = "beds:bed_bottom",
burntime = 12,
})

View File

@ -1,7 +1,7 @@
local pi = math.pi local pi = math.pi
local player_in_bed = 0 local player_in_bed = 0
local is_sp = minetest.is_singleplayer() local is_sp = minetest.is_singleplayer()
local enable_respawn = minetest.setting_getbool("enable_bed_respawn") local enable_respawn = minetest.settings:get_bool("enable_bed_respawn")
if enable_respawn == nil then if enable_respawn == nil then
enable_respawn = true enable_respawn = true
end end
@ -22,7 +22,7 @@ local function get_look_yaw(pos)
end end
local function is_night_skip_enabled() local function is_night_skip_enabled()
local enable_night_skip = minetest.setting_getbool("enable_bed_night_skip") local enable_night_skip = minetest.settings:get_bool("enable_bed_night_skip")
if enable_night_skip == nil then if enable_night_skip == nil then
enable_night_skip = true enable_night_skip = true
end end
@ -70,7 +70,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- physics, eye_offset, etc -- physics, eye_offset, etc
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) 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) player:set_look_horizontal(math.random(1, 180) / 100)
default.player_attached[name] = false default.player_attached[name] = false
-- player:set_physics_override(1, 1, 1) -- player:set_physics_override(1, 1, 1)
hud_flags.wielditem = true hud_flags.wielditem = true
@ -85,7 +85,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- physics, eye_offset, etc -- physics, eye_offset, etc
player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0}) player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0})
local yaw, param2 = get_look_yaw(bed_pos) local yaw, param2 = get_look_yaw(bed_pos)
player:set_look_yaw(yaw) player:set_look_horizontal(yaw)
local dir = minetest.facedir_to_dir(param2) 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} 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:set_physics_override(0, 0, 0)
@ -100,7 +100,7 @@ end
local function update_formspecs(finished) local function update_formspecs(finished)
local ges = #minetest.get_connected_players() local ges = #minetest.get_connected_players()
local form_n = "" local form_n
local is_majority = (ges / 2) < player_in_bed local is_majority = (ges / 2) < player_in_bed
if finished then if finished then
@ -130,7 +130,6 @@ end
function beds.skip_night() function beds.skip_night()
minetest.set_timeofday(0.23) minetest.set_timeofday(0.23)
beds.set_spawns()
end end
function beds.on_rightclick(pos, player) function beds.on_rightclick(pos, player)
@ -149,6 +148,7 @@ function beds.on_rightclick(pos, player)
-- move to bed -- move to bed
if not beds.player[name] then if not beds.player[name] then
lay_down(player, ppos, pos) lay_down(player, ppos, pos)
beds.set_spawns() -- save respawn positions when entering bed
else else
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
end end
@ -173,25 +173,20 @@ end
-- Callbacks -- Callbacks
-- Only register respawn callback if respawn enabled
minetest.register_on_joinplayer(function(player) if enable_respawn then
beds.read_spawns() -- respawn player at bed if enabled and valid position is found
end) minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
-- respawn player at bed if enabled and valid position is found local pos = beds.spawn[name]
minetest.register_on_respawnplayer(function(player) if pos then
if not enable_respawn then if not minetest.is_protected(pos, name) then
return false player:setpos(pos)
end return true
local name = player:get_player_name() end
local pos = beds.spawn[name] or nil
if pos then
if not minetest.is_protected(pos, name) then
player:setpos(pos)
return true
end end
end end)
end) end
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()

60
mods/beds/license.txt Normal file
View File

@ -0,0 +1,60 @@
License of source code
----------------------
The MIT License (MIT)
Copyright (C) 2014-2016 BlockMen
Copyright (C) 2014-2016 Various Minetest developers and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT
Licenses of media (textures)
----------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Copyright (C) 2014-2016 BlockMen
You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by-sa/3.0/

View File

@ -18,8 +18,8 @@ function beds.read_spawns()
repeat repeat
local x = input:read("*n") local x = input:read("*n")
if x == nil then if x == nil then
break break
end end
local y = input:read("*n") local y = input:read("*n")
local z = input:read("*n") local z = input:read("*n")
local name = input:read("*l") local name = input:read("*l")
@ -32,19 +32,21 @@ function beds.read_spawns()
beds.save_spawns() beds.save_spawns()
os.rename(file, file .. ".backup") os.rename(file, file .. ".backup")
file = org_file file = org_file
else
spawns = {}
end end
end end
beds.read_spawns()
function beds.save_spawns() function beds.save_spawns()
if not beds.spawn then if not beds.spawn then
return return
end end
local data = {}
local output = io.open(org_file, "w") local output = io.open(org_file, "w")
for i, v in pairs(beds.spawn) do for k, v in pairs(beds.spawn) do
output:write(v.x .. " " .. v.y .. " " .. v.z .. " " .. i .. "\n") table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, k))
end end
output:write(table.concat(data))
io.close(output) io.close(output)
end end
@ -52,7 +54,10 @@ function beds.set_spawns()
for name,_ in pairs(beds.player) do for name,_ in pairs(beds.player) do
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
local p = player:getpos() local p = player:getpos()
beds.spawn[name] = p -- but don't change spawn location if borrowing a bed
if not minetest.is_protected(p, name) then
beds.spawn[name] = p
end
end end
beds.save_spawns() beds.save_spawns()
end end