Skip to content

Commit

Permalink
free player when seat is dug
Browse files Browse the repository at this point in the history
  • Loading branch information
wsor4035 committed Nov 7, 2024
1 parent d8ae7a3 commit f8ee689
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
6 changes: 4 additions & 2 deletions homedecor_seating/armchairs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ minetest.register_node(":lrfurn:armchair", {
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

homedecor.register("armchair", {
Expand All @@ -59,7 +60,8 @@ homedecor.register("armchair", {
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

-- crafts
Expand Down
13 changes: 12 additions & 1 deletion homedecor_seating/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats)

xcompat.player.player_attached[name] = true
xcompat.player.set_animation(clicker, "sit", 0)
seated_cache[name] = true
seated_cache[name] = minetest.hash_node_position(pos)

return itemstack
end
Expand All @@ -210,6 +210,17 @@ function lrfurn.stand(clicker)
end
end

function lrfurn.on_seat_destruct(pos) --called when a seat is destroyed
for name, seatpos in pairs(seated_cache) do
if seatpos == minetest.hash_node_position(pos) then
local player = minetest.get_player_by_name(name)
if player then
lrfurn.stand(player)
end
end
end
end

--if the player gets killed in the seat, handle it
minetest.register_on_dieplayer(function(player)
if seated_cache[player:get_player_name()] then
Expand Down
3 changes: 2 additions & 1 deletion homedecor_seating/longsofas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ minetest.register_node(":lrfurn:longsofa", {
on_dig = unifieddyes.on_dig,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 3)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

minetest.register_craft({
Expand Down
18 changes: 12 additions & 6 deletions homedecor_seating/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ homedecor.register("deckchair", {
on_rotate = minetest.get_modpath("screwdriver") and screwdriver.disallow or nil,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

minetest.register_alias("homedecor:deckchair_foot", "homedecor:deckchair")
Expand All @@ -42,7 +43,8 @@ homedecor.register("deckchair_striped_blue", {
on_rotate = minetest.get_modpath("screwdriver") and screwdriver.disallow or nil,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

homedecor.register("simple_bench", {
Expand All @@ -62,7 +64,8 @@ homedecor.register("simple_bench", {
},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

local bl1_sbox = {
Expand Down Expand Up @@ -154,7 +157,8 @@ homedecor.register("kitchen_chair_wood", {
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

homedecor.register("kitchen_chair_padded", {
Expand All @@ -180,7 +184,8 @@ homedecor.register("kitchen_chair_padded", {
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

local ofchairs_sbox = {
Expand Down Expand Up @@ -219,7 +224,8 @@ for _, c in pairs(chairs) do
on_rotate = minetest.get_modpath("screwdriver") and screwdriver.rotate_simple or nil,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 1)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})
end

Expand Down
3 changes: 2 additions & 1 deletion homedecor_seating/sofas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ minetest.register_node(":lrfurn:sofa", {
on_dig = unifieddyes.on_dig,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
return lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, 2)
end
end,
on_destruct = lrfurn.on_seat_destruct,
})

minetest.register_craft({
Expand Down

0 comments on commit f8ee689

Please sign in to comment.