mirror of
https://github.com/mt-mods/homedecor_modpack.git
synced 2024-12-23 08:20:21 +01:00
cache seat offset for sofas
This commit is contained in:
parent
cc9c7d49fe
commit
bc9945c2bb
@ -79,6 +79,7 @@ function lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local seated_cache = {}
|
local seated_cache = {}
|
||||||
|
local offset_cache = {}
|
||||||
|
|
||||||
minetest.register_entity("homedecor_seating:seat", {
|
minetest.register_entity("homedecor_seating:seat", {
|
||||||
initial_properties = {
|
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
|
--see if we can find a non occupied seat
|
||||||
local sit_pos
|
local sit_pos
|
||||||
|
local sit_hash
|
||||||
for hash, spos in pairs(valid_seats) do
|
for hash, spos in pairs(valid_seats) do
|
||||||
local pstatus = false
|
local pstatus = false
|
||||||
for _, ref in pairs(minetest.get_objects_inside_radius(spos, 0.5)) do
|
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
|
pstatus = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not pstatus then sit_pos = spos end
|
if not pstatus then
|
||||||
|
sit_pos = spos
|
||||||
|
sit_hash = hash
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not sit_pos then
|
if not sit_pos then
|
||||||
minetest.chat_send_player(name, "sorry, this seat is currently occupied")
|
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.player_attached[name] = true
|
||||||
xcompat.player.set_animation(clicker, "sit", 0)
|
xcompat.player.set_animation(clicker, "sit", 0)
|
||||||
seated_cache[name] = minetest.hash_node_position(pos)
|
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
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -207,6 +215,7 @@ function lrfurn.stand(clicker)
|
|||||||
attached_to:remove() --removing also detaches
|
attached_to:remove() --removing also detaches
|
||||||
end
|
end
|
||||||
seated_cache[name] = nil
|
seated_cache[name] = nil
|
||||||
|
offset_cache[name] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -231,7 +240,12 @@ function lrfurn.on_seat_movenode(from_pos, to_pos)
|
|||||||
local attached_to = player:get_attach()
|
local attached_to = player:get_attach()
|
||||||
-- Check, clearobjects might have been called, etc
|
-- Check, clearobjects might have been called, etc
|
||||||
if attached_to then
|
if attached_to then
|
||||||
|
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)
|
attached_to:set_pos(to_pos)
|
||||||
|
end
|
||||||
seated_cache[name] = hashed_to_pos
|
seated_cache[name] = hashed_to_pos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user