1
0
Fork 0
This commit is contained in:
epCode 2021-02-06 17:50:27 -08:00
commit c5169e48a1
3 changed files with 307 additions and 318 deletions

View File

@ -94,19 +94,19 @@ armor.def = {
} }
armor.update_player_visuals = function(self, player) armor.update_player_visuals = function(self, player)
local player_holding = player:get_wielded_item():get_name()
if string.find(player_holding,"mcl_tools:") or player_holding == "mcl_mobitems:bone" or player_holding == "mcl_fishing:fishing_rod" then
player:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
elseif string.find(player_holding, "mcl_bows:bow") then
player:set_bone_position("Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20))
else
player:set_bone_position("Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90))
end
if not player then if not player then
return return
end end
local player_holding = player:get_wielded_item():get_name()
if string.find(player_holding,"mcl_tools:") or player_holding == "mcl_mobitems:bone" or player_holding == "mcl_fishing:fishing_rod" then
player:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
elseif string.find(player_holding, "mcl_bows:bow") then
player:set_bone_position("Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20))
else
player:set_bone_position("Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90))
end
local name = player:get_player_name() local name = player:get_player_name()
if self.textures[name] then if self.textures[name] then
mcl_player.player_set_textures(player, { mcl_player.player_set_textures(player, {

View File

@ -21,20 +21,16 @@ mcl_player.player_register_model("character.b3d", {
textures = {"character.png", }, textures = {"character.png", },
animations = { animations = {
-- Standard animations. -- Standard animations.
stand = {x=0, y=79}, stand = {x= 0, y= 79},
lay = {x=162, y=166}, lay = {x=162, y=166},
walk = {x=168, y=187}, walk = {x=168, y=187},
mine = {x=189, y=198}, mine = {x=189, y=198},
walk_mine = {x=200, y=219}, walk_mine = {x=200, y=219},
sit = {x=81, y=160}, sit = {x= 81, y=160},
sneak_stand = {x=222, y=302}, sneak_stand = {x=222, y=302},
sneak_mine = {x=346, y=366}, sneak_mine = {x=346, y=366},
sneak_walk = {x=304, y=323}, sneak_walk = {x=304, y=323},
sneak_walk_mine = {x=325, y=344}, sneak_walk_mine = {x=325, y=344},
swim_walk = {x=368, y=388},
swim_walk_mine = {x=389, y=409},
swim_stand = {x=434, y=434},
swim_mine = {x=411, y=430},
}, },
}) })

View File

@ -1,294 +1,287 @@
local S = minetest.get_translator("mcl_playerplus") local S = minetest.get_translator("mcl_playerplus")
-- Internal player state -- Internal player state
local mcl_playerplus_internal = {} local mcl_playerplus_internal = {}
local def = {} local def = {}
local time = 0 local time = 0
-- converts yaw to degrees -- converts yaw to degrees
local function degrees(rad) local function degrees(rad)
return rad * 180.0 / math.pi return rad * 180.0 / math.pi
end end
local pitch, name, node_stand, node_stand_below, node_head, node_feet, pos local pitch, name, node_stand, node_stand_below, node_head, node_feet, pos
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
time = time + dtime time = time + dtime
-- Update jump status immediately since we need this info in real time. -- 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. -- WARNING: This section is HACKY as hell since it is all just based on heuristics.
for _,player in pairs(minetest.get_connected_players()) do for _,player in pairs(minetest.get_connected_players()) do
local controls = player:get_player_control() local controls = player:get_player_control()
name = player:get_player_name() name = player:get_player_name()
-- controls head bone -- controls head bone
pitch = degrees(player:get_look_vertical()) * -1 pitch = degrees(player:get_look_vertical()) * -1
if controls.LMB then if controls.LMB then
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch,0,0)) player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch,0,0))
else else
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0)) player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0))
end end
if controls.sneak and player:get_attach() == nil then if controls.sneak and player:get_attach() == nil then
-- controls head pitch when sneaking -- controls head pitch when sneaking
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+36,0,0)) player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+36,0,0))
-- sets collisionbox, eye height, and nametag color accordingly -- sets collisionbox, eye height, and nametag color accordingly
if player:get_properties().collisionbox ~= {-0.35,0,-0.35,0.35,1.35,0.35} then if player:get_properties().collisionbox ~= {-0.35,0,-0.35,0.35,1.35,0.35} then
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.35,0.35}, eye_height = 1.35, nametag_color = { r = 255, b = 225, a = 0, g = 225 }}) player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.35,0.35}, eye_height = 1.35, nametag_color = { r = 255, b = 225, a = 0, g = 225 }})
end end
elseif minetest.get_item_group(mcl_playerinfo[name].node_stand, "water") ~= 0 then else
-- controls head pitch when swiming -- controls head pitch when not sneaking
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,0,0)) player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0))
-- sets collisionbox, eye height, and nametag color accordingly -- sets collisionbox, eye height, and nametag color accordingly
if player:get_properties().collisionbox ~= {-0.35,0.2,-0.35,0.35,1.8,0.35} then if player:get_properties().collisionbox ~= {-0.35,0,-0.35,0.35,1.8,0.35} then
player:set_properties({collisionbox = {-0.35,0.2,-0.35,0.35,1.8,0.35}, eye_height = 1.65, nametag_color = { r = 255, b = 225, a = 225, g = 225 }}) player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.65, nametag_color = { r = 255, b = 225, a = 225, g = 225 }})
end end
else end
-- controls head pitch when not sneaking
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0)) if mcl_playerplus_internal[name].jump_cooldown > 0 then
-- sets collisionbox, eye height, and nametag color accordingly mcl_playerplus_internal[name].jump_cooldown = mcl_playerplus_internal[name].jump_cooldown - dtime
if player:get_properties().collisionbox ~= {-0.35,0,-0.35,0.35,1.8,0.35} then end
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.65, nametag_color = { r = 255, b = 225, a = 225, g = 225 }}) if player:get_player_control().jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then
end
end pos = player:get_pos()
if mcl_playerplus_internal[name].jump_cooldown > 0 then node_stand = mcl_playerinfo[name].node_stand
mcl_playerplus_internal[name].jump_cooldown = mcl_playerplus_internal[name].jump_cooldown - dtime node_stand_below = mcl_playerinfo[name].node_stand_below
end node_head = mcl_playerinfo[name].node_head
if player:get_player_control().jump and mcl_playerplus_internal[name].jump_cooldown <= 0 then node_feet = mcl_playerinfo[name].node_feet
if not node_stand or not node_stand_below or not node_head or not node_feet then
pos = player:get_pos() return
end
node_stand = mcl_playerinfo[name].node_stand if not minetest.registered_nodes[node_stand] or not minetest.registered_nodes[node_stand_below] or not minetest.registered_nodes[node_head] or not minetest.registered_nodes[node_feet] then
node_stand_below = mcl_playerinfo[name].node_stand_below return
node_head = mcl_playerinfo[name].node_head end
node_feet = mcl_playerinfo[name].node_feet
if not node_stand or not node_stand_below or not node_head or not node_feet then -- Cause buggy exhaustion for jumping
return
end --[[ Checklist we check to know the player *actually* jumped:
if not minetest.registered_nodes[node_stand] or not minetest.registered_nodes[node_stand_below] or not minetest.registered_nodes[node_head] or not minetest.registered_nodes[node_feet] then * Not on or in liquid
return * Not on or at climbable
end * On walkable
* Not on disable_jump
-- Cause buggy exhaustion for jumping FIXME: This code is pretty hacky and it is possible to miss some jumps or detect false
jumps because of delays, rounding errors, etc.
--[[ Checklist we check to know the player *actually* jumped: What this code *really* needs is some kind of jumping callback which this engine lacks
* Not on or in liquid as of 0.4.15.
* Not on or at climbable ]]
* On walkable
* Not on disable_jump if minetest.get_item_group(node_feet, "liquid") == 0 and
FIXME: This code is pretty hacky and it is possible to miss some jumps or detect false minetest.get_item_group(node_stand, "liquid") == 0 and
jumps because of delays, rounding errors, etc. not minetest.registered_nodes[node_feet].climbable and
What this code *really* needs is some kind of jumping callback which this engine lacks not minetest.registered_nodes[node_stand].climbable and
as of 0.4.15. (minetest.registered_nodes[node_stand].walkable or minetest.registered_nodes[node_stand_below].walkable)
]] and minetest.get_item_group(node_stand, "disable_jump") == 0
and minetest.get_item_group(node_stand_below, "disable_jump") == 0 then
if minetest.get_item_group(node_feet, "liquid") == 0 and -- Cause exhaustion for jumping
minetest.get_item_group(node_stand, "liquid") == 0 and if mcl_sprint.is_sprinting(name) then
not minetest.registered_nodes[node_feet].climbable and mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_SPRINT_JUMP)
not minetest.registered_nodes[node_stand].climbable and else
(minetest.registered_nodes[node_stand].walkable or minetest.registered_nodes[node_stand_below].walkable) mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_JUMP)
and minetest.get_item_group(node_stand, "disable_jump") == 0 end
and minetest.get_item_group(node_stand_below, "disable_jump") == 0 then
-- Cause exhaustion for jumping -- Reset cooldown timer
if mcl_sprint.is_sprinting(name) then mcl_playerplus_internal[name].jump_cooldown = 0.45
mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_SPRINT_JUMP) end
else end
mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_JUMP) end
end
-- Run the rest of the code every 0.5 seconds
-- Reset cooldown timer if time < 0.5 then
mcl_playerplus_internal[name].jump_cooldown = 0.45 return
end end
end
end -- reset time for next check
-- FIXME: Make sure a regular check interval applies
-- Run the rest of the code every 0.5 seconds time = 0
if time < 0.5 then
return -- check players
end for _,player in pairs(minetest.get_connected_players()) do
-- who am I?
-- reset time for next check local name = player:get_player_name()
-- FIXME: Make sure a regular check interval applies
time = 0 -- where am I?
local pos = player:get_pos()
-- check players
for _,player in pairs(minetest.get_connected_players()) do -- what is around me?
-- who am I? local node_stand = mcl_playerinfo[name].node_stand
local name = player:get_player_name() local node_stand_below = mcl_playerinfo[name].node_stand_below
local node_head = mcl_playerinfo[name].node_head
-- where am I? local node_feet = mcl_playerinfo[name].node_feet
local pos = player:get_pos() if not node_stand or not node_stand_below or not node_head or not node_feet then
return
-- what is around me? end
local node_stand = mcl_playerinfo[name].node_stand
local node_stand_below = mcl_playerinfo[name].node_stand_below -- set defaults
local node_head = mcl_playerinfo[name].node_head def.speed = 1
local node_feet = mcl_playerinfo[name].node_feet
if not node_stand or not node_stand_below or not node_head or not node_feet then -- Standing on soul sand? If so, walk slower (unless player wears Soul Speed boots)
return if node_stand == "mcl_nether:soul_sand" then
end -- TODO: Tweak walk speed
-- TODO: Also slow down mobs
-- set defaults -- Slow down even more when soul sand is above certain block
def.speed = 1 local boots = player:get_inventory():get_stack("armor", 5)
local soul_speed = mcl_enchanting.get_enchantment(boots, "soul_speed")
-- Standing on soul sand? If so, walk slower (unless player wears Soul Speed boots) if soul_speed > 0 then
if node_stand == "mcl_nether:soul_sand" then playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", soul_speed * 0.105 + 1.3)
-- TODO: Tweak walk speed else
-- TODO: Also slow down mobs 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
-- Slow down even more when soul sand is above certain block playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.1)
local boots = player:get_inventory():get_stack("armor", 5) else
local soul_speed = mcl_enchanting.get_enchantment(boots, "soul_speed") playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4)
if soul_speed > 0 then end
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", soul_speed * 0.105 + 1.3) end
else 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 -- Reset speed decrease
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.1) playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface")
else end
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", 0.4)
end -- Is player suffocating inside node? (Only for solid full opaque cube type nodes
end -- without group disable_suffocation=1)
else local ndef = minetest.registered_nodes[node_head]
-- Reset speed decrease
playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface") if (ndef.walkable == nil or ndef.walkable == true)
end and (ndef.collision_box == nil or ndef.collision_box.type == "regular")
and (ndef.node_box == nil or ndef.node_box.type == "regular")
-- Is player suffocating inside node? (Only for solid full opaque cube type nodes and (ndef.groups.disable_suffocation ~= 1)
-- without group disable_suffocation=1) and (ndef.groups.opaque == 1)
local ndef = minetest.registered_nodes[node_head] and (node_head ~= "ignore")
-- Check privilege, too
if (ndef.walkable == nil or ndef.walkable == true) and (not minetest.check_player_privs(name, {noclip = true})) then
and (ndef.collision_box == nil or ndef.collision_box.type == "regular") if player:get_hp() > 0 then
and (ndef.node_box == nil or ndef.node_box.type == "regular") mcl_death_messages.player_damage(player, S("@1 suffocated to death.", name))
and (ndef.groups.disable_suffocation ~= 1) player:set_hp(player:get_hp() - 1)
and (ndef.groups.opaque == 1) end
and (node_head ~= "ignore") end
-- Check privilege, too
and (not minetest.check_player_privs(name, {noclip = true})) then -- Am I near a cactus?
if player:get_hp() > 0 then local near = minetest.find_node_near(pos, 1, "mcl_core:cactus")
mcl_death_messages.player_damage(player, S("@1 suffocated to death.", name)) if not near then
player:set_hp(player:get_hp() - 1) near = minetest.find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus")
end end
end if near then
-- Am I touching the cactus? If so, it hurts
-- Am I near a cactus? local dist = vector.distance(pos, near)
local near = minetest.find_node_near(pos, 1, "mcl_core:cactus") local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near)
if not near then if dist < 1.1 or dist_feet < 1.1 then
near = minetest.find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus") if player:get_hp() > 0 then
end mcl_death_messages.player_damage(player, S("@1 was prickled to death by a cactus.", name))
if near then player:set_hp(player:get_hp() - 1, { type = "punch", from = "mod" })
-- Am I touching the cactus? If so, it hurts end
local dist = vector.distance(pos, near) end
local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near) end
if dist < 1.1 or dist_feet < 1.1 then
if player:get_hp() > 0 then --[[ Swimming: Cause exhaustion.
mcl_death_messages.player_damage(player, S("@1 was prickled to death by a cactus.", name)) NOTE: As of 0.4.15, it only counts as swimming when you are with the feet inside the liquid!
player:set_hp(player:get_hp() - 1, { type = "punch", from = "mod" }) Head alone does not count. We respect that for now. ]]
end if minetest.get_item_group(node_feet, "liquid") ~= 0 or
end minetest.get_item_group(node_stand, "liquid") ~= 0 then
end local lastPos = mcl_playerplus_internal[name].lastPos
if lastPos then
--[[ Swimming: Cause exhaustion. local dist = vector.distance(lastPos, pos)
NOTE: As of 0.4.15, it only counts as swimming when you are with the feet inside the liquid! mcl_playerplus_internal[name].swimDistance = mcl_playerplus_internal[name].swimDistance + dist
Head alone does not count. We respect that for now. ]] if mcl_playerplus_internal[name].swimDistance >= 1 then
if minetest.get_item_group(node_feet, "liquid") ~= 0 or local superficial = math.floor(mcl_playerplus_internal[name].swimDistance)
minetest.get_item_group(node_stand, "liquid") ~= 0 then mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_SWIM * superficial)
local lastPos = mcl_playerplus_internal[name].lastPos mcl_playerplus_internal[name].swimDistance = mcl_playerplus_internal[name].swimDistance - superficial
if lastPos then end
local dist = vector.distance(lastPos, pos) end
mcl_playerplus_internal[name].swimDistance = mcl_playerplus_internal[name].swimDistance + dist
if mcl_playerplus_internal[name].swimDistance >= 1 then end
local superficial = math.floor(mcl_playerplus_internal[name].swimDistance)
mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_SWIM * superficial) -- Underwater: Spawn bubble particles
mcl_playerplus_internal[name].swimDistance = mcl_playerplus_internal[name].swimDistance - superficial if minetest.get_item_group(node_head, "water") ~= 0 then
end
end minetest.add_particlespawner({
amount = 10,
end time = 0.15,
minpos = { x = -0.25, y = 0.3, z = -0.25 },
-- Underwater: Spawn bubble particles maxpos = { x = 0.25, y = 0.7, z = 0.75 },
if minetest.get_item_group(node_head, "water") ~= 0 then attached = player,
minvel = {x = -0.2, y = 0, z = -0.2},
minetest.add_particlespawner({ maxvel = {x = 0.5, y = 0, z = 0.5},
amount = 10, minacc = {x = -0.4, y = 4, z = -0.4},
time = 0.15, maxacc = {x = 0.5, y = 1, z = 0.5},
minpos = { x = -0.25, y = 0.3, z = -0.25 }, minexptime = 0.3,
maxpos = { x = 0.25, y = 0.7, z = 0.75 }, maxexptime = 0.8,
attached = player, minsize = 0.7,
minvel = {x = -0.2, y = 0, z = -0.2}, maxsize = 2.4,
maxvel = {x = 0.5, y = 0, z = 0.5}, texture = "mcl_particles_bubble.png"
minacc = {x = -0.4, y = 4, z = -0.4}, })
maxacc = {x = 0.5, y = 1, z = 0.5}, end
minexptime = 0.3,
maxexptime = 0.8, -- Show positions of barriers when player is wielding a barrier
minsize = 0.7, local wi = player:get_wielded_item():get_name()
maxsize = 2.4, if wi == "mcl_core:barrier" or wi == "mcl_core:realm_barrier" then
texture = "mcl_particles_bubble.png" local pos = vector.round(player:get_pos())
}) local r = 8
end local vm = minetest.get_voxel_manip()
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})
-- Show positions of barriers when player is wielding a barrier local area = VoxelArea:new{
local wi = player:get_wielded_item():get_name() MinEdge = emin,
if wi == "mcl_core:barrier" or wi == "mcl_core:realm_barrier" then MaxEdge = emax,
local pos = vector.round(player:get_pos()) }
local r = 8 local data = vm:get_data()
local vm = minetest.get_voxel_manip() for x=pos.x-r, pos.x+r do
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}) for y=pos.y-r, pos.y+r do
local area = VoxelArea:new{ for z=pos.z-r, pos.z+r do
MinEdge = emin, local vi = area:indexp({x=x, y=y, z=z})
MaxEdge = emax, local nodename = minetest.get_name_from_content_id(data[vi])
} local tex
local data = vm:get_data() if nodename == "mcl_core:barrier" then
for x=pos.x-r, pos.x+r do tex = "mcl_core_barrier.png"
for y=pos.y-r, pos.y+r do elseif nodename == "mcl_core:realm_barrier" then
for z=pos.z-r, pos.z+r do tex = "mcl_core_barrier.png^[colorize:#FF00FF:127^[transformFX"
local vi = area:indexp({x=x, y=y, z=z}) end
local nodename = minetest.get_name_from_content_id(data[vi]) if tex then
local tex minetest.add_particle({
if nodename == "mcl_core:barrier" then pos = {x=x, y=y, z=z},
tex = "mcl_core_barrier.png" expirationtime = 1,
elseif nodename == "mcl_core:realm_barrier" then size = 8,
tex = "mcl_core_barrier.png^[colorize:#FF00FF:127^[transformFX" texture = tex,
end glow = 14,
if tex then playername = name
minetest.add_particle({ })
pos = {x=x, y=y, z=z}, end
expirationtime = 1, end
size = 8, end
texture = tex, end
glow = 14, end
playername = name
}) -- Update internal values
end mcl_playerplus_internal[name].lastPos = pos
end
end end
end
end end)
-- Update internal values -- set to blank on join (for 3rd party mods)
mcl_playerplus_internal[name].lastPos = pos minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
end
mcl_playerplus_internal[name] = {
end) lastPos = nil,
swimDistance = 0,
-- set to blank on join (for 3rd party mods) jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly
minetest.register_on_joinplayer(function(player) }
local name = player:get_player_name() end)
mcl_playerplus_internal[name] = { -- clear when player leaves
lastPos = nil, minetest.register_on_leaveplayer(function(player)
swimDistance = 0, local name = player:get_player_name()
jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly
} mcl_playerplus_internal[name] = nil
end) end)
-- clear when player leaves
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
mcl_playerplus_internal[name] = nil
end)