Animations for swiming

This commit is contained in:
epCode 2021-02-06 17:40:07 -08:00
parent 282af37555
commit df8bdfbc36
5 changed files with 41 additions and 16 deletions

View File

@ -94,7 +94,7 @@ 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() 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 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)) player:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
@ -359,6 +359,10 @@ mcl_player.player_register_model("mcl_armor_character.b3d", {
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=387},
swim_walk_mine = {x=389, y=408},
swim_stand = {x=434, y=434},
swim_mine = {x=411, y=430},
}, },
}) })
@ -514,12 +518,12 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
if name and hp_change < 0 then if name and hp_change < 0 then
local damage_type = armor.last_damage_types[name] local damage_type = armor.last_damage_types[name]
armor.last_damage_types[name] = nil armor.last_damage_types[name] = nil
-- Armor doesn't protect from set_hp (commands like /kill), -- Armor doesn't protect from set_hp (commands like /kill),
if reason.type == "set_hp" then if reason.type == "set_hp" then
return hp_change return hp_change
end end
local regular_reduction = reason.type ~= "drown" and reason.type ~= "fall" local regular_reduction = reason.type ~= "drown" and reason.type ~= "fall"
-- Account for potion effects (armor doesn't save the target) -- Account for potion effects (armor doesn't save the target)
@ -530,7 +534,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
local heal_max = 0 local heal_max = 0
local items = 0 local items = 0
local armor_damage = math.max(1, math.floor(math.abs(hp_change)/4)) local armor_damage = math.max(1, math.floor(math.abs(hp_change)/4))
local total_points = 0 local total_points = 0
local total_toughness = 0 local total_toughness = 0
local epf = 0 local epf = 0
@ -544,7 +548,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
local tough = stack:get_definition().groups["mcl_armor_toughness"] or 0 local tough = stack:get_definition().groups["mcl_armor_toughness"] or 0
total_points = total_points + pts total_points = total_points + pts
total_toughness = total_toughness + tough total_toughness = total_toughness + tough
local protection_level = enchantments.protection or 0 local protection_level = enchantments.protection or 0
if protection_level > 0 then if protection_level > 0 then
epf = epf + protection_level * 1 epf = epf + protection_level * 1
@ -566,7 +570,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
if feather_falling_level and reason.type == "fall" then if feather_falling_level and reason.type == "fall" then
epf = epf + feather_falling_level * 3 epf = epf + feather_falling_level * 3
end end
local did_thorns_damage = false local did_thorns_damage = false
local thorns_level = enchantments.thorns or 0 local thorns_level = enchantments.thorns or 0
if thorns_level then if thorns_level then
@ -580,7 +584,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
did_thorns_damage = true did_thorns_damage = true
end end
end end
-- Damage armor -- Damage armor
local use = stack:get_definition().groups["mcl_armor_uses"] or 0 local use = stack:get_definition().groups["mcl_armor_uses"] or 0
if use > 0 and regular_reduction then if use > 0 and regular_reduction then
@ -606,14 +610,14 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
end end
end end
local damage = math.abs(hp_change) local damage = math.abs(hp_change)
if regular_reduction then if regular_reduction then
-- Damage calculation formula (from <https://minecraft.gamepedia.com/Armor#Damage_protection>) -- Damage calculation formula (from <https://minecraft.gamepedia.com/Armor#Damage_protection>)
damage = damage * (1 - math.min(20, math.max((total_points/5), total_points - damage / (2+(total_toughness/4)))) / 25) damage = damage * (1 - math.min(20, math.max((total_points/5), total_points - damage / (2+(total_toughness/4)))) / 25)
end end
damage = damage * (1 - (math.min(20, epf) / 25)) damage = damage * (1 - (math.min(20, epf) / 25))
damage = math.floor(damage+0.5) damage = math.floor(damage+0.5)
if reason.type == "punch" and thorns_damage > 0 then if reason.type == "punch" and thorns_damage > 0 then
local obj = reason.object local obj = reason.object
if obj then if obj then
@ -630,7 +634,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
}) })
end end
end end
hp_change = -math.abs(damage) hp_change = -math.abs(damage)
armor.def[name].count = items armor.def[name].count = items

View File

@ -31,6 +31,10 @@ mcl_player.player_register_model("character.b3d", {
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},
}, },
}) })
@ -147,6 +151,8 @@ minetest.register_globalstep(function(dtime)
animation_speed_mod = animation_speed_mod / 2 animation_speed_mod = animation_speed_mod / 2
end end
local standing_on_water = minetest.get_item_group(mcl_playerinfo[name].node_stand, "water") ~= 0
-- Apply animations based on what the player is doing -- Apply animations based on what the player is doing
if player:get_hp() == 0 then if player:get_hp() == 0 then
player_set_animation(player, "lay") player_set_animation(player, "lay")
@ -155,20 +161,28 @@ minetest.register_globalstep(function(dtime)
player_anim[name] = nil player_anim[name] = nil
player_sneak[name] = controls.sneak player_sneak[name] = controls.sneak
end end
if controls.LMB and not controls.sneak then if controls.LMB and not controls.sneak and standing_on_water then
player_set_animation(player, "swim_walk_mine", animation_speed_mod)
elseif not controls.sneak and standing_on_water then
player_set_animation(player, "swim_walk", animation_speed_mod)
elseif controls.LMB and not controls.sneak and not standing_on_water then
player_set_animation(player, "walk_mine", animation_speed_mod) player_set_animation(player, "walk_mine", animation_speed_mod)
elseif controls.LMB and controls.sneak then elseif controls.LMB and controls.sneak and not standing_on_water then
player_set_animation(player, "sneak_walk_mine", animation_speed_mod) player_set_animation(player, "sneak_walk_mine", animation_speed_mod)
elseif not controls.sneak then elseif not controls.sneak and not standing_on_water then
player_set_animation(player, "walk", animation_speed_mod) player_set_animation(player, "walk", animation_speed_mod)
else else
player_set_animation(player, "sneak_walk", animation_speed_mod) player_set_animation(player, "sneak_walk", animation_speed_mod)
end end
elseif controls.LMB and not controls.sneak then elseif controls.LMB and not controls.sneak and standing_on_water then
player_set_animation(player, "swim_mine")
elseif controls.LMB and not controls.sneak and not standing_on_water then
player_set_animation(player, "mine") player_set_animation(player, "mine")
elseif controls.LMB and controls.sneak then elseif controls.LMB and controls.sneak then
player_set_animation(player, "sneak_mine") player_set_animation(player, "sneak_mine")
elseif not controls.sneak then elseif not controls.sneak and standing_on_water then
player_set_animation(player, "swim_stand", animation_speed_mod)
elseif not controls.sneak and not standing_on_water then
player_set_animation(player, "stand", animation_speed_mod) player_set_animation(player, "stand", animation_speed_mod)
else else
player_set_animation(player, "sneak_stand", animation_speed_mod) player_set_animation(player, "sneak_stand", animation_speed_mod)

View File

@ -39,6 +39,13 @@ minetest.register_globalstep(function(dtime)
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
-- controls head pitch when swiming
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,0,0))
-- 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
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 }})
end
else else
-- controls head pitch when not sneaking -- controls head pitch when not sneaking
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0)) player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0))