2023-06-30 16:38:27 +03:00
|
|
|
local mod_playerphysics = minetest.get_modpath("playerphysics") ~= nil
|
2023-06-30 16:51:06 +03:00
|
|
|
local mod_player_api = minetest.get_modpath("player_api") ~= nil
|
2023-06-30 16:38:27 +03:00
|
|
|
|
2016-02-12 17:00:44 +03:00
|
|
|
local function top_face(pointed_thing)
|
2016-02-28 22:13:40 +03:00
|
|
|
if not pointed_thing then return end
|
2016-02-12 17:00:44 +03:00
|
|
|
return pointed_thing.above.y > pointed_thing.under.y
|
|
|
|
end
|
|
|
|
|
|
|
|
function xdecor.sit(pos, node, clicker, pointed_thing)
|
2023-06-30 16:51:06 +03:00
|
|
|
if not mod_player_api then return end
|
2016-02-12 17:00:44 +03:00
|
|
|
if not top_face(pointed_thing) then return end
|
2016-02-28 23:07:43 +03:00
|
|
|
local player_name = clicker:get_player_name()
|
2016-02-12 17:00:44 +03:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
2023-06-30 16:43:02 +03:00
|
|
|
local vel = clicker:get_velocity()
|
2016-02-12 17:00:44 +03:00
|
|
|
local ctrl = clicker:get_player_control()
|
|
|
|
|
2016-02-28 23:07:43 +03:00
|
|
|
for _, obj in pairs(objs) do
|
|
|
|
if obj:is_player() and obj:get_player_name() ~= player_name then
|
|
|
|
return
|
|
|
|
end
|
2016-02-12 17:00:44 +03:00
|
|
|
end
|
|
|
|
|
2023-06-30 16:48:50 +03:00
|
|
|
if player_api.player_attached[player_name] then
|
2019-08-21 07:40:06 +03:00
|
|
|
clicker:set_pos(pos)
|
2019-07-23 15:03:20 +03:00
|
|
|
clicker:set_eye_offset(vector.new(), vector.new())
|
2023-06-30 16:38:27 +03:00
|
|
|
if mod_playerphysics then
|
|
|
|
playerphysics.remove_physics_factor(clicker, "speed", "xdecor:sit_speed")
|
|
|
|
playerphysics.remove_physics_factor(clicker, "jump", "xdecor:sit_jump")
|
|
|
|
else
|
|
|
|
clicker:set_physics_override({speed = 1, jump = 1})
|
|
|
|
end
|
2023-06-30 16:48:50 +03:00
|
|
|
player_api.player_attached[player_name] = false
|
|
|
|
player_api.set_animation(clicker, "stand", 30)
|
2016-02-12 17:00:44 +03:00
|
|
|
|
2023-06-30 16:48:50 +03:00
|
|
|
elseif not player_api.player_attached[player_name] and node.param2 <= 3 and
|
2019-07-23 15:03:20 +03:00
|
|
|
not ctrl.sneak and vector.equals(vel, vector.new()) then
|
2016-02-12 17:00:44 +03:00
|
|
|
|
2019-07-23 15:03:20 +03:00
|
|
|
clicker:set_eye_offset({x = 0, y = -7, z = 2}, vector.new())
|
2023-06-30 16:38:27 +03:00
|
|
|
if mod_playerphysics then
|
|
|
|
playerphysics.add_physics_factor(clicker, "speed", "xdecor:sit_speed", 0)
|
|
|
|
playerphysics.add_physics_factor(clicker, "jump", "xdecor:sit_jump", 0)
|
|
|
|
else
|
|
|
|
clicker:set_physics_override({speed = 0, jump = 0})
|
|
|
|
end
|
2019-08-21 07:40:06 +03:00
|
|
|
clicker:set_pos(pos)
|
2023-06-30 16:48:50 +03:00
|
|
|
player_api.player_attached[player_name] = true
|
|
|
|
player_api.set_animation(clicker, "sit", 30)
|
2016-02-12 17:00:44 +03:00
|
|
|
|
2019-07-23 15:03:20 +03:00
|
|
|
if node.param2 == 0 then
|
2023-06-30 16:43:02 +03:00
|
|
|
clicker:set_look_horizontal(0)
|
2019-07-23 15:03:20 +03:00
|
|
|
elseif node.param2 == 1 then
|
2023-06-30 16:43:02 +03:00
|
|
|
clicker:set_look_horizontal(3*(math.pi/2))
|
2019-07-23 15:03:20 +03:00
|
|
|
elseif node.param2 == 2 then
|
2023-06-30 16:43:02 +03:00
|
|
|
clicker:set_look_horizontal(math.pi)
|
2019-07-23 15:03:20 +03:00
|
|
|
elseif node.param2 == 3 then
|
2023-06-30 16:43:02 +03:00
|
|
|
clicker:set_look_horizontal(math.pi/2)
|
2019-07-23 15:03:20 +03:00
|
|
|
end
|
2016-02-12 17:00:44 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-05 23:17:15 +03:00
|
|
|
function xdecor.sit_dig(pos, digger)
|
2023-06-30 16:51:06 +03:00
|
|
|
if not mod_player_api then
|
|
|
|
return true
|
|
|
|
end
|
2016-08-05 23:17:15 +03:00
|
|
|
for _, player in pairs(minetest.get_objects_inside_radius(pos, 0.1)) do
|
2016-12-05 14:58:35 +03:00
|
|
|
if player:is_player() and
|
2023-06-30 16:48:50 +03:00
|
|
|
player_api.player_attached[player:get_player_name()] then
|
2016-02-12 17:00:44 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2019-07-23 15:03:20 +03:00
|
|
|
|
2016-02-12 17:00:44 +03:00
|
|
|
return true
|
|
|
|
end
|