2021-04-17 20:34:23 +03:00
|
|
|
mcl_playerplus = {
|
|
|
|
elytra = {},
|
2022-08-06 17:38:20 +03:00
|
|
|
is_pressing_jump = {},
|
2021-04-17 20:34:23 +03:00
|
|
|
}
|
2021-04-13 00:56:33 +03:00
|
|
|
|
2021-03-15 02:32:19 +03:00
|
|
|
local get_connected_players = minetest.get_connected_players
|
|
|
|
local dir_to_yaw = minetest.dir_to_yaw
|
|
|
|
local get_item_group = minetest.get_item_group
|
|
|
|
local check_player_privs = minetest.check_player_privs
|
|
|
|
local find_node_near = minetest.find_node_near
|
|
|
|
local get_name_from_content_id = minetest.get_name_from_content_id
|
|
|
|
local get_voxel_manip = minetest.get_voxel_manip
|
|
|
|
local add_particle = minetest.add_particle
|
|
|
|
local add_particlespawner = minetest.add_particlespawner
|
|
|
|
|
|
|
|
local is_sprinting = mcl_sprint.is_sprinting
|
|
|
|
local exhaust = mcl_hunger.exhaust
|
|
|
|
local playerphysics = playerphysics
|
|
|
|
|
|
|
|
local vector = vector
|
|
|
|
local math = math
|
2021-02-08 02:15:34 +03:00
|
|
|
-- Internal player state
|
|
|
|
local mcl_playerplus_internal = {}
|
|
|
|
|
|
|
|
local time = 0
|
2021-04-14 02:14:37 +03:00
|
|
|
local look_pitch = 0
|
2021-02-08 02:15:34 +03:00
|
|
|
|
2021-05-25 13:52:25 +03:00
|
|
|
local function player_collision(player)
|
2021-04-10 00:33:14 +03:00
|
|
|
|
|
|
|
local pos = player:get_pos()
|
2021-04-16 00:41:34 +03:00
|
|
|
--local vel = player:get_velocity()
|
2021-04-10 00:33:14 +03:00
|
|
|
local x = 0
|
|
|
|
local z = 0
|
|
|
|
local width = .75
|
|
|
|
|
|
|
|
for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do
|
|
|
|
|
2022-03-20 20:11:30 +03:00
|
|
|
local ent = object:get_luaentity()
|
2022-05-25 15:02:10 +03:00
|
|
|
if (object:is_player() or (ent and ent.is_mob and object ~= player)) then
|
2021-04-10 00:33:14 +03:00
|
|
|
|
|
|
|
local pos2 = object:get_pos()
|
|
|
|
local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
|
|
|
local force = (width + 0.5) - vector.distance(
|
|
|
|
{x = pos.x, y = 0, z = pos.z},
|
|
|
|
{x = pos2.x, y = 0, z = pos2.z})
|
|
|
|
|
|
|
|
x = x + (vec.x * force)
|
|
|
|
z = z + (vec.z * force)
|
|
|
|
end
|
|
|
|
end
|
2021-05-25 11:56:06 +03:00
|
|
|
return {x,z}
|
2021-04-10 00:33:14 +03:00
|
|
|
end
|
|
|
|
|
2021-07-12 21:50:37 +03:00
|
|
|
local function walking_player(player, control)
|
|
|
|
if control.up or control.down or control.left or control.right then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-02-08 02:15:34 +03:00
|
|
|
-- converts yaw to degrees
|
|
|
|
local function degrees(rad)
|
|
|
|
return rad * 180.0 / math.pi
|
|
|
|
end
|
|
|
|
|
2021-05-25 13:52:25 +03:00
|
|
|
local function dir_to_pitch(dir)
|
2021-04-16 00:41:34 +03:00
|
|
|
--local dir2 = vector.normalize(dir)
|
2021-02-23 05:48:09 +03:00
|
|
|
local xz = math.abs(dir.x) + math.abs(dir.z)
|
|
|
|
return -math.atan2(-dir.y, xz)
|
|
|
|
end
|
|
|
|
|
2021-03-19 13:32:17 +03:00
|
|
|
local player_vel_yaws = {}
|
|
|
|
|
|
|
|
function limit_vel_yaw(player_vel_yaw, yaw)
|
|
|
|
if player_vel_yaw < 0 then
|
|
|
|
player_vel_yaw = player_vel_yaw + 360
|
|
|
|
end
|
|
|
|
|
|
|
|
if yaw < 0 then
|
|
|
|
yaw = yaw + 360
|
|
|
|
end
|
|
|
|
|
|
|
|
if math.abs(player_vel_yaw - yaw) > 40 then
|
|
|
|
local player_vel_yaw_nm, yaw_nm = player_vel_yaw, yaw
|
|
|
|
if player_vel_yaw > yaw then
|
|
|
|
player_vel_yaw_nm = player_vel_yaw - 360
|
|
|
|
else
|
|
|
|
yaw_nm = yaw - 360
|
|
|
|
end
|
|
|
|
if math.abs(player_vel_yaw_nm - yaw_nm) > 40 then
|
|
|
|
local diff = math.abs(player_vel_yaw - yaw)
|
|
|
|
if diff > 180 and diff < 185 or diff < 180 and diff > 175 then
|
|
|
|
player_vel_yaw = yaw
|
|
|
|
elseif diff < 180 then
|
|
|
|
if player_vel_yaw < yaw then
|
|
|
|
player_vel_yaw = yaw - 40
|
|
|
|
else
|
|
|
|
player_vel_yaw = yaw + 40
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if player_vel_yaw < yaw then
|
|
|
|
player_vel_yaw = yaw + 40
|
|
|
|
else
|
|
|
|
player_vel_yaw = yaw - 40
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if player_vel_yaw < 0 then
|
|
|
|
player_vel_yaw = player_vel_yaw + 360
|
|
|
|
elseif player_vel_yaw > 360 then
|
|
|
|
player_vel_yaw = player_vel_yaw - 360
|
|
|
|
end
|
|
|
|
|
|
|
|
return player_vel_yaw
|
|
|
|
end
|
|
|
|
|
2022-07-17 16:14:24 +03:00
|
|
|
local node_stand, node_stand_below, node_head, node_feet, node_head_top
|
2022-07-17 14:46:36 +03:00
|
|
|
local is_swimming
|
2021-02-08 02:15:34 +03:00
|
|
|
|
2022-02-13 01:44:21 +03:00
|
|
|
-- This following part is 2 wrapper functions for player:set_bones
|
|
|
|
-- and player:set_properties preventing them from being resent on
|
|
|
|
-- every globalstep when they have not changed.
|
|
|
|
|
|
|
|
local function roundN(n, d)
|
|
|
|
if type(n) ~= "number" then return n end
|
|
|
|
local m = 10^d
|
|
|
|
return math.floor(n * m + 0.5) / m
|
|
|
|
end
|
|
|
|
|
|
|
|
local function close_enough(a,b)
|
|
|
|
local rt=true
|
|
|
|
if type(a) == "table" and type(b) == "table" then
|
|
|
|
for k,v in pairs(a) do
|
|
|
|
if roundN(v,2) ~= roundN(b[k],2) then
|
|
|
|
rt=false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
rt = roundN(a,2) == roundN(b,2)
|
|
|
|
end
|
|
|
|
return rt
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function props_changed(props,oldprops)
|
|
|
|
local changed=false
|
|
|
|
local p={}
|
|
|
|
for k,v in pairs(props) do
|
|
|
|
if not close_enough(v,oldprops[k]) then
|
|
|
|
p[k]=v
|
|
|
|
changed=true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return changed,p
|
|
|
|
end
|
|
|
|
|
|
|
|
--tests for roundN
|
|
|
|
local test_round1=15
|
|
|
|
local test_round2=15.00199999999
|
|
|
|
local test_round3=15.00111111
|
|
|
|
local test_round4=15.00999999
|
|
|
|
|
|
|
|
assert(roundN(test_round1,2)==roundN(test_round1,2))
|
|
|
|
assert(roundN(test_round1,2)==roundN(test_round2,2))
|
|
|
|
assert(roundN(test_round1,2)==roundN(test_round3,2))
|
|
|
|
assert(roundN(test_round1,2)~=roundN(test_round4,2))
|
|
|
|
|
|
|
|
-- tests for close_enough
|
|
|
|
local test_cb = {-0.35,0,-0.35,0.35,0.8,0.35} --collisionboxes
|
|
|
|
local test_cb_close = {-0.351213,0,-0.35,0.35,0.8,0.351212}
|
|
|
|
local test_cb_diff = {-0.35,0,-1.35,0.35,0.8,0.35}
|
|
|
|
|
|
|
|
local test_eh = 1.65 --eye height
|
|
|
|
local test_eh_close = 1.65123123
|
|
|
|
local test_eh_diff = 1.35
|
|
|
|
|
|
|
|
local test_nt = { r = 225, b = 225, a = 225, g = 225 } --nametag
|
|
|
|
local test_nt_diff = { r = 225, b = 225, a = 0, g = 225 }
|
|
|
|
|
|
|
|
assert(close_enough(test_cb,test_cb_close))
|
|
|
|
assert(not close_enough(test_cb,test_cb_diff))
|
|
|
|
assert(close_enough(test_eh,test_eh_close))
|
|
|
|
assert(not close_enough(test_eh,test_eh_diff))
|
|
|
|
assert(not close_enough(test_nt,test_nt_diff)) --no floats involved here
|
|
|
|
|
|
|
|
--tests for properties_changed
|
|
|
|
local test_properties_set1={collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}
|
|
|
|
local test_properties_set2={collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 1.35, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}
|
|
|
|
|
|
|
|
local test_p1,_=props_changed(test_properties_set1,test_properties_set1)
|
|
|
|
local test_p2,_=props_changed(test_properties_set1,test_properties_set2)
|
|
|
|
|
|
|
|
assert(not test_p1)
|
|
|
|
assert(test_p2)
|
|
|
|
|
|
|
|
local function set_properties_conditional(player,props)
|
|
|
|
local changed,p=props_changed(props,player:get_properties())
|
|
|
|
if changed then
|
|
|
|
player:set_properties(p)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_bone_position_conditional(player,b,p,r) --bone,position,rotation
|
|
|
|
local oldp,oldr=player:get_bone_position(b)
|
|
|
|
if vector.equals(vector.round(oldp),vector.round(p)) and vector.equals(vector.round(oldr),vector.round(r)) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
player:set_bone_position(b,p,r)
|
|
|
|
end
|
|
|
|
|
2022-08-07 16:12:57 +03:00
|
|
|
local function get_overall_velocity(vector)
|
|
|
|
local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2)
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
local function anglediff(a1, a2)
|
|
|
|
local a = a1 - a2
|
|
|
|
return math.abs((a + math.pi) % (math.pi*2) - math.pi)
|
|
|
|
end
|
|
|
|
local function clamp(num, min, max)
|
|
|
|
return math.min(max, math.max(num, min))
|
|
|
|
end
|
|
|
|
|
|
|
|
local elytra_vars = {
|
2022-08-08 04:50:23 +03:00
|
|
|
slowdown_mult = 0.0, -- amount of vel to take per sec
|
|
|
|
fall_speed = 0.2, -- amount of vel to fall down per sec
|
2022-08-11 19:26:22 +03:00
|
|
|
speedup_mult = 2, -- amount of speed to add based on look dir
|
2022-08-08 04:50:23 +03:00
|
|
|
max_speed = 6, -- max amount to multiply against look direction when flying
|
2022-08-08 03:50:06 +03:00
|
|
|
pitch_penalty = 1.3, -- if pitching up, slow down at this rate as a multiplier
|
2022-08-08 04:50:23 +03:00
|
|
|
rocket_speed = 5.5,
|
2022-08-07 16:12:57 +03:00
|
|
|
}
|
2022-02-13 01:44:21 +03:00
|
|
|
|
|
|
|
|
2021-02-08 02:15:34 +03:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
|
|
|
|
time = time + dtime
|
|
|
|
|
2021-03-16 19:39:06 +03:00
|
|
|
for _,player in pairs(get_connected_players()) do
|
2021-02-08 02:15:34 +03:00
|
|
|
|
2021-04-05 10:25:03 +03:00
|
|
|
--[[
|
2021-10-15 22:00:37 +03:00
|
|
|
|
2021-04-05 10:25:03 +03:00
|
|
|
_ _ _
|
|
|
|
__ _ _ __ (_)_ __ ___ __ _| |_(_) ___ _ __ ___
|
|
|
|
/ _` | '_ \| | '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
|
|
|
|
| (_| | | | | | | | | | | (_| | |_| | (_) | | | \__ \
|
|
|
|
\__,_|_| |_|_|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
|
2021-03-19 13:32:17 +03:00
|
|
|
|
2021-04-05 10:25:03 +03:00
|
|
|
]]--
|
2021-02-23 05:48:09 +03:00
|
|
|
|
2021-04-13 21:45:31 +03:00
|
|
|
local control = player:get_player_control()
|
2021-04-05 10:25:03 +03:00
|
|
|
local name = player:get_player_name()
|
2021-04-16 00:41:34 +03:00
|
|
|
--local meta = player:get_meta()
|
2021-04-05 10:25:03 +03:00
|
|
|
local parent = player:get_attach()
|
2021-03-20 03:42:48 +03:00
|
|
|
local wielded = player:get_wielded_item()
|
2021-04-05 10:25:03 +03:00
|
|
|
local player_velocity = player:get_velocity() or player:get_player_velocity()
|
2021-04-14 16:46:52 +03:00
|
|
|
local wielded_def = wielded:get_definition()
|
|
|
|
|
2021-04-18 15:41:44 +03:00
|
|
|
local c_x, c_y = unpack(player_collision(player))
|
|
|
|
|
|
|
|
if player_velocity.x + player_velocity.y < .5 and c_x + c_y > 0 then
|
2022-05-12 16:34:14 +03:00
|
|
|
player:add_velocity({x = c_x, y = 0, z = c_y})
|
2021-04-18 15:41:44 +03:00
|
|
|
player_velocity = player:get_velocity() or player:get_player_velocity()
|
|
|
|
end
|
|
|
|
|
2021-04-13 21:45:31 +03:00
|
|
|
-- control head bone
|
2021-03-19 13:32:17 +03:00
|
|
|
local pitch = - degrees(player:get_look_vertical())
|
|
|
|
local yaw = degrees(player:get_look_horizontal())
|
2021-02-27 17:10:25 +03:00
|
|
|
|
2021-03-19 13:32:17 +03:00
|
|
|
local player_vel_yaw = degrees(dir_to_yaw(player_velocity))
|
|
|
|
if player_vel_yaw == 0 then
|
|
|
|
player_vel_yaw = player_vel_yaws[name] or yaw
|
2021-02-23 05:48:09 +03:00
|
|
|
end
|
2021-03-19 13:32:17 +03:00
|
|
|
player_vel_yaw = limit_vel_yaw(player_vel_yaw, yaw)
|
|
|
|
player_vel_yaws[name] = player_vel_yaw
|
2021-02-23 05:48:09 +03:00
|
|
|
|
2021-04-17 20:34:23 +03:00
|
|
|
local fly_pos = player:get_pos()
|
2022-08-11 19:26:22 +03:00
|
|
|
local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.1, z = fly_pos.z}).name
|
2021-04-17 20:34:23 +03:00
|
|
|
local elytra = mcl_playerplus.elytra[player]
|
2021-04-17 19:15:45 +03:00
|
|
|
|
2022-08-01 13:12:53 +03:00
|
|
|
if not elytra.active then
|
2022-08-10 06:24:08 +03:00
|
|
|
elytra.speed = 0
|
2022-08-01 10:42:43 +03:00
|
|
|
end
|
|
|
|
|
2022-08-06 17:38:20 +03:00
|
|
|
local is_just_jumped = control.jump and not mcl_playerplus.is_pressing_jump[name] and not elytra.active
|
|
|
|
mcl_playerplus.is_pressing_jump[name] = control.jump
|
2022-08-01 16:45:41 +03:00
|
|
|
if is_just_jumped and not elytra.active then
|
2022-08-11 19:26:22 +03:00
|
|
|
elytra.speed = clamp(get_overall_velocity(player:get_velocity()), 1, 3)
|
2022-08-08 03:50:06 +03:00
|
|
|
-- don't let player get too fast by spamming jump
|
|
|
|
local block_below = minetest.get_node(vector.offset(fly_pos, 0, -0.9, 0)).name
|
|
|
|
local block_below2 = minetest.get_node(vector.offset(fly_pos, 0, -1.9, 0)).name
|
|
|
|
if minetest.registered_nodes[block_below].walkable
|
|
|
|
or minetest.registered_nodes[block_below2].walkable then
|
2022-08-10 06:24:08 +03:00
|
|
|
elytra.speed = 1
|
2022-08-08 03:50:06 +03:00
|
|
|
end
|
2022-08-02 15:06:19 +03:00
|
|
|
end
|
2022-08-01 16:45:41 +03:00
|
|
|
|
2021-04-17 20:34:23 +03:00
|
|
|
elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra"
|
|
|
|
and not player:get_attach()
|
2022-08-01 16:45:41 +03:00
|
|
|
and (elytra.active or (is_just_jumped and player_velocity.y < -0))
|
2022-08-11 19:26:22 +03:00
|
|
|
and ((not minetest.registered_nodes[fly_node].walkable) or fly_node == "ignore")
|
2021-04-13 00:56:33 +03:00
|
|
|
|
2021-04-17 20:34:23 +03:00
|
|
|
if elytra.active then
|
2022-08-02 11:26:00 +03:00
|
|
|
if is_just_jumped then -- move the player up when they start flying to give some clearance
|
|
|
|
player:set_pos(vector.offset(player:get_pos(), 0, 0.8, 0))
|
|
|
|
end
|
2021-04-13 00:56:33 +03:00
|
|
|
mcl_player.player_set_animation(player, "fly")
|
2022-08-01 13:12:53 +03:00
|
|
|
local direction = player:get_look_dir()
|
2022-08-01 16:01:27 +03:00
|
|
|
local player_vel = player:get_velocity()
|
2022-08-02 01:20:08 +03:00
|
|
|
local turn_amount = anglediff(minetest.dir_to_yaw(direction), minetest.dir_to_yaw(player_vel))
|
2022-08-08 03:50:06 +03:00
|
|
|
local direction_mult = clamp(-(direction.y+0.1), -1, 1)
|
2022-08-07 17:05:00 +03:00
|
|
|
if direction_mult < 0 then direction_mult = direction_mult * elytra_vars.pitch_penalty end
|
2022-08-01 16:01:27 +03:00
|
|
|
|
2022-08-11 19:26:22 +03:00
|
|
|
local speed_mult = elytra.speed
|
|
|
|
local block_below = minetest.get_node(vector.offset(fly_pos, 0, -0.9, 0)).name
|
|
|
|
if (not minetest.registered_nodes[block_below].walkable) and (player_vel.y ~= 0) then
|
|
|
|
speed_mult = speed_mult + direction_mult * elytra_vars.speedup_mult * dtime
|
|
|
|
end
|
2022-08-08 04:50:23 +03:00
|
|
|
speed_mult = speed_mult - elytra_vars.slowdown_mult * clamp(dtime, 0.09, 0.2) -- slow down but don't overdo it
|
2022-08-07 17:05:00 +03:00
|
|
|
speed_mult = clamp(speed_mult, -elytra_vars.max_speed, elytra_vars.max_speed)
|
|
|
|
if turn_amount > 0.3 and math.abs(direction.y) < 0.98 then -- don't do this if looking straight up / down
|
2022-08-05 07:43:48 +03:00
|
|
|
speed_mult = speed_mult - (speed_mult * (turn_amount / (math.pi*8)))
|
2022-08-02 15:06:19 +03:00
|
|
|
end
|
2022-08-01 16:45:41 +03:00
|
|
|
|
2022-08-07 17:05:00 +03:00
|
|
|
playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", elytra_vars.fall_speed)
|
2021-04-17 20:34:23 +03:00
|
|
|
if elytra.rocketing > 0 then
|
|
|
|
elytra.rocketing = elytra.rocketing - dtime
|
|
|
|
if vector.length(player_velocity) < 40 then
|
2022-08-01 15:15:36 +03:00
|
|
|
-- player:add_velocity(vector.multiply(player:get_look_dir(), 4))
|
2022-08-07 17:05:00 +03:00
|
|
|
speed_mult = elytra_vars.rocket_speed
|
2021-06-12 20:23:03 +03:00
|
|
|
add_particle({
|
|
|
|
pos = fly_pos,
|
|
|
|
velocity = {x = 0, y = 0, z = 0},
|
|
|
|
acceleration = {x = 0, y = 0, z = 0},
|
|
|
|
expirationtime = math.random(0.3, 0.5),
|
|
|
|
size = math.random(1, 2),
|
2021-04-24 22:35:23 +03:00
|
|
|
collisiondetection = false,
|
|
|
|
vertical = false,
|
2021-06-12 20:23:03 +03:00
|
|
|
texture = "mcl_particles_bonemeal.png^[colorize:#bc7a57:127",
|
2021-04-24 22:35:23 +03:00
|
|
|
glow = 5,
|
|
|
|
})
|
2021-04-13 00:56:33 +03:00
|
|
|
end
|
|
|
|
end
|
2022-08-01 15:15:36 +03:00
|
|
|
|
2022-08-02 18:03:28 +03:00
|
|
|
elytra.speed = speed_mult -- set the speed so you can keep track of it and add to it
|
|
|
|
|
2022-08-08 04:50:23 +03:00
|
|
|
local new_vel = vector.multiply(direction, speed_mult * dtime * 30) -- use the look dir and speed as a mult
|
2022-08-07 17:05:00 +03:00
|
|
|
-- new_vel.y = new_vel.y - elytra_vars.fall_speed * dtime -- make the player fall a set amount
|
2022-08-01 15:15:36 +03:00
|
|
|
|
2022-08-07 17:05:00 +03:00
|
|
|
-- slow the player down so less spongy movement by applying some of the inverse velocity
|
2022-08-02 18:03:28 +03:00
|
|
|
-- NOTE: do not set this higher than about 0.2 or the game will get the wrong vel and it will be broken
|
2022-08-07 17:05:00 +03:00
|
|
|
-- this is far from ideal, but there's no good way to set_velocity or slow down the player
|
2022-08-02 16:42:04 +03:00
|
|
|
player_vel = vector.multiply(player_vel, -0.1)
|
2022-08-03 11:41:51 +03:00
|
|
|
-- if speed_mult < 1 then player_vel.y = player_vel.y * 0.1 end
|
2022-08-01 17:14:24 +03:00
|
|
|
new_vel = vector.add(new_vel, player_vel)
|
|
|
|
|
2022-08-01 16:01:27 +03:00
|
|
|
player:add_velocity(new_vel)
|
2022-08-07 17:05:00 +03:00
|
|
|
else -- reset things when you stop flying with elytra
|
2022-08-02 14:23:05 +03:00
|
|
|
elytra.rocketing = 0
|
|
|
|
playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra")
|
2021-04-13 00:56:33 +03:00
|
|
|
end
|
|
|
|
|
2021-04-14 16:46:52 +03:00
|
|
|
if wielded_def and wielded_def._mcl_toollike_wield then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
|
2021-04-14 16:46:52 +03:00
|
|
|
elseif string.find(wielded:get_name(), "mcl_bows:bow") then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20))
|
2021-10-15 22:00:37 +03:00
|
|
|
elseif string.find(wielded:get_name(), "mcl_bows:crossbow_loaded") then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Wield_Item", vector.new(-1.5,5.7,1.8), vector.new(64,90,0))
|
2021-10-15 22:00:37 +03:00
|
|
|
elseif string.find(wielded:get_name(), "mcl_bows:crossbow") then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Wield_Item", vector.new(-1.5,5.7,1.8), vector.new(90,90,0))
|
2021-04-14 16:46:52 +03:00
|
|
|
else
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90))
|
2021-04-14 16:46:52 +03:00
|
|
|
end
|
|
|
|
|
2022-03-15 17:58:27 +03:00
|
|
|
-- controls right and left arms pitch when shooting a bow or blocking
|
|
|
|
if mcl_shields.is_blocking(player) == 2 then
|
|
|
|
set_bone_position_conditional(player, "Arm_Right_Pitch_Control", vector.new(-3, 5.785, 0), vector.new(20, -20, 0))
|
|
|
|
elseif mcl_shields.is_blocking(player) == 1 then
|
|
|
|
set_bone_position_conditional(player, "Arm_Left_Pitch_Control", vector.new(3, 5.785, 0), vector.new(20, 20, 0))
|
|
|
|
elseif string.find(wielded:get_name(), "mcl_bows:bow") and control.RMB then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch+90,-30,pitch * -1 * .35))
|
|
|
|
set_bone_position_conditional(player,"Arm_Left_Pitch_Control", vector.new(3.5,5.785,0), vector.new(pitch+90,43,pitch * .35))
|
2021-10-15 22:00:37 +03:00
|
|
|
-- controls right and left arms pitch when holing a loaded crossbow
|
|
|
|
elseif string.find(wielded:get_name(), "mcl_bows:crossbow_loaded") then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch+90,-30,pitch * -1 * .35))
|
|
|
|
set_bone_position_conditional(player,"Arm_Left_Pitch_Control", vector.new(3.5,5.785,0), vector.new(pitch+90,43,pitch * .35))
|
2021-10-15 22:00:37 +03:00
|
|
|
-- controls right and left arms pitch when loading a crossbow
|
2022-03-15 17:58:27 +03:00
|
|
|
elseif string.find(wielded:get_name(), "mcl_bows:crossbow_") then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(45,-20,25))
|
|
|
|
set_bone_position_conditional(player,"Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(55,20,-45))
|
2021-03-20 03:42:48 +03:00
|
|
|
-- when punching
|
2021-04-13 21:45:31 +03:00
|
|
|
elseif control.LMB and not parent then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch,0,0))
|
|
|
|
set_bone_position_conditional(player,"Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(0,0,0))
|
2021-03-20 03:42:48 +03:00
|
|
|
-- when holding an item.
|
|
|
|
elseif wielded:get_name() ~= "" then
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(20,0,0))
|
|
|
|
set_bone_position_conditional(player,"Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(0,0,0))
|
2021-03-20 03:42:48 +03:00
|
|
|
-- resets arms pitch
|
2021-02-08 02:15:34 +03:00
|
|
|
else
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(0,0,0))
|
|
|
|
set_bone_position_conditional(player,"Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0))
|
2021-02-08 02:15:34 +03:00
|
|
|
end
|
2021-02-14 03:09:00 +03:00
|
|
|
|
2021-04-17 20:34:23 +03:00
|
|
|
if elytra.active then
|
|
|
|
-- set head pitch and yaw when flying
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch-degrees(dir_to_pitch(player_velocity)),player_vel_yaw - yaw,0))
|
2021-04-13 00:56:33 +03:00
|
|
|
-- sets eye height, and nametag color accordingly
|
2022-02-13 01:44:21 +03:00
|
|
|
set_properties_conditional(player,{collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
|
2021-04-17 20:34:23 +03:00
|
|
|
-- control body bone when flying
|
2022-08-07 19:05:03 +03:00
|
|
|
set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new((75-degrees(dir_to_pitch(player_velocity))) , -player_vel_yaw + yaw, 0))
|
2021-04-13 00:56:33 +03:00
|
|
|
elseif parent then
|
2021-04-05 10:25:03 +03:00
|
|
|
local parent_yaw = degrees(parent:get_yaw())
|
2022-02-13 01:44:21 +03:00
|
|
|
set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
|
|
|
|
set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch, -limit_vel_yaw(yaw, parent_yaw) + parent_yaw, 0))
|
|
|
|
set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(0,0,0))
|
2021-04-13 21:45:31 +03:00
|
|
|
elseif control.sneak then
|
2021-02-08 02:15:34 +03:00
|
|
|
-- controls head pitch when sneaking
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch, player_vel_yaw - yaw, player_vel_yaw - yaw))
|
2021-02-08 02:15:34 +03:00
|
|
|
-- sets eye height, and nametag color accordingly
|
2022-02-13 01:44:21 +03:00
|
|
|
set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.35, nametag_color = { r = 225, b = 225, a = 0, g = 225 }})
|
2021-02-23 05:48:09 +03:00
|
|
|
-- sneaking body conrols
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(0, -player_vel_yaw + yaw, 0))
|
2021-04-05 10:25:03 +03:00
|
|
|
elseif get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and is_sprinting(name) == true then
|
2021-02-23 05:48:09 +03:00
|
|
|
-- set head pitch and yaw when swimming
|
2022-07-17 14:46:36 +03:00
|
|
|
is_swimming = true
|
2022-08-07 19:05:03 +03:00
|
|
|
set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch-degrees(dir_to_pitch(player_velocity))+20,player_vel_yaw - yaw,0))
|
2021-02-08 02:15:34 +03:00
|
|
|
-- sets eye height, and nametag color accordingly
|
2022-02-13 01:44:21 +03:00
|
|
|
set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
|
2021-02-23 05:48:09 +03:00
|
|
|
-- control body bone when swimming
|
2022-08-12 05:55:50 +03:00
|
|
|
<<<<<<< HEAD
|
2022-08-07 19:05:03 +03:00
|
|
|
set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new((75-degrees(dir_to_pitch(player_velocity))) , -player_vel_yaw + yaw, 0))
|
2022-07-18 03:09:04 +03:00
|
|
|
elseif get_item_group(mcl_playerinfo[name].node_head, "opaque") == 0
|
|
|
|
and get_item_group(mcl_playerinfo[name].node_head_top, "opaque") == 0 then
|
2022-08-12 05:55:50 +03:00
|
|
|
=======
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0))
|
2022-08-08 21:17:30 +03:00
|
|
|
elseif get_item_group(mcl_playerinfo[name].node_head, "solid") == 0
|
|
|
|
and get_item_group(mcl_playerinfo[name].node_head_top, "solid") == 0 then
|
2022-08-12 05:55:50 +03:00
|
|
|
>>>>>>> master
|
2021-02-08 02:15:34 +03:00
|
|
|
-- sets eye height, and nametag color accordingly
|
2022-07-17 14:46:36 +03:00
|
|
|
is_swimming = false
|
2022-02-13 01:44:21 +03:00
|
|
|
set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
|
2021-02-25 04:11:00 +03:00
|
|
|
|
2022-02-13 01:44:21 +03:00
|
|
|
set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch, player_vel_yaw - yaw, 0))
|
|
|
|
set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(0, -player_vel_yaw + yaw, 0))
|
2021-02-08 02:15:34 +03:00
|
|
|
end
|
|
|
|
|
2021-04-05 10:25:03 +03:00
|
|
|
-- Update jump status immediately since we need this info in real time.
|
|
|
|
-- WARNING: This section is HACKY as hell since it is all just based on heuristics.
|
|
|
|
|
2021-02-08 02:15:34 +03:00
|
|
|
if mcl_playerplus_internal[name].jump_cooldown > 0 then
|
|
|
|
mcl_playerplus_internal[name].jump_cooldown = mcl_playerplus_internal[name].jump_cooldown - dtime
|
|
|
|
end
|
2021-04-05 10:25:03 +03:00
|
|
|
|
2021-04-13 21:45:31 +03:00
|
|
|
if control.jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then
|
2021-02-08 02:15:34 +03:00
|
|
|
|
2021-04-16 00:41:34 +03:00
|
|
|
--pos = player:get_pos()
|
2021-02-08 02:15:34 +03:00
|
|
|
|
|
|
|
node_stand = mcl_playerinfo[name].node_stand
|
|
|
|
node_stand_below = mcl_playerinfo[name].node_stand_below
|
|
|
|
node_head = mcl_playerinfo[name].node_head
|
|
|
|
node_feet = mcl_playerinfo[name].node_feet
|
2022-07-17 16:14:24 +03:00
|
|
|
node_head_top = mcl_playerinfo[name].node_head_top
|
2022-07-17 14:50:22 +03:00
|
|
|
if not node_stand or not node_stand_below or not node_head or not node_feet then
|
2021-02-08 02:15:34 +03:00
|
|
|
return
|
|
|
|
end
|
2022-07-17 14:46:36 +03:00
|
|
|
if (not minetest.registered_nodes[node_stand]
|
|
|
|
or not minetest.registered_nodes[node_stand_below]
|
|
|
|
or not minetest.registered_nodes[node_head]
|
2022-07-17 16:14:24 +03:00
|
|
|
or not minetest.registered_nodes[node_feet]
|
|
|
|
or not minetest.registered_nodes[node_head_top]) then
|
2021-02-08 02:15:34 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Cause buggy exhaustion for jumping
|
|
|
|
|
|
|
|
--[[ Checklist we check to know the player *actually* jumped:
|
|
|
|
* Not on or in liquid
|
|
|
|
* Not on or at climbable
|
|
|
|
* On walkable
|
|
|
|
* Not on disable_jump
|
|
|
|
FIXME: This code is pretty hacky and it is possible to miss some jumps or detect false
|
|
|
|
jumps because of delays, rounding errors, etc.
|
|
|
|
What this code *really* needs is some kind of jumping “callback” which this engine lacks
|
|
|
|
as of 0.4.15.
|
|
|
|
]]
|
|
|
|
|
2021-03-15 02:32:19 +03:00
|
|
|
if get_item_group(node_feet, "liquid") == 0 and
|
|
|
|
get_item_group(node_stand, "liquid") == 0 and
|
2021-02-08 02:15:34 +03:00
|
|
|
not minetest.registered_nodes[node_feet].climbable and
|
|
|
|
not minetest.registered_nodes[node_stand].climbable and
|
|
|
|
(minetest.registered_nodes[node_stand].walkable or minetest.registered_nodes[node_stand_below].walkable)
|
2021-03-15 02:32:19 +03:00
|
|
|
and get_item_group(node_stand, "disable_jump") == 0
|
|
|
|
and get_item_group(node_stand_below, "disable_jump") == 0 then
|
2021-02-08 02:15:34 +03:00
|
|
|
-- Cause exhaustion for jumping
|
2021-03-15 02:32:19 +03:00
|
|
|
if is_sprinting(name) then
|
|
|
|
exhaust(name, mcl_hunger.EXHAUST_SPRINT_JUMP)
|
2021-02-08 02:15:34 +03:00
|
|
|
else
|
2021-03-15 02:32:19 +03:00
|
|
|
exhaust(name, mcl_hunger.EXHAUST_JUMP)
|
2021-02-08 02:15:34 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Reset cooldown timer
|
|
|
|
mcl_playerplus_internal[name].jump_cooldown = 0.45
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Run the rest of the code every 0.5 seconds
|
|
|
|
if time < 0.5 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- reset time for next check
|
|
|
|
-- FIXME: Make sure a regular check interval applies
|
|
|
|
time = 0
|
|
|
|
|
|
|
|
-- check players
|
2021-03-16 19:39:06 +03:00
|
|
|
for _,player in pairs(get_connected_players()) do
|
2021-02-08 02:15:34 +03:00
|
|
|
-- who am I?
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
-- where am I?
|
|
|
|
local pos = player:get_pos()
|
|
|
|
|
|
|
|
-- what is around me?
|
|
|
|
local node_stand = mcl_playerinfo[name].node_stand
|
|
|
|
local node_stand_below = mcl_playerinfo[name].node_stand_below
|
|
|
|
local node_head = mcl_playerinfo[name].node_head
|
|
|
|
local node_feet = mcl_playerinfo[name].node_feet
|
2022-07-17 16:14:24 +03:00
|
|
|
local node_head_top = mcl_playerinfo[name].node_head_top
|
|
|
|
if not node_stand or not node_stand_below or not node_head or not node_feet or not node_head_top then
|
2021-02-08 02:15:34 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Standing on soul sand? If so, walk slower (unless player wears Soul Speed boots)
|
|
|
|
if node_stand == "mcl_nether:soul_sand" then
|
|
|
|
-- TODO: Tweak walk speed
|
|
|
|
-- TODO: Also slow down mobs
|
|
|
|
-- Slow down even more when soul sand is above certain block
|
|
|
|
local boots = player:get_inventory():get_stack("armor", 5)
|
|
|
|
local soul_speed = mcl_enchanting.get_enchantment(boots, "soul_speed")
|
|
|
|
if soul_speed > 0 then
|
|
|
|
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", soul_speed * 0.105 + 1.3)
|
|
|
|
else
|
|
|
|
if node_stand_below == "mcl_core:ice" or node_stand_below == "mcl_core:packed_ice" or node_stand_below == "mcl_core:slimeblock" or node_stand_below == "mcl_core:water_source" then
|
|
|
|
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.1)
|
|
|
|
else
|
|
|
|
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4)
|
|
|
|
end
|
|
|
|
end
|
2021-03-22 23:55:57 +03:00
|
|
|
elseif get_item_group(node_feet, "liquid") ~= 0 and mcl_enchanting.get_enchantment(player:get_inventory():get_stack("armor", 5), "depth_strider") then
|
2021-02-27 18:37:25 +03:00
|
|
|
local boots = player:get_inventory():get_stack("armor", 5)
|
|
|
|
local depth_strider = mcl_enchanting.get_enchantment(boots, "depth_strider")
|
2021-03-12 02:56:09 +03:00
|
|
|
|
2021-02-27 18:37:25 +03:00
|
|
|
if depth_strider > 0 then
|
2021-02-28 17:02:48 +03:00
|
|
|
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", (depth_strider / 3) + 0.75)
|
2021-02-27 18:37:25 +03:00
|
|
|
end
|
|
|
|
else
|
|
|
|
playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface")
|
|
|
|
end
|
|
|
|
|
2021-02-08 02:15:34 +03:00
|
|
|
-- Is player suffocating inside node? (Only for solid full opaque cube type nodes
|
|
|
|
-- without group disable_suffocation=1)
|
2022-07-17 15:50:22 +03:00
|
|
|
-- if swimming, check the feet node instead, because the head node will be above the player when swimming
|
|
|
|
local ndef = minetest.registered_nodes[node_head]
|
2022-07-17 14:46:36 +03:00
|
|
|
if is_swimming then
|
|
|
|
ndef = minetest.registered_nodes[node_feet]
|
|
|
|
end
|
2021-02-08 02:15:34 +03:00
|
|
|
if (ndef.walkable == nil or ndef.walkable == true)
|
|
|
|
and (ndef.collision_box == nil or ndef.collision_box.type == "regular")
|
|
|
|
and (ndef.node_box == nil or ndef.node_box.type == "regular")
|
|
|
|
and (ndef.groups.disable_suffocation ~= 1)
|
|
|
|
and (ndef.groups.opaque == 1)
|
|
|
|
and (node_head ~= "ignore")
|
|
|
|
-- Check privilege, too
|
2021-03-15 02:32:19 +03:00
|
|
|
and (not check_player_privs(name, {noclip = true})) then
|
2021-02-08 02:15:34 +03:00
|
|
|
if player:get_hp() > 0 then
|
2021-04-14 20:07:58 +03:00
|
|
|
mcl_util.deal_damage(player, 1, {type = "in_wall"})
|
2021-02-08 02:15:34 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Am I near a cactus?
|
2021-03-15 02:32:19 +03:00
|
|
|
local near = find_node_near(pos, 1, "mcl_core:cactus")
|
2021-02-08 02:15:34 +03:00
|
|
|
if not near then
|
2021-03-15 02:32:19 +03:00
|
|
|
near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus")
|
2021-02-08 02:15:34 +03:00
|
|
|
end
|
|
|
|
if near then
|
|
|
|
-- Am I touching the cactus? If so, it hurts
|
|
|
|
local dist = vector.distance(pos, near)
|
|
|
|
local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near)
|
|
|
|
if dist < 1.1 or dist_feet < 1.1 then
|
|
|
|
if player:get_hp() > 0 then
|
2021-04-14 18:20:51 +03:00
|
|
|
mcl_util.deal_damage(player, 1, {type = "cactus"})
|
2021-02-08 02:15:34 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[ Swimming: Cause exhaustion.
|
|
|
|
NOTE: As of 0.4.15, it only counts as swimming when you are with the feet inside the liquid!
|
|
|
|
Head alone does not count. We respect that for now. ]]
|
2021-03-15 02:32:19 +03:00
|
|
|
if not player:get_attach() and (get_item_group(node_feet, "liquid") ~= 0 or
|
|
|
|
get_item_group(node_stand, "liquid") ~= 0) then
|
2021-02-08 02:15:34 +03:00
|
|
|
local lastPos = mcl_playerplus_internal[name].lastPos
|
|
|
|
if lastPos then
|
|
|
|
local dist = vector.distance(lastPos, pos)
|
|
|
|
mcl_playerplus_internal[name].swimDistance = mcl_playerplus_internal[name].swimDistance + dist
|
|
|
|
if mcl_playerplus_internal[name].swimDistance >= 1 then
|
|
|
|
local superficial = math.floor(mcl_playerplus_internal[name].swimDistance)
|
2021-03-15 02:32:19 +03:00
|
|
|
exhaust(name, mcl_hunger.EXHAUST_SWIM * superficial)
|
2021-02-08 02:15:34 +03:00
|
|
|
mcl_playerplus_internal[name].swimDistance = mcl_playerplus_internal[name].swimDistance - superficial
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Underwater: Spawn bubble particles
|
2021-03-15 02:32:19 +03:00
|
|
|
if get_item_group(node_head, "water") ~= 0 then
|
|
|
|
add_particlespawner({
|
2021-02-08 02:15:34 +03:00
|
|
|
amount = 10,
|
|
|
|
time = 0.15,
|
|
|
|
minpos = { x = -0.25, y = 0.3, z = -0.25 },
|
|
|
|
maxpos = { x = 0.25, y = 0.7, z = 0.75 },
|
|
|
|
attached = player,
|
|
|
|
minvel = {x = -0.2, y = 0, z = -0.2},
|
|
|
|
maxvel = {x = 0.5, y = 0, z = 0.5},
|
|
|
|
minacc = {x = -0.4, y = 4, z = -0.4},
|
|
|
|
maxacc = {x = 0.5, y = 1, z = 0.5},
|
|
|
|
minexptime = 0.3,
|
|
|
|
maxexptime = 0.8,
|
|
|
|
minsize = 0.7,
|
|
|
|
maxsize = 2.4,
|
|
|
|
texture = "mcl_particles_bubble.png"
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Show positions of barriers when player is wielding a barrier
|
|
|
|
local wi = player:get_wielded_item():get_name()
|
|
|
|
if wi == "mcl_core:barrier" or wi == "mcl_core:realm_barrier" then
|
|
|
|
local pos = vector.round(player:get_pos())
|
|
|
|
local r = 8
|
2021-03-15 02:32:19 +03:00
|
|
|
local vm = get_voxel_manip()
|
2021-02-08 02:15:34 +03:00
|
|
|
local emin, emax = vm:read_from_map({x=pos.x-r, y=pos.y-r, z=pos.z-r}, {x=pos.x+r, y=pos.y+r, z=pos.z+r})
|
|
|
|
local area = VoxelArea:new{
|
|
|
|
MinEdge = emin,
|
|
|
|
MaxEdge = emax,
|
|
|
|
}
|
|
|
|
local data = vm:get_data()
|
|
|
|
for x=pos.x-r, pos.x+r do
|
|
|
|
for y=pos.y-r, pos.y+r do
|
|
|
|
for z=pos.z-r, pos.z+r do
|
|
|
|
local vi = area:indexp({x=x, y=y, z=z})
|
2021-03-15 02:32:19 +03:00
|
|
|
local nodename = get_name_from_content_id(data[vi])
|
2021-02-08 02:15:34 +03:00
|
|
|
local tex
|
|
|
|
if nodename == "mcl_core:barrier" then
|
|
|
|
tex = "mcl_core_barrier.png"
|
|
|
|
elseif nodename == "mcl_core:realm_barrier" then
|
|
|
|
tex = "mcl_core_barrier.png^[colorize:#FF00FF:127^[transformFX"
|
|
|
|
end
|
|
|
|
if tex then
|
2021-03-15 02:32:19 +03:00
|
|
|
add_particle({
|
2021-02-08 02:15:34 +03:00
|
|
|
pos = {x=x, y=y, z=z},
|
|
|
|
expirationtime = 1,
|
|
|
|
size = 8,
|
|
|
|
texture = tex,
|
|
|
|
glow = 14,
|
|
|
|
playername = name
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Update internal values
|
|
|
|
mcl_playerplus_internal[name].lastPos = pos
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- set to blank on join (for 3rd party mods)
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
mcl_playerplus_internal[name] = {
|
|
|
|
lastPos = nil,
|
|
|
|
swimDistance = 0,
|
|
|
|
jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly
|
|
|
|
}
|
2022-08-01 10:42:43 +03:00
|
|
|
mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0}
|
2021-02-08 02:15:34 +03:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- clear when player leaves
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
mcl_playerplus_internal[name] = nil
|
2021-04-17 20:34:23 +03:00
|
|
|
mcl_playerplus.elytra[player] = nil
|
2021-02-08 02:15:34 +03:00
|
|
|
end)
|
2021-04-23 13:34:24 +03:00
|
|
|
|
|
|
|
-- Don't change HP if the player falls in the water or through End Portal:
|
|
|
|
mcl_damage.register_modifier(function(obj, damage, reason)
|
|
|
|
if reason.type == "fall" then
|
2022-08-02 15:47:51 +03:00
|
|
|
if minetest.is_creative_enabled(obj:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
2021-04-23 13:34:24 +03:00
|
|
|
local pos = obj:get_pos()
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local velocity = obj:get_velocity() or obj:get_player_velocity() or {x=0,y=-10,z=0}
|
|
|
|
local v_axis_max = math.max(math.abs(velocity.x), math.abs(velocity.y), math.abs(velocity.z))
|
|
|
|
local step = {x = velocity.x / v_axis_max, y = velocity.y / v_axis_max, z = velocity.z / v_axis_max}
|
|
|
|
for i = 1, math.ceil(v_axis_max/5)+1 do -- trace at least 1/5 of the way per second
|
|
|
|
if not node or node.name == "ignore" then
|
|
|
|
minetest.get_voxel_manip():read_from_map(pos, pos)
|
|
|
|
node = minetest.get_node(pos)
|
|
|
|
end
|
|
|
|
if node then
|
2021-12-19 20:59:09 +03:00
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
if not def or def.walkable then
|
2021-04-23 13:34:24 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if minetest.get_item_group(node.name, "water") ~= 0 then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if node.name == "mcl_portals:portal_end" then
|
|
|
|
if mcl_portals and mcl_portals.end_teleport then
|
|
|
|
mcl_portals.end_teleport(obj)
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
2021-05-17 00:13:07 +03:00
|
|
|
if node.name == "mcl_core:cobweb" then
|
|
|
|
return 0
|
|
|
|
end
|
2021-05-28 20:26:00 +03:00
|
|
|
if node.name == "mcl_core:vine" then
|
|
|
|
return 0
|
|
|
|
end
|
2021-04-23 13:34:24 +03:00
|
|
|
end
|
|
|
|
pos = vector.add(pos, step)
|
|
|
|
node = minetest.get_node(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, -200)
|
|
|
|
|
|
|
|
minetest.register_on_respawnplayer(function(player)
|
|
|
|
local pos = player:get_pos()
|
|
|
|
minetest.add_particlespawner({
|
|
|
|
amount = 50,
|
|
|
|
time = 0.001,
|
|
|
|
minpos = vector.add(pos, 0),
|
|
|
|
maxpos = vector.add(pos, 0),
|
|
|
|
minvel = vector.new(-5,-5,-5),
|
|
|
|
maxvel = vector.new(5,5,5),
|
|
|
|
minexptime = 1.1,
|
|
|
|
maxexptime = 1.5,
|
|
|
|
minsize = 1,
|
|
|
|
maxsize = 2,
|
|
|
|
collisiondetection = false,
|
|
|
|
vertical = false,
|
|
|
|
texture = "mcl_particles_mob_death.png^[colorize:#000000:255",
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.sound_play("mcl_mobs_mob_poof", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 8,
|
|
|
|
}, true)
|
|
|
|
end)
|