From 94e25c21924cb705c952b5bc58231b88dae2fc1f Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:32:14 -0500 Subject: [PATCH] free player when seat is dug (#84) --- homedecor_seating/armchairs.lua | 6 ++++-- homedecor_seating/init.lua | 13 ++++++++++++- homedecor_seating/longsofas.lua | 3 ++- homedecor_seating/misc.lua | 18 ++++++++++++------ homedecor_seating/sofas.lua | 3 ++- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/homedecor_seating/armchairs.lua b/homedecor_seating/armchairs.lua index 8359c913..2c7d1c3b 100644 --- a/homedecor_seating/armchairs.lua +++ b/homedecor_seating/armchairs.lua @@ -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", { @@ -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 diff --git a/homedecor_seating/init.lua b/homedecor_seating/init.lua index 4f77efd5..c4c0bf9e 100644 --- a/homedecor_seating/init.lua +++ b/homedecor_seating/init.lua @@ -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 @@ -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 diff --git a/homedecor_seating/longsofas.lua b/homedecor_seating/longsofas.lua index e919ef92..4f1c7c96 100644 --- a/homedecor_seating/longsofas.lua +++ b/homedecor_seating/longsofas.lua @@ -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({ diff --git a/homedecor_seating/misc.lua b/homedecor_seating/misc.lua index b5d9bb64..386de67c 100644 --- a/homedecor_seating/misc.lua +++ b/homedecor_seating/misc.lua @@ -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") @@ -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", { @@ -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 = { @@ -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", { @@ -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 = { @@ -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 diff --git a/homedecor_seating/sofas.lua b/homedecor_seating/sofas.lua index 5ee43f61..130f9c58 100644 --- a/homedecor_seating/sofas.lua +++ b/homedecor_seating/sofas.lua @@ -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({