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)
Various Minetest developers and contributors (MIT)
License of textures:
--------------------
License of textures
-------------------
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.
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.
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,

View File

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

View File

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

View File

@ -50,7 +50,7 @@ local function check_in_beds(players)
return #players > 0
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 hud_flags = player:hud_get_flags()
@ -58,17 +58,29 @@ local function lay_down(player, pos, bed_pos, state, skip)
return
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
if state ~= nil and not state then
if state ~= nil and not state and not sit then
local p = beds.pos[name] or nil
beds.player[name] = nil
beds.player[name] = nil
beds.bed_position[name] = nil
-- skip here to prevent sending player specific changes (used for leaving players)
if skip then
return
end
if p then
player:set_pos(p)
player:move_to(p)
end
-- physics, eye_offset, etc
@ -77,28 +89,43 @@ local function lay_down(player, pos, bed_pos, state, skip)
player_api.player_attached[name] = false
player:set_physics_override(1, 1, 1)
hud_flags.wielditem = true
player_api.set_animation(player, "stand", 30)
-- lay down
else
player_api.set_animation(player, "stand", 30)
else -- sit or lay down
if vector.length(player:get_player_velocity()) > 0 then
return
end
beds.pos[name] = pos
beds.bed_position[name] = bed_pos
beds.player[name] = 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_horizontal(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:set_pos(p)
player_api.player_attached[name] = true
hud_flags.wielditem = false
player_api.set_animation(player, "lay", 0)
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
minetest.after(0.2, function()
if player then
player_api.set_animation(player, "lay", 0)
end
end)
end
end
player:hud_set_flags(hud_flags)
@ -146,6 +173,9 @@ end
function beds.skip_night()
minetest.set_timeofday(0.23)
if is_sp then
minetest.chat_send_all(S("Good morning."))
end
end
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 beds.player[name] then
lay_down(player, nil, nil, false)
else
lay_down(player, ppos, pos, nil, false, true)
end
minetest.chat_send_player(name, S("You can only sleep at night."))
return
end
-- 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)
beds.set_spawns() -- save respawn positions when entering bed
else