Skip to content

Commit

Permalink
Add player_monoids support (#80)
Browse files Browse the repository at this point in the history
* Add `player_monoids` support (*sometimes* broken for whatever reason, see xkcd#1739)

* .
  • Loading branch information
Niklp09 authored Oct 20, 2024
1 parent 00ee805 commit 79416b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ read_globals = {
"doors",
"i3",
"xcompat",
"player_monoids"
}
42 changes: 32 additions & 10 deletions homedecor_seating/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion homedecor_seating/mod.conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 79416b9

Please sign in to comment.