]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/player_mechanics/player_mechanics.lua
Remove third person sneaking eye offset
[Crafter.git] / mods / player_mechanics / player_mechanics.lua
index 7a84bc73c110042b10db6da9c02a8ecfd568b883..bfe9c4fc8162ff604012801d36332609ca4045a8 100644 (file)
@@ -21,6 +21,7 @@ minetest.register_on_joinplayer(function(player)
        temp_pool.old_state    = 0
        temp_pool.was_in_water = false
        temp_pool.swimming     = false
+       temp_pool.swim_bumped  = false
 end)
 
 -- resets the player's state on death
@@ -29,6 +30,7 @@ minetest.register_on_respawnplayer(function(player)
        name = player:get_player_name()
        pool[name].state = 0
        pool[name].was_in_water = false
+       pool[name].swim_bumped = false
        send_running_cancellation(player,false)
 end)
 
@@ -36,8 +38,7 @@ end)
 -- delete data on player leaving
 local name
 minetest.register_on_leaveplayer(function(player)
-       name = minetest.get_player_name()
-       
+       name = player:get_player_name()
        pool[name] = nil
 end)
 
@@ -88,6 +89,8 @@ local temp_pool
 local head
 local legs
 local in_water
+local swim_unlock
+local swim_bump
 local control_state = function(player)
        hunger    = get_player_hunger(player)
        name      = player:get_player_name()
@@ -98,26 +101,33 @@ local control_state = function(player)
        legs = minetest.get_item_group(get_player_legs_env(player),"water") > 0
 
        --check if in water
-       if legs or head then
+       if head then
                in_water = true
                temp_pool.swimming = true
-       else
-               in_water = false
-               temp_pool.swimming = false
+       elseif temp_pool.swimming == true then
+               swim_unlock = player_swim_under_check(player)
+               swim_bump = player_swim_check(player)
+               if swim_unlock then
+                       in_water = false
+                       temp_pool.swimming = false
+               elseif swim_bump then
+                       if player:get_player_velocity().y <= 0 then
+                               player:add_player_velocity(vector.new(0,9,0))
+                       end
+               end
        end
        
        if (in_water ~= temp_pool.was_in_water) or 
        (temp_pool.state ~= temp_pool.old_state) or 
        ((temp_pool.state == 1 or temp_pool.state == 2) and hunger <= 6) then
 
-               if not in_water and temp_pool.was_in_water then
+               if (not in_water and temp_pool.was_in_water) then
                        player:set_physics_override({
                                sneak   = true,
                        })
 
                        force_update_animation(player)
 
-                       player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
                        player:set_properties({
                                collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
                        })
@@ -129,10 +139,10 @@ local control_state = function(player)
 
                        force_update_animation(player)
 
-                       player:set_eye_offset({x=0,y=-6,z=0},{x=0,y=-6,z=5.9})
                        player:set_properties({
-                               collisionbox = {-0.3, 0.5, -0.3, 0.3, 1.2, 0.3},
+                               collisionbox = {-0.3, 0.8, -0.3, 0.3, 1.6, 0.3},
                        })
+                       player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
                end
 
                -- running/swimming fov modifier
@@ -165,7 +175,7 @@ local control_state = function(player)
                if temp_pool.state == 3 and in_water then
                        send_running_cancellation(player,false)
                elseif not in_water and temp_pool.state == 3 and temp_pool.old_state ~= 3 then
-                       player:set_eye_offset({x=0,y=-1,z=0},{x=0,y=-1,z=0})
+                       player:set_eye_offset({x=0,y=-1,z=0},{x=0,y=0,z=0})
                elseif not in_water and temp_pool.old_state == 3 and temp_pool.state ~= 3 then
                        player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
                end