From 3fb0420ebe4ae200de8f77dd4939e983fdbc3711 Mon Sep 17 00:00:00 2001 From: Maksim Date: Thu, 28 Oct 2021 17:03:13 +0200 Subject: [PATCH] Beds: update --- .luacheckrc | 1 + files/furniture/beds/README.txt | 3 +- files/furniture/beds/api.lua | 17 ++++- files/furniture/beds/beds.lua | 2 +- files/furniture/beds/depends.txt | 1 + files/furniture/beds/functions.lua | 78 ++++++++++++--------- files/furniture/beds/license.txt | 3 +- files/furniture/beds/textures/beds_red.png | Bin 0 -> 3217 bytes 8 files changed, 68 insertions(+), 37 deletions(-) create mode 100644 files/furniture/beds/textures/beds_red.png diff --git a/.luacheckrc b/.luacheckrc index e7f0b12..9a99c7e 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -28,6 +28,7 @@ read_globals = { "experience", "mobs", "playerphysics", + "node_attacher", "screwdriver", "bonemeal", "sscsm", diff --git a/files/furniture/beds/README.txt b/files/furniture/beds/README.txt index 45591d0..b47b1f0 100644 --- a/files/furniture/beds/README.txt +++ b/files/furniture/beds/README.txt @@ -6,10 +6,11 @@ Authors of source code ---------------------- Originally by BlockMen (MIT) Various Minetest developers and contributors (MIT) +MultiCraft Development Team (MIT) License of textures ------------------- -Copyright (C) 2019-2020 MultiCraft Development Team +Copyright (C) 2019-2021 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. diff --git a/files/furniture/beds/api.lua b/files/furniture/beds/api.lua index d83b30f..cdb7225 100644 --- a/files/furniture/beds/api.lua +++ b/files/furniture/beds/api.lua @@ -1,3 +1,4 @@ +local na_exists = minetest.global_exists("node_attacher") function beds.register_bed(name, def) def.groups = def.groups or {} def.groups.choppy = 2 @@ -20,6 +21,7 @@ function beds.register_bed(name, def) groups = def.groups, sounds = def.sounds or default.node_sound_wood_defaults(), node_placement_prediction = "", + node_dig_prediction = "", selection_box = { type = "fixed", fixed = def.selectionbox @@ -29,6 +31,7 @@ function beds.register_bed(name, def) fixed = def.collisionbox }, on_rotate = false, + attach_shift = {x = 0, y = 0.6, z = -1}, on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under @@ -96,7 +99,19 @@ function beds.register_bed(name, def) return itemstack end, - can_dig = beds.can_dig + on_punch = function(_, _, clicker) + if na_exists then + node_attacher.stand(clicker) + end + end, + + can_dig = beds.can_dig, + + after_destruct = function(pos) + if na_exists then + node_attacher.destruct(pos) + end + end }) if def.recipe then diff --git a/files/furniture/beds/beds.lua b/files/furniture/beds/beds.lua index 8488863..1d8e493 100644 --- a/files/furniture/beds/beds.lua +++ b/files/furniture/beds/beds.lua @@ -28,7 +28,7 @@ beds.register_bed("beds:bed", { description = beds.S"Bed", inventory_image = "beds_bed_inv.png", wield_image = "beds_bed_inv.png", - tiles = {"beds_bed.png", "wool_red.png"}, + tiles = {"beds_bed.png", "beds_red.png"}, mesh = "beds_bed.b3d", selectionbox = beds.box, collisionbox = beds.box, diff --git a/files/furniture/beds/depends.txt b/files/furniture/beds/depends.txt index 4ad96d5..c06a9dc 100644 --- a/files/furniture/beds/depends.txt +++ b/files/furniture/beds/depends.txt @@ -1 +1,2 @@ default +node_attacher? diff --git a/files/furniture/beds/functions.lua b/files/furniture/beds/functions.lua index 022c941..d710d13 100644 --- a/files/furniture/beds/functions.lua +++ b/files/furniture/beds/functions.lua @@ -10,6 +10,7 @@ if enable_night_skip == nil then enable_night_skip = true end local hunger_exists = minetest.global_exists("hunger") +local na_exists = minetest.global_exists("node_attacher") -- Helper functions @@ -45,7 +46,7 @@ local function check_in_beds(players) return #players > 0 end -local function lay_down(player, pos, bed_pos, state, skip, sit) +local function lay_down(player, pos, bed_pos, state, skip) local name = player:get_player_name() local hud_flags = player:hud_get_flags() @@ -54,26 +55,35 @@ local function lay_down(player, pos, bed_pos, state, skip, sit) end -- stand up - if state ~= nil and not state and not sit then - local p = beds.pos[name] or nil - beds.player[name] = nil + if state ~= nil and not state then + if not beds.player[name] then + -- player not in bed, do nothing + return false + end beds.bed_position[name] = nil -- skip here to prevent sending player specific changes (used for leaving players) if skip then return end + local p = beds.pos[name] or nil if p then - player:move_to(p) + player:set_pos(p) end -- physics, eye_offset, etc + -- local physics_override = beds.player[name].physics_override + beds.player[name] = nil + --[[player:set_physics_override({ + speed = physics_override.speed, + jump = physics_override.jump, + gravity = physics_override.gravity + })]] player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0}) player:set_look_horizontal(math.random(1, 180) / 100) player_api.player_attached[name] = false - player:set_physics_override(1, 1, 1) hud_flags.wielditem = true player_api.set_animation(player, "stand", 30) - else -- sit or lay down + else -- lay down -- Check if bed is occupied for other_name, other_pos in pairs(beds.bed_position) do if name ~= other_name and @@ -94,37 +104,30 @@ local function lay_down(player, pos, bed_pos, state, skip, sit) return false end + if beds.player[name] then + -- player already in bed, do nothing + return false + end + beds.pos[name] = pos beds.bed_position[name] = bed_pos + -- beds.player[name] = {physics_override = player:get_physics_override()} + beds.player[name] = true -- 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) + -- player:set_physics_override({speed = 0, jump = 0, gravity = 0}) + player:set_pos({x = bed_pos.x + dir.x / 2, y = bed_pos.y, z = bed_pos.z + dir.z / 2}) 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:set_pos({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:set_pos({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 + hud_flags.wielditem = false + minetest.after(0.2, function() + if player then + player_api.set_animation(player, "lay", 0) + end + end) end player:hud_set_flags(hud_flags) @@ -195,11 +198,15 @@ function beds.on_rightclick(pos, player) local ppos = player:get_pos() local tod = minetest.get_timeofday() + if na_exists and node_attacher.stand(player) then + return false + end + 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) + elseif na_exists then + node_attacher.sit(pos, minetest.get_node(pos), player) end return end @@ -215,13 +222,18 @@ function beds.on_rightclick(pos, player) update_formspecs(false) end -function beds.can_dig(bed_pos) +function beds.can_dig(bed_pos, player) -- Check all players in bed which one is at the expected position for _, player_bed_pos in pairs(beds.bed_position) do if vector.equals(bed_pos, player_bed_pos) then return false end end + + if na_exists then + return node_attacher.can_dig(bed_pos, player) + end + return true end diff --git a/files/furniture/beds/license.txt b/files/furniture/beds/license.txt index 6e75294..0c613a5 100644 --- a/files/furniture/beds/license.txt +++ b/files/furniture/beds/license.txt @@ -4,6 +4,7 @@ License of source code The MIT License (MIT) Copyright (C) 2014-2016 BlockMen Copyright (C) 2014-2016 Various Minetest developers and contributors +Copyright (C) 2016-2021 MultiCraft Development Team 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 @@ -26,7 +27,7 @@ https://opensource.org/licenses/MIT License of textures ------------------- -Copyright (C) 2019-2020 MultiCraft Development Team +Copyright (C) 2019-2021 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. diff --git a/files/furniture/beds/textures/beds_red.png b/files/furniture/beds/textures/beds_red.png new file mode 100644 index 0000000000000000000000000000000000000000..ba4c2b5cc47442d1817cda3d25f047f1188fc853 GIT binary patch literal 3217 zcmV;C3~uv@P)j zC!GKxp8z7E03)IRB%c5ypa3JJ03@&gC!+u)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