From e13f481b36590f95baf56deba938c98f21c44ff6 Mon Sep 17 00:00:00 2001 From: Niklp Date: Sun, 15 Sep 2024 15:30:07 +0200 Subject: [PATCH 1/2] Add `player_monoids` support (*sometimes* broken for whatever reason, see xkcd#1739) --- .luacheckrc | 1 + homedecor_seating/init.lua | 34 +++++++++++++++++++++++++--------- homedecor_seating/mod.conf | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index ee964473..f4c7d9ae 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -41,4 +41,5 @@ read_globals = { "doors", "i3", "xcompat", + "player_monoids" } \ No newline at end of file diff --git a/homedecor_seating/init.lua b/homedecor_seating/init.lua index cec447f4..84bb240e 100644 --- a/homedecor_seating/init.lua +++ b/homedecor_seating/init.lua @@ -3,6 +3,7 @@ local S = minetest.get_translator("homedecor_seating") local modpath = minetest.get_modpath("homedecor_seating") +local has_player_monoids = minetest.get_modpath("player_monoids") lrfurn = {} @@ -85,7 +86,8 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) return itemstack end - if physics_cache[clicker:get_player_name()] then + local name = clicker:get_player_name() + if physics_cache[name] then --already sitting lrfurn.stand(clicker) return itemstack end @@ -123,26 +125,40 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) if not pstatus then sit_pos = spos end end if not sit_pos then - minetest.chat_send_player(clicker:get_player_name(), "sorry, this seat is currently occupied") + minetest.chat_send_player(name, "sorry, this seat is currently occupied") return itemstack end --seat the player clicker:set_pos(sit_pos) - xcompat.player.player_attached[clicker:get_player_name()] = true + xcompat.player.player_attached[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}) + if has_player_monoids then + physics_cache[name] = true + player_monoids.speed:add_change(clicker, 0, "homedecor_seating:sit") + player_monoids.jump:add_change(clicker, 0, "homedecor_seating:sit") + player_monoids.gravity:add_change(clicker, 0, "homedecor_seating:sit") + else + physics_cache[name] = table.copy(clicker:get_physics_override()) + clicker:set_physics_override({speed = 0, jump = 0, gravity = 0}) + end 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()]) - physics_cache[clicker:get_player_name()] = nil + local name = clicker:get_player_name() + xcompat.player.player_attached[name] = false + if physics_cache[name] then + if has_player_monoids then + player_monoids.speed:del_change(clicker, "homedecor_seating:sit") + player_monoids.jump:del_change(clicker, "homedecor_seating:sit") + player_monoids.gravity:del_change(clicker, "homedecor_seating:sit") + else + clicker:set_physics_override(physics_cache[name]) + end + physics_cache[name] = nil else --in case this is called and the cache is empty clicker:set_physics_override({speed = 1, jump = 1, gravity = 1}) end diff --git a/homedecor_seating/mod.conf b/homedecor_seating/mod.conf index 5d17db39..d0b057fe 100644 --- a/homedecor_seating/mod.conf +++ b/homedecor_seating/mod.conf @@ -1,4 +1,4 @@ name = homedecor_seating description = Homedecor mod: seating depends = homedecor_common -optional_depends = screwdriver, wool, default, unifieddyes, basic_materials +optional_depends = screwdriver, wool, default, unifieddyes, basic_materials, player_monoids From 5349998e467f7b3c4340432b731eb85c782d8f78 Mon Sep 17 00:00:00 2001 From: Niklp Date: Fri, 4 Oct 2024 22:25:55 +0200 Subject: [PATCH 2/2] . --- homedecor_seating/init.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homedecor_seating/init.lua b/homedecor_seating/init.lua index 84bb240e..ab145573 100644 --- a/homedecor_seating/init.lua +++ b/homedecor_seating/init.lua @@ -160,7 +160,13 @@ function lrfurn.stand(clicker) end physics_cache[name] = nil else --in case this is called and the cache is empty - clicker:set_physics_override({speed = 1, jump = 1, gravity = 1}) + if has_player_monoids then + player_monoids.speed:del_change(clicker, "homedecor_seating:sit") + player_monoids.jump:del_change(clicker, "homedecor_seating:sit") + player_monoids.gravity:del_change(clicker, "homedecor_seating:sit") + else + clicker:set_physics_override({speed = 1, jump = 1, gravity = 1}) + end end end