Tune caves
[oweals/minetest.git] / src / player.cpp
index 688be5d9890e060d899b3918d4b0d6b5e4163911..0d4a1cb695c05553fb9c21c7b8ac2273f7122475 100644 (file)
@@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "collision.h"
 #include "environment.h"
 #include "gamedef.h"
+#include "event.h"
 
 Player::Player(IGameDef *gamedef):
        touching_ground(false),
@@ -156,10 +157,6 @@ void Player::deSerialize(std::istream &is)
        setPitch(args.getFloat("pitch"));
        setYaw(args.getFloat("yaw"));
        setPosition(args.getV3F("position"));
-       bool craftresult_is_preview = true;
-       try{
-               craftresult_is_preview = args.getBool("craftresult_is_preview");
-       }catch(SettingNotFoundException &e){}
        try{
                hp = args.getS32("hp");
        }catch(SettingNotFoundException &e){
@@ -173,6 +170,9 @@ void Player::deSerialize(std::istream &is)
                // Convert players without craftpreview
                inventory.addList("craftpreview", 1);
 
+               bool craftresult_is_preview = true;
+               if(args.exists("craftresult_is_preview"))
+                       craftresult_is_preview = args.getBool("craftresult_is_preview");
                if(craftresult_is_preview)
                {
                        // Clear craftresult
@@ -294,8 +294,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        // This should always apply, otherwise there are glitches
        assert(d > pos_max_d);
 
-       float player_radius = BS*0.35;
-       float player_height = BS*1.7;
+       float player_radius = BS*0.30;
+       float player_height = BS*1.55;
        
        // Maximum distance over border for sneaking
        f32 sneak_max = BS*0.4;
@@ -368,6 +368,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
 
                Player is allowed to jump when this is true.
        */
+       bool touching_ground_was = touching_ground;
        touching_ground = false;
 
        /*std::cout<<"Checking collisions for ("
@@ -609,6 +610,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                        collision_info->push_back(info);
                }
        }
+
+       if(!touching_ground_was && touching_ground){
+               MtEvent *e = new SimpleTriggerEvent("PlayerRegainGround");
+               m_gamedef->event()->put(e);
+       }
 }
 
 void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
@@ -714,14 +720,20 @@ void LocalPlayer::applyControl(float dtime)
                }
                else if(touching_ground)
                {
-                       v3f speed = getSpeed();
                        /*
                                NOTE: The d value in move() affects jump height by
                                raising the height at which the jump speed is kept
                                at its starting value
                        */
-                       speed.Y = 6.5*BS;
-                       setSpeed(speed);
+                       v3f speed = getSpeed();
+                       if(speed.Y >= -0.5*BS)
+                       {
+                               speed.Y = 6.5*BS;
+                               setSpeed(speed);
+                               
+                               MtEvent *e = new SimpleTriggerEvent("PlayerJump");
+                               m_gamedef->event()->put(e);
+                       }
                }
                // Use the oscillating value for getting out of water
                // (so that the player doesn't fly on the surface)
@@ -757,5 +769,13 @@ void LocalPlayer::applyControl(float dtime)
        // Accelerate to target speed with maximum increment
        accelerate(speed, inc);
 }
+
+v3s16 LocalPlayer::getStandingNodePos()
+{
+       if(m_sneak_node_exists)
+               return m_sneak_node;
+       return floatToInt(getPosition(), BS);
+}
+
 #endif