2016-12-29 13:28:25 +01:00
|
|
|
-- lib_mount by Blert2112 (edited by TenPlus1)
|
|
|
|
|
2022-03-01 10:04:38 +01:00
|
|
|
local is_50 = minetest.get_modpath("player_api") -- 5.x compatibility
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local abs, cos, floor, sin, sqrt, pi =
|
|
|
|
math.abs, math.cos, math.floor, math.sin, math.sqrt, math.pi
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Helper functions
|
|
|
|
--
|
|
|
|
|
2017-06-26 22:03:55 +02:00
|
|
|
local node_ok = function(pos, fallback)
|
2022-02-05 13:25:01 +01:00
|
|
|
|
2017-07-08 10:08:23 +02:00
|
|
|
fallback = fallback or mobs.fallback_node
|
2017-06-26 22:03:55 +02:00
|
|
|
|
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
|
|
|
|
if node and minetest.registered_nodes[node.name] then
|
|
|
|
return node
|
|
|
|
end
|
|
|
|
|
|
|
|
return {name = fallback}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
local function node_is(pos)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2017-06-26 22:03:55 +02:00
|
|
|
local node = node_ok(pos)
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
if node.name == "air" then
|
|
|
|
return "air"
|
|
|
|
end
|
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
if minetest.get_item_group(node.name, "lava") ~= 0 then
|
|
|
|
return "lava"
|
|
|
|
end
|
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if minetest.get_item_group(node.name, "liquid") ~= 0 then
|
|
|
|
return "liquid"
|
|
|
|
end
|
|
|
|
|
2017-06-26 22:03:55 +02:00
|
|
|
if minetest.registered_nodes[node.name].walkable == true then
|
2016-12-29 13:28:25 +01:00
|
|
|
return "walkable"
|
|
|
|
end
|
|
|
|
|
|
|
|
return "other"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_sign(i)
|
2022-02-05 13:25:01 +01:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
i = i or 0
|
|
|
|
|
|
|
|
if i == 0 then
|
|
|
|
return 0
|
|
|
|
else
|
2021-01-21 10:44:31 +01:00
|
|
|
return i / abs(i)
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_velocity(v, yaw, y)
|
2022-02-05 13:25:01 +01:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local x = -sin(yaw) * v
|
|
|
|
local z = cos(yaw) * v
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
return {x = x, y = y, z = z}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_v(v)
|
2021-01-21 10:44:31 +01:00
|
|
|
return sqrt(v.x * v.x + v.z * v.z)
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function force_detach(player)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2022-03-01 10:04:38 +01:00
|
|
|
if not player then return end
|
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
local attached_to = player:get_attach()
|
|
|
|
|
|
|
|
if not attached_to then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local entity = attached_to:get_luaentity()
|
|
|
|
|
2020-07-03 16:46:50 +02:00
|
|
|
if entity and entity.driver
|
2016-12-29 13:28:25 +01:00
|
|
|
and entity.driver == player then
|
|
|
|
entity.driver = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
player:set_detach()
|
2022-03-01 10:04:38 +01:00
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
if is_50 then
|
|
|
|
player_api.player_attached[name] = false
|
|
|
|
player_api.set_animation(player, "stand", 30)
|
|
|
|
else
|
|
|
|
default.player_attached[name] = false
|
|
|
|
default.player_set_animation(player, "stand", 30)
|
|
|
|
end
|
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
2021-01-21 10:44:31 +01:00
|
|
|
player:set_properties({visual_size = {x = 1, y = 1}})
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
force_detach(player)
|
|
|
|
end)
|
|
|
|
|
2022-03-01 10:04:38 +01:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
minetest.register_on_shutdown(function()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
local players = minetest.get_connected_players()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
for i = 1, #players do
|
|
|
|
force_detach(players[i])
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-03-01 10:04:38 +01:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
|
|
|
force_detach(player)
|
|
|
|
return true
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
-- Just for correct detaching
|
|
|
|
local function find_free_pos(pos)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local check = {
|
|
|
|
{x = 1, y = 0, z = 0},
|
|
|
|
{x = 1, y = 1, z = 0},
|
|
|
|
{x = -1, y = 0, z = 0},
|
|
|
|
{x = -1, y = 1, z = 0},
|
|
|
|
{x = 0, y = 0, z = 1},
|
|
|
|
{x = 0, y = 1, z = 1},
|
|
|
|
{x = 0, y = 0, z = -1},
|
|
|
|
{x = 0, y = 1, z = -1}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c in pairs(check) do
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local npos = {x = pos.x + c.x, y = pos.y + c.y, z = pos.z + c.z}
|
|
|
|
local node = minetest.get_node_or_nil(npos)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if node and node.name then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local def = minetest.registered_nodes[node.name]
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if def and not def.walkable and
|
|
|
|
def.liquidtype == "none" then
|
|
|
|
return npos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-29 13:28:25 +01:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
return pos
|
|
|
|
end
|
2016-12-29 13:28:25 +01:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
|
|
|
|
function mobs.attach(entity, player)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2017-01-19 16:01:58 +01:00
|
|
|
entity.player_rotation = entity.player_rotation or {x = 0, y = 0, z = 0}
|
|
|
|
entity.driver_attach_at = entity.driver_attach_at or {x = 0, y = 0, z = 0}
|
|
|
|
entity.driver_eye_offset = entity.driver_eye_offset or {x = 0, y = 0, z = 0}
|
|
|
|
entity.driver_scale = entity.driver_scale or {x = 1, y = 1}
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
local rot_view = 0
|
|
|
|
|
|
|
|
if entity.player_rotation.y == 90 then
|
2021-01-21 10:44:31 +01:00
|
|
|
rot_view = pi / 2
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local attach_at = entity.driver_attach_at
|
|
|
|
local eye_offset = entity.driver_eye_offset
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
entity.driver = player
|
|
|
|
|
|
|
|
force_detach(player)
|
|
|
|
|
2022-03-01 10:04:38 +01:00
|
|
|
if is_50 then
|
|
|
|
player_api.player_attached[player:get_player_name()] = true
|
|
|
|
else
|
|
|
|
default.player_attached[player:get_player_name()] = true
|
|
|
|
end
|
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
player:set_attach(entity.object, "", attach_at, entity.player_rotation)
|
|
|
|
player:set_eye_offset(eye_offset, {x = 0, y = 0, z = 0})
|
2017-01-19 16:01:58 +01:00
|
|
|
|
|
|
|
player:set_properties({
|
|
|
|
visual_size = {
|
|
|
|
x = entity.driver_scale.x,
|
|
|
|
y = entity.driver_scale.y
|
|
|
|
}
|
|
|
|
})
|
2016-12-29 13:28:25 +01:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
minetest.after(0.2, function()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if player and player:is_player() then
|
2022-03-01 10:04:38 +01:00
|
|
|
|
|
|
|
if is_50 then
|
|
|
|
player_api.set_animation(player, "sit", 30)
|
|
|
|
else
|
|
|
|
default.player_set_animation(player, "sit", 30)
|
|
|
|
end
|
2020-04-29 16:01:21 +02:00
|
|
|
end
|
2021-01-21 10:44:31 +01:00
|
|
|
end)
|
2016-12-29 13:28:25 +01:00
|
|
|
|
2017-09-21 10:24:18 +02:00
|
|
|
player:set_look_horizontal(entity.object:get_yaw() - rot_view)
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
function mobs.detach(player)
|
2022-02-05 13:25:01 +01:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
force_detach(player)
|
2017-01-23 21:25:00 +01:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
minetest.after(0.1, function()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if player and player:is_player() then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local pos = find_free_pos(player:get_pos())
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
pos.y = pos.y + 0.5
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2020-04-29 16:01:21 +02:00
|
|
|
player:set_pos(pos)
|
|
|
|
end
|
2021-01-21 10:44:31 +01:00
|
|
|
end)
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
2016-12-29 13:28:25 +01:00
|
|
|
|
2021-06-11 23:25:00 +02:00
|
|
|
local yaw = entity.object:get_yaw() or 0
|
2021-01-21 10:44:31 +01:00
|
|
|
local rot_view = 0
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
if entity.player_rotation.y == 90 then
|
2021-01-21 10:44:31 +01:00
|
|
|
rot_view = pi / 2
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local acce_y = 0
|
2022-01-03 18:35:51 +01:00
|
|
|
local velo = entity.object:get_velocity() ; if not velo then return end
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
entity.v = get_v(velo) * get_sign(entity.v)
|
|
|
|
|
|
|
|
-- process controls
|
|
|
|
if entity.driver then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
local ctrl = entity.driver:get_player_control()
|
|
|
|
|
|
|
|
-- move forwards
|
|
|
|
if ctrl.up then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2022-04-18 09:31:25 +02:00
|
|
|
entity.v = entity.v + entity.accel * dtime
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
-- move backwards
|
|
|
|
elseif ctrl.down then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if entity.max_speed_reverse == 0 and entity.v == 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-04-18 09:31:25 +02:00
|
|
|
entity.v = entity.v - entity.accel * dtime
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
-- mob rotation
|
|
|
|
local horz
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if entity.alt_turn == true then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
horz = yaw
|
|
|
|
|
|
|
|
if ctrl.left then
|
|
|
|
horz = horz + 0.05
|
|
|
|
|
|
|
|
elseif ctrl.right then
|
|
|
|
horz = horz - 0.05
|
|
|
|
end
|
|
|
|
else
|
|
|
|
horz = entity.driver:get_look_horizontal() or 0
|
|
|
|
end
|
|
|
|
|
2019-06-15 21:37:16 +02:00
|
|
|
entity.object:set_yaw(horz - entity.rotate)
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
if can_fly then
|
2022-02-05 13:25:01 +01:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
-- fly up
|
|
|
|
if ctrl.jump then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
velo.y = velo.y + 1
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if velo.y > entity.accel then velo.y = entity.accel end
|
|
|
|
|
|
|
|
elseif velo.y > 0 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2022-04-21 09:28:35 +02:00
|
|
|
velo.y = velo.y - dtime
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if velo.y < 0 then velo.y = 0 end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- fly down
|
|
|
|
if ctrl.sneak then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
velo.y = velo.y - 1
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if velo.y < -entity.accel then velo.y = -entity.accel end
|
|
|
|
|
|
|
|
elseif velo.y < 0 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2022-04-21 09:28:35 +02:00
|
|
|
velo.y = velo.y + dtime
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if velo.y > 0 then velo.y = 0 end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- jump
|
|
|
|
if ctrl.jump then
|
|
|
|
|
|
|
|
if velo.y == 0 then
|
|
|
|
velo.y = velo.y + entity.jump_height
|
|
|
|
acce_y = acce_y + (acce_y * 3) + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if not moving then set animation and return
|
|
|
|
if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if stand_anim then
|
2017-05-27 22:29:46 +02:00
|
|
|
mobs:set_animation(entity, stand_anim)
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
2019-06-15 21:37:16 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
-- set moving animation
|
|
|
|
if moving_anim then
|
2017-05-27 22:29:46 +02:00
|
|
|
mobs:set_animation(entity, moving_anim)
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Stop!
|
|
|
|
local s = get_sign(entity.v)
|
|
|
|
|
|
|
|
entity.v = entity.v - 0.02 * s
|
|
|
|
|
|
|
|
if s ~= get_sign(entity.v) then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2018-07-02 17:24:34 +02:00
|
|
|
entity.object:set_velocity({x = 0, y = 0, z = 0})
|
2016-12-29 13:28:25 +01:00
|
|
|
entity.v = 0
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- enforce speed limit forward and reverse
|
2022-04-18 09:31:25 +02:00
|
|
|
if entity.v > entity.max_speed_forward then
|
|
|
|
entity.v = entity.max_speed_forward
|
|
|
|
elseif entity.v < -entity.max_speed_reverse then
|
|
|
|
entity.v = -entity.max_speed_reverse
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Set position, velocity and acceleration
|
2017-10-09 16:24:40 +02:00
|
|
|
local p = entity.object:get_pos()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if not p then return end
|
|
|
|
|
2022-04-21 09:28:35 +02:00
|
|
|
local new_acce = {x = 0, y = entity.fall_speed, z = 0}
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
p.y = p.y - 0.5
|
|
|
|
|
|
|
|
local ni = node_is(p)
|
|
|
|
local v = entity.v
|
|
|
|
|
|
|
|
if ni == "air" then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if can_fly == true then
|
|
|
|
new_acce.y = 0
|
|
|
|
end
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
elseif ni == "liquid" or ni == "lava" then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
if ni == "lava" and entity.lava_damage ~= 0 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
entity.lava_counter = (entity.lava_counter or 0) + dtime
|
|
|
|
|
|
|
|
if entity.lava_counter > 1 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
minetest.sound_play("default_punch", {
|
|
|
|
object = entity.object,
|
|
|
|
max_hear_distance = 5
|
2021-06-11 23:25:00 +02:00
|
|
|
}, true)
|
2016-12-29 16:28:53 +01:00
|
|
|
|
|
|
|
entity.object:punch(entity.object, 1.0, {
|
|
|
|
full_punch_interval = 1.0,
|
|
|
|
damage_groups = {fleshy = entity.lava_damage}
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
entity.lava_counter = 0
|
|
|
|
end
|
|
|
|
end
|
2016-12-29 13:28:25 +01:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local terrain_type = entity.terrain_type
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if terrain_type == 2 or terrain_type == 3 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
new_acce.y = 0
|
|
|
|
p.y = p.y + 1
|
|
|
|
|
|
|
|
if node_is(p) == "liquid" then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
if velo.y >= 5 then
|
|
|
|
velo.y = 5
|
|
|
|
elseif velo.y < 0 then
|
|
|
|
new_acce.y = 20
|
|
|
|
else
|
|
|
|
new_acce.y = 5
|
|
|
|
end
|
|
|
|
else
|
2021-01-21 10:44:31 +01:00
|
|
|
if abs(velo.y) < 1 then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2017-10-09 16:24:40 +02:00
|
|
|
local pos = entity.object:get_pos()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
if not pos then return end
|
|
|
|
|
|
|
|
pos.y = floor(pos.y) + 0.5
|
2018-07-02 17:24:34 +02:00
|
|
|
entity.object:set_pos(pos)
|
2016-12-29 13:28:25 +01:00
|
|
|
velo.y = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2016-12-29 16:28:53 +01:00
|
|
|
v = v * 0.25
|
2016-12-29 13:28:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
local new_velo = get_velocity(v, yaw - rot_view, velo.y)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2016-12-29 13:28:25 +01:00
|
|
|
new_acce.y = new_acce.y + acce_y
|
|
|
|
|
2018-07-02 17:24:34 +02:00
|
|
|
entity.object:set_velocity(new_velo)
|
|
|
|
entity.object:set_acceleration(new_acce)
|
2016-12-29 13:28:25 +01:00
|
|
|
|
|
|
|
entity.v2 = v
|
|
|
|
end
|
2017-02-21 16:01:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- directional flying routine by D00Med (edited by TenPlus1)
|
2021-01-21 10:44:31 +01:00
|
|
|
function mobs.fly(entity, _, speed, shoots, arrow, moving_anim, stand_anim)
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2022-01-03 18:35:51 +01:00
|
|
|
local ctrl = entity.driver:get_player_control() ; if not ctrl then return end
|
2018-07-02 17:24:34 +02:00
|
|
|
local velo = entity.object:get_velocity()
|
2017-02-21 16:01:36 +01:00
|
|
|
local dir = entity.driver:get_look_dir()
|
2022-02-05 13:25:01 +01:00
|
|
|
local yaw = entity.driver:get_look_horizontal() + 1.57
|
2017-02-21 16:01:36 +01:00
|
|
|
|
2022-02-05 13:25:01 +01:00
|
|
|
if not ctrl or not velo then return end
|
2021-05-21 18:46:10 +02:00
|
|
|
|
2017-02-21 16:01:36 +01:00
|
|
|
if ctrl.up then
|
2022-02-05 13:25:01 +01:00
|
|
|
|
2018-07-02 17:24:34 +02:00
|
|
|
entity.object:set_velocity({
|
2017-02-21 16:01:36 +01:00
|
|
|
x = dir.x * speed,
|
|
|
|
y = dir.y * speed + 2,
|
|
|
|
z = dir.z * speed
|
|
|
|
})
|
|
|
|
|
|
|
|
elseif ctrl.down then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2018-07-02 17:24:34 +02:00
|
|
|
entity.object:set_velocity({
|
2017-02-21 16:01:36 +01:00
|
|
|
x = -dir.x * speed,
|
2021-01-21 10:44:31 +01:00
|
|
|
y = dir.y * speed + 2,
|
2017-02-21 16:01:36 +01:00
|
|
|
z = -dir.z * speed
|
|
|
|
})
|
|
|
|
|
|
|
|
elseif not ctrl.down or ctrl.up or ctrl.jump then
|
2018-07-02 17:24:34 +02:00
|
|
|
entity.object:set_velocity({x = 0, y = -2, z = 0})
|
2017-02-21 16:01:36 +01:00
|
|
|
end
|
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
entity.object:set_yaw(yaw + pi + pi / 2 - entity.rotate)
|
2017-02-21 16:01:36 +01:00
|
|
|
|
|
|
|
-- firing arrows
|
|
|
|
if ctrl.LMB and ctrl.sneak and shoots then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2017-10-09 16:24:40 +02:00
|
|
|
local pos = entity.object:get_pos()
|
2017-02-21 16:01:36 +01:00
|
|
|
local obj = minetest.add_entity({
|
|
|
|
x = pos.x + 0 + dir.x * 2.5,
|
|
|
|
y = pos.y + 1.5 + dir.y,
|
|
|
|
z = pos.z + 0 + dir.z * 2.5}, arrow)
|
|
|
|
|
2017-02-22 13:57:02 +01:00
|
|
|
local ent = obj:get_luaentity()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2017-02-22 13:57:02 +01:00
|
|
|
if ent then
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2017-02-22 13:57:02 +01:00
|
|
|
ent.switch = 1 -- for mob specific arrows
|
2017-03-02 21:41:45 +01:00
|
|
|
ent.owner_id = tostring(entity.object) -- so arrows dont hurt entity you are riding
|
2017-02-22 13:57:02 +01:00
|
|
|
local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
yaw = entity.driver:get_look_horizontal()
|
2021-06-11 23:25:00 +02:00
|
|
|
|
2021-01-21 10:44:31 +01:00
|
|
|
obj:set_yaw(yaw + pi / 2)
|
2018-07-02 17:24:34 +02:00
|
|
|
obj:set_velocity(vec)
|
2017-02-22 13:57:02 +01:00
|
|
|
else
|
|
|
|
obj:remove()
|
|
|
|
end
|
2017-02-21 16:01:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- change animation if stopped
|
|
|
|
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
|
2017-05-27 22:29:46 +02:00
|
|
|
mobs:set_animation(entity, stand_anim)
|
2017-02-21 16:01:36 +01:00
|
|
|
else
|
|
|
|
-- moving animation
|
2017-05-27 22:29:46 +02:00
|
|
|
mobs:set_animation(entity, moving_anim)
|
2017-02-21 16:01:36 +01:00
|
|
|
end
|
|
|
|
end
|