2019-05-27 02:02:29 +02:00
|
|
|
-- Home decor seating
|
|
|
|
-- forked from the previous lrfurn mod
|
|
|
|
|
2020-08-05 00:35:08 +02:00
|
|
|
local S = minetest.get_translator("homedecor_seating")
|
2019-05-27 02:02:29 +02:00
|
|
|
local modpath = minetest.get_modpath("homedecor_seating")
|
2017-01-29 22:41:03 +01:00
|
|
|
|
2015-04-07 04:49:46 +02:00
|
|
|
lrfurn = {}
|
|
|
|
|
2017-02-22 22:38:19 +01:00
|
|
|
lrfurn.fdir_to_right = {
|
2015-04-07 04:49:46 +02:00
|
|
|
{ 1, 0 },
|
|
|
|
{ 0, -1 },
|
|
|
|
{ -1, 0 },
|
2017-02-22 22:38:19 +01:00
|
|
|
{ 0, 1 },
|
2015-04-07 04:49:46 +02:00
|
|
|
}
|
|
|
|
|
2017-01-25 10:22:28 +01:00
|
|
|
lrfurn.colors = {
|
2017-01-30 22:46:04 +01:00
|
|
|
"black",
|
|
|
|
"brown",
|
|
|
|
"blue",
|
|
|
|
"cyan",
|
|
|
|
"dark_grey",
|
|
|
|
"dark_green",
|
|
|
|
"green",
|
|
|
|
"grey",
|
|
|
|
"magenta",
|
|
|
|
"orange",
|
|
|
|
"pink",
|
|
|
|
"red",
|
|
|
|
"violet",
|
|
|
|
"white",
|
|
|
|
"yellow",
|
2015-09-23 07:29:06 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 22:38:19 +01:00
|
|
|
function lrfurn.check_right(pos, fdir, long, placer)
|
2015-04-07 04:49:46 +02:00
|
|
|
if not fdir or fdir > 3 then fdir = 0 end
|
|
|
|
|
2020-08-05 00:35:08 +02:00
|
|
|
local pos2 = {
|
|
|
|
x = pos.x + lrfurn.fdir_to_right[fdir+1][1],
|
|
|
|
y = pos.y, z = pos.z + lrfurn.fdir_to_right[fdir+1][2]
|
|
|
|
}
|
|
|
|
local pos3 = {
|
|
|
|
x = pos.x + lrfurn.fdir_to_right[fdir+1][1] * 2,
|
|
|
|
y = pos.y, z = pos.z + lrfurn.fdir_to_right[fdir+1][2] * 2
|
|
|
|
}
|
2015-04-07 04:49:46 +02:00
|
|
|
|
|
|
|
local node2 = minetest.get_node(pos2)
|
2015-07-21 11:08:40 +02:00
|
|
|
if node2 and node2.name ~= "air" then
|
|
|
|
return false
|
|
|
|
elseif minetest.is_protected(pos2, placer:get_player_name()) then
|
|
|
|
if not long then
|
2020-08-05 00:35:08 +02:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), S("Someone else owns the spot where the other end goes!"))
|
2015-07-21 11:08:40 +02:00
|
|
|
else
|
2020-08-05 00:35:08 +02:00
|
|
|
minetest.chat_send_player(placer:get_player_name(),
|
|
|
|
S("Someone else owns the spot where the middle or far end goes!"))
|
2015-07-21 11:08:40 +02:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
2015-04-07 04:49:46 +02:00
|
|
|
|
|
|
|
if long then
|
|
|
|
local node3 = minetest.get_node(pos3)
|
2015-07-21 11:08:40 +02:00
|
|
|
if node3 and node3.name ~= "air" then
|
|
|
|
return false
|
|
|
|
elseif minetest.is_protected(pos3, placer:get_player_name()) then
|
2017-08-12 22:30:46 +02:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), S("Someone else owns the spot where the other end goes!"))
|
2015-07-21 11:08:40 +02:00
|
|
|
return false
|
|
|
|
end
|
2015-04-07 04:49:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-02-22 22:38:19 +01:00
|
|
|
function lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing)
|
|
|
|
local node = minetest.get_node(pos)
|
2018-08-22 11:08:48 +02:00
|
|
|
local colorbits = node.param2 - (node.param2 % 8)
|
2023-09-24 13:19:47 +02:00
|
|
|
local yaw = placer:get_look_horizontal()
|
|
|
|
local dir = minetest.yaw_to_dir(yaw)
|
2017-02-22 22:38:19 +01:00
|
|
|
local fdir = minetest.dir_to_wallmounted(dir)
|
2018-08-22 11:08:48 +02:00
|
|
|
minetest.swap_node(pos, { name = node.name, param2 = fdir+colorbits })
|
2017-02-22 22:38:19 +01:00
|
|
|
end
|
|
|
|
|
2024-09-09 18:11:43 +02:00
|
|
|
local physics_cache = {}
|
|
|
|
|
2022-05-03 21:21:14 +02:00
|
|
|
function lrfurn.sit(pos, node, clicker, itemstack, pointed_thing, seats)
|
|
|
|
if not clicker:is_player() then
|
|
|
|
return itemstack
|
|
|
|
end
|
2024-09-09 18:11:43 +02:00
|
|
|
|
|
|
|
if physics_cache[clicker:get_player_name()] then
|
|
|
|
lrfurn.stand(clicker)
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2022-05-03 21:21:14 +02:00
|
|
|
--conversion table for param2 to dir
|
|
|
|
local p2d = {
|
|
|
|
vector.new(0, 0, 0),
|
|
|
|
vector.new(0, 0, -1),
|
|
|
|
vector.new(0, 0, 1),
|
|
|
|
vector.new(1, 0, 0),
|
|
|
|
vector.new(-1, 0, 0),
|
|
|
|
vector.new(0, 0, 0),
|
|
|
|
vector.new(0, 0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
--generate posible seat positions
|
|
|
|
local valid_seats = {[minetest.hash_node_position(pos)] = pos}
|
|
|
|
if seats > 1 then
|
|
|
|
for i=1,seats-1 do
|
|
|
|
--since this are hardware colored nodes, node.param2 gives us a actual param to get a dir from
|
|
|
|
local npos = vector.add(pos, vector.multiply(p2d[node.param2 % 8], i))
|
|
|
|
valid_seats[minetest.hash_node_position(npos)] = npos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--see if we can find a non occupied seat
|
|
|
|
local sit_pos
|
|
|
|
for hash, spos in pairs(valid_seats) do
|
|
|
|
local pstatus = false
|
|
|
|
for _, ref in pairs(minetest.get_objects_inside_radius(spos, 0.5)) do
|
|
|
|
if ref:is_player() then
|
|
|
|
pstatus = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not pstatus then sit_pos = spos end
|
|
|
|
end
|
|
|
|
if not sit_pos then
|
|
|
|
minetest.chat_send_player(clicker:get_player_name(), "sorry, this seat is currently occupied")
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
--seat the player
|
2022-06-18 10:44:02 +02:00
|
|
|
clicker:set_pos(sit_pos)
|
2024-09-09 18:11:43 +02:00
|
|
|
|
|
|
|
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})
|
|
|
|
|
2022-05-03 21:21:14 +02:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2024-09-09 18:11:43 +02:00
|
|
|
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
|
|
|
|
|
2019-05-27 02:02:29 +02:00
|
|
|
dofile(modpath.."/longsofas.lua")
|
|
|
|
dofile(modpath.."/sofas.lua")
|
|
|
|
dofile(modpath.."/armchairs.lua")
|
|
|
|
dofile(modpath.."/misc.lua")
|