diff --git a/homedecor_seating/init.lua b/homedecor_seating/init.lua index 1166afb1..a5f0977a 100644 --- a/homedecor_seating/init.lua +++ b/homedecor_seating/init.lua @@ -79,6 +79,7 @@ function lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing) end local seated_cache = {} +local offset_cache = {} minetest.register_entity("homedecor_seating:seat", { initial_properties = { @@ -161,6 +162,7 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) --see if we can find a non occupied seat local sit_pos + local sit_hash for hash, spos in pairs(valid_seats) do local pstatus = false for _, ref in pairs(minetest.get_objects_inside_radius(spos, 0.5)) do @@ -168,7 +170,10 @@ function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats) pstatus = true end end - if not pstatus then sit_pos = spos end + if not pstatus then + sit_pos = spos + sit_hash = hash + end end if not sit_pos then minetest.chat_send_player(name, "sorry, this seat is currently occupied") @@ -194,6 +199,9 @@ 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] = minetest.hash_node_position(pos) + if seated_cache[name] ~= sit_hash then + offset_cache[name] = core.hash_node_position(vector.subtract(pos, sit_pos)) + end return itemstack end @@ -207,6 +215,7 @@ function lrfurn.stand(clicker) attached_to:remove() --removing also detaches end seated_cache[name] = nil + offset_cache[name] = nil end end @@ -231,7 +240,12 @@ function lrfurn.on_seat_movenode(from_pos, to_pos) local attached_to = player:get_attach() -- Check, clearobjects might have been called, etc if attached_to then - attached_to:set_pos(to_pos) + if offset_cache[name] then + attached_to:set_pos(vector.subtract(to_pos, + core.get_position_from_hash(offset_cache[name]))) + else + attached_to:set_pos(to_pos) + end seated_cache[name] = hashed_to_pos end end