From 79416b962cdaaca4cb897a95e41315166d07cc5b Mon Sep 17 00:00:00 2001 From: Niklp Date: Sun, 20 Oct 2024 18:24:57 +0200 Subject: [PATCH] Add `player_monoids` support (#80) * Add `player_monoids` support (*sometimes* broken for whatever reason, see xkcd#1739) * . --- .luacheckrc | 1 + homedecor_seating/init.lua | 42 +++++++++++++++++++++++++++++--------- homedecor_seating/mod.conf | 2 +- 3 files changed, 34 insertions(+), 11 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..ab145573 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,28 +125,48 @@ 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}) + 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 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