From 9c9a2d3d5e537de87dc2814d76acb11711cfa62a Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:44:29 -0400 Subject: [PATCH 1/2] implment https://github.com/mt-mods/homedecor_modpack/issues/31 - show players sitting in seats --- .luacheckrc | 3 ++- homedecor_seating/init.lua | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 9480ba23..ee964473 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -15,7 +15,8 @@ globals = { "homedecor_doors_and_gates", -- mod-deps - "armor" + "armor", + xcompat = {fields = {"player"}}, } read_globals = { diff --git a/homedecor_seating/init.lua b/homedecor_seating/init.lua index 5639fd6f..7127e362 100644 --- a/homedecor_seating/init.lua +++ b/homedecor_seating/init.lua @@ -78,10 +78,18 @@ function lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing) minetest.swap_node(pos, { name = node.name, param2 = fdir+colorbits }) end +local physics_cache = {} + function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) if not clicker:is_player() then return itemstack end + + if xcompat.player.player_attached[clicker:get_player_name()] then + lrfurn.stand(clicker) + return itemstack + end + --conversion table for param2 to dir local p2d = { vector.new(0, 0, 0), @@ -120,11 +128,25 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) end --seat the player - sit_pos.y = sit_pos.y-0.5 clicker:set_pos(sit_pos) + + xcompat.player.player_attached[clicker:get_player_name()] = true + xcompat.player.set_animation(clicker, "sit", 0) + physics_cache[clicker:get_player_name()] = table.copy(clicker:get_physics_override()) + clicker:set_physics_override({speed = 0, jump = 0, gravity = 0}) + return itemstack end +function lrfurn.stand(clicker) + xcompat.player.player_attached[clicker:get_player_name()] = false + if physics_cache[clicker:get_player_name()] then + clicker:set_physics_override(physics_cache[clicker:get_player_name()]) + else + clicker:set_physics_override({speed = 1, jump = 1, gravity = 1}) + end +end + dofile(modpath.."/longsofas.lua") dofile(modpath.."/sofas.lua") dofile(modpath.."/armchairs.lua") From f02f927f3873b9e199efb72e9e7fe4cc38b740ae Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:55:03 -0400 Subject: [PATCH 2/2] improve things --- homedecor_seating/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homedecor_seating/init.lua b/homedecor_seating/init.lua index 7127e362..11cfc048 100644 --- a/homedecor_seating/init.lua +++ b/homedecor_seating/init.lua @@ -85,7 +85,7 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) return itemstack end - if xcompat.player.player_attached[clicker:get_player_name()] then + if physics_cache[clicker:get_player_name()] then lrfurn.stand(clicker) return itemstack end @@ -142,7 +142,7 @@ function lrfurn.stand(clicker) xcompat.player.player_attached[clicker:get_player_name()] = false if physics_cache[clicker:get_player_name()] then clicker:set_physics_override(physics_cache[clicker:get_player_name()]) - else + else --in case this is called and the cache is empty clicker:set_physics_override({speed = 1, jump = 1, gravity = 1}) end end