Beds: allow sitting and fix some issues

This commit is contained in:
MoNTE48 2020-04-28 21:22:52 +02:00
parent 9a18320430
commit 6e384c8d79
4 changed files with 61 additions and 23 deletions

View File

@ -7,14 +7,13 @@ Authors of source code
Originally by BlockMen (MIT) Originally by BlockMen (MIT)
Various Minetest developers and contributors (MIT) Various Minetest developers and contributors (MIT)
License of textures: License of textures
-------------------- -------------------
Copyright (C) 2019-2020 MultiCraft Development Team Copyright (C) 2019-2020 MultiCraft Development Team
Graphics in this mod is NOT free and can be used only as part of the official MultiCraft build. Graphics in this mod is NOT free and can be used only as part of the official MultiCraft build.
Allowed to be used in non-official builds ONLY for personal use. Allowed to be used in non-official builds ONLY for personal use.
This mod adds a bed to MultiCraft which allows players to skip the night. This mod adds a bed to MultiCraft which allows players to skip the night.
To sleep, right click on the bed. If playing in singleplayer mode the night gets skipped To sleep, right click on the bed. If playing in singleplayer mode the night gets skipped
immediately. If playing multiplayer you get shown how many other players are in bed too, immediately. If playing multiplayer you get shown how many other players are in bed too,

View File

@ -16,7 +16,7 @@ function beds.register_bed(name, def)
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
stack_max = 1, stack_max = 1,
drop = def.drop or name, drop = def.drop or nil,
groups = def.groups, groups = def.groups,
sounds = def.sounds or default.node_sound_wood_defaults(), sounds = def.sounds or default.node_sound_wood_defaults(),
node_placement_prediction = "", node_placement_prediction = "",
@ -100,8 +100,11 @@ function beds.register_bed(name, def)
}) })
if def.recipe then if def.recipe then
if name:sub(1,1) == ":" then
name = name:sub(2)
end
minetest.register_craft({ minetest.register_craft({
output = name:sub(1, 1):gsub(":", "") .. name:sub(2), output = name,
recipe = def.recipe recipe = def.recipe
}) })
end end

View File

@ -20,6 +20,7 @@ function beds.dyeing(pos, _, clicker, itemstack)
return true return true
end end
return false return false
end end
@ -32,13 +33,17 @@ beds.register_bed("beds:bed", {
mesh = "beds_bed.obj", mesh = "beds_bed.obj",
selectionbox = beds.box, selectionbox = beds.box,
collisionbox = beds.box, collisionbox = beds.box,
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wood", "group:wood", "group:wood"}
},
on_rightclick = beds.dyeing on_rightclick = beds.dyeing
}) })
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",
recipe = "beds:bed_bottom", recipe = "group:bed",
burntime = 12 burntime = 12
}) })

View File

@ -50,7 +50,7 @@ local function check_in_beds(players)
return #players > 0 return #players > 0
end end
local function lay_down(player, pos, bed_pos, state, skip) local function lay_down(player, pos, bed_pos, state, skip, sit)
local name = player:get_player_name() local name = player:get_player_name()
local hud_flags = player:hud_get_flags() local hud_flags = player:hud_get_flags()
@ -58,8 +58,20 @@ local function lay_down(player, pos, bed_pos, state, skip)
return return
end end
if bed_pos then
for _, obj in pairs(minetest.get_objects_inside_radius(bed_pos, 0.5)) do
if obj:is_player() then
local obj_name = obj:get_player_name()
if obj_name ~= name then
minetest.chat_send_player(name, S("This bed is already occupied!"))
return
end
end
end
end
-- stand up -- stand up
if state ~= nil and not state then if state ~= nil and not state and not sit then
local p = beds.pos[name] or nil local p = beds.pos[name] or nil
beds.player[name] = nil beds.player[name] = nil
beds.bed_position[name] = nil beds.bed_position[name] = nil
@ -68,7 +80,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
return return
end end
if p then if p then
player:set_pos(p) player:move_to(p)
end end
-- physics, eye_offset, etc -- physics, eye_offset, etc
@ -78,28 +90,43 @@ local function lay_down(player, pos, bed_pos, state, skip)
player:set_physics_override(1, 1, 1) player:set_physics_override(1, 1, 1)
hud_flags.wielditem = true hud_flags.wielditem = true
player_api.set_animation(player, "stand", 30) player_api.set_animation(player, "stand", 30)
else -- sit or lay down
-- lay down
else
if vector.length(player:get_player_velocity()) > 0 then if vector.length(player:get_player_velocity()) > 0 then
return return
end end
beds.pos[name] = pos beds.pos[name] = pos
beds.bed_position[name] = bed_pos beds.bed_position[name] = bed_pos
beds.player[name] = 1
-- physics, eye_offset, etc -- 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) local yaw, param2 = get_look_yaw(bed_pos)
player:set_look_horizontal(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}
player:set_physics_override(0, 0, 0)
player:set_pos(p)
player_api.player_attached[name] = true player_api.player_attached[name] = true
player:set_physics_override(0, 0, 0)
if sit then
beds.player[name] = 2
player:set_eye_offset({x = 0, y = -7, z = 0}, {x = 0, y = 0, z = 0})
player:move_to({x = bed_pos.x + dir.x / 3.75, y = bed_pos.y, z = bed_pos.z + dir.z / 3.75})
hud_flags.wielditem = true
minetest.after(0.2, function()
if player then
player_api.set_animation(player, "sit", 30)
end
end)
else
beds.player[name] = 1
player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0})
player:move_to({x = bed_pos.x + dir.x / 2, y = bed_pos.y, z = bed_pos.z + dir.z / 2})
hud_flags.wielditem = false hud_flags.wielditem = false
minetest.after(0.2, function()
if player then
player_api.set_animation(player, "lay", 0) player_api.set_animation(player, "lay", 0)
end end
end)
end
end
player:hud_set_flags(hud_flags) player:hud_set_flags(hud_flags)
end end
@ -146,6 +173,9 @@ end
function beds.skip_night() function beds.skip_night()
minetest.set_timeofday(0.23) minetest.set_timeofday(0.23)
if is_sp then
minetest.chat_send_all(S("Good morning."))
end
end end
function beds.on_rightclick(pos, player) function beds.on_rightclick(pos, player)
@ -156,13 +186,14 @@ function beds.on_rightclick(pos, player)
if tod > 0.2 and tod < 0.805 then if tod > 0.2 and tod < 0.805 then
if beds.player[name] then if beds.player[name] then
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
else
lay_down(player, ppos, pos, nil, false, true)
end end
minetest.chat_send_player(name, S("You can only sleep at night."))
return return
end end
-- move to bed -- move to bed
if not beds.player[name] then if not beds.player[name] or beds.player[name] == 2 then
lay_down(player, ppos, pos) lay_down(player, ppos, pos)
beds.set_spawns() -- save respawn positions when entering bed beds.set_spawns() -- save respawn positions when entering bed
else else