Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements https://github.com/mt-mods/homedecor_modpack/issues/31 - show players sitting in seats #76

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ globals = {
"homedecor_doors_and_gates",

-- mod-deps
"armor"
"armor",
xcompat = {fields = {"player"}},
}

read_globals = {
Expand Down
24 changes: 23 additions & 1 deletion homedecor_seating/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 physics_cache[clicker:get_player_name()] then
lrfurn.stand(clicker)
return itemstack
end

--conversion table for param2 to dir
local p2d = {
vector.new(0, 0, 0),
Expand Down Expand Up @@ -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 --in case this is called and the cache is empty
clicker:set_physics_override({speed = 1, jump = 1, gravity = 1})
end
end

dofile(modpath.."/longsofas.lua")
dofile(modpath.."/sofas.lua")
dofile(modpath.."/armchairs.lua")
Expand Down