Jump to content

How can I cancel fall damage?


Recommended Posts

  • 5 months later...

I made it do the opposite (increase fall damage). It's basically a custom made behavior for the player, that extends EntityBehavior and overrides the OnFallToGround method in there. But I'm not quite sure it completely replaces the fall damage mechanic (actually I think my method adds on top of the vanilla method), I wrote that a looong time ago with little experience. But it increased the damage for sure, so I was content and never looked back at it again. Maybe you can find something useful here.

Patch json

Spoiler
[
	// HEALTH BEHAVIOR OVERHAUL
	{ 
		"side": "Server", 
		"file": "game:entities/humanoid/player", 
		"op": "add", 
		"path": "/client/behaviors/0", 
		"value": { "code": "BehaviorFTHealth" }
	},
	{ 
		"side": "Server", 
		"file": "game:entities/humanoid/player", 
		"op": "add", 
		"path": "/server/behaviors/0", 
		"value": { "code": "BehaviorFTHealth" }
	}
]

 

My custom behavior class

Spoiler
namespace fregtech
{
    internal class BehaviorFTHealth : EntityBehavior
    {
        public BehaviorFTHealth(Entity entity) : base(entity)
        {
        }

        public override void Initialize(EntityProperties properties, JsonObject typeAttributes)
        {
            base.Initialize(properties, typeAttributes);
        }

        // FALL DAMAGE OVERHAUL
        public override void OnFallToGround(Vec3d positionBeforeFalling, double withYMotion)
        {
            float fallDmgMod = 1.8f;
            IInventory inv;


            if (!this.entity.Properties.FallDamage)
            {
                return;
            }
            double yDistance = Math.Abs(positionBeforeFalling.Y - this.entity.Pos.Y);
            if (yDistance < 3.5)
            {
                return;
            }
            if (withYMotion > -0.19)
            {
                return;
            }

            // reduce from gear
            if(this.entity is EntityPlayer) // this.entity.Api.Side == EnumAppSide.Server
            {
                EntityPlayer plr = this.entity as EntityPlayer;
                // GearInventory = characterInventory:
                // 0 = head (clothes), 1 = cape (clothes), 2 = over shirt (clothes), 3 = pants (clothes), 4 = boots (clothes), 5 = gloves (misc)
                // 6 = necklace (misc), 7 = brooch (misc), 8 = mask (misc), 9 = belt (misc), 10 = bracelet (misc), 11 = under shirt (clothes)
                // 12 = helmet (armor), 13 = body (armor), 14 = legs (armor)
                inv = plr.GearInventory;
                
                if(inv != null)
                {
                    // each piece of clothing reduces fall damage by 5%
                    if (!inv[0].Empty) {fallDmgMod -= 0.05f;}
                    if (!inv[1].Empty) { fallDmgMod -= 0.05f; }
                    if (!inv[2].Empty) { fallDmgMod -= 0.05f; }
                    if (!inv[3].Empty) { fallDmgMod -= 0.05f; }
                    if (!inv[4].Empty) { // boots
                        if (inv[4].Itemstack.GetName() == "Catfeet boots") { fallDmgMod -= 0.25f; }
                        else { fallDmgMod -= 0.05f; }
                    }
                    if (!inv[11].Empty) { fallDmgMod -= 0.05f; }

                    // legs armor
                    if (!inv[14].Empty)
                    {

                    }
                }
            }

            if (fallDmgMod <= 0.0)
            {
                return;
            }

            double fallDamage = yDistance - 3.5;
            double expectedYMotion = -0.04100000113248825 * Math.Pow(fallDamage, 0.75) - 0.2199999988079071;
            double yMotionLoss = Math.Max(0.0, -expectedYMotion + withYMotion);
            fallDamage -= 20.0 * yMotionLoss;
            if (fallDamage <= 0.0)
            {
                return;
            }
            
            //// TESTING
            //if (this.entity.World.Side == EnumAppSide.Client)
            //{
            //    (this.entity.Api as ICoreClientAPI).TriggerIngameError(this, "error-msg", Lang.Get("Extra damage factor: " + fallDmgMod, Array.Empty<object>()));
            //}

            this.entity.ReceiveDamage(new DamageSource
            {
                Source = EnumDamageSource.Fall,
                Type = EnumDamageType.Gravity
            }, (float)fallDamage*fallDmgMod);
        }

        public override string PropertyName()
        {
            //throw new NotImplementedException();
            return "extrafalldamage";
        }
    }
}

 

Maybe you can just write something like this

public override void OnFallToGround(Vec3d positionBeforeFalling, double withYMotion)
{
	return;
}

But again, I'm very unsure that this method completely replaces the vanilla mechanic.

 

  • Like 1
Link to comment
Share on other sites

8 minutes ago, Frepo said:

I made it do the opposite (increase fall damage). It's basically a custom made behavior for the player, that extends EntityBehavior and overrides the OnFallToGround method in there. But I'm not quite sure it completely replaces the fall damage mechanic (actually I think my method adds on top of the vanilla method), I wrote that a looong time ago with little experience. But it increased the damage for sure, so I was content and never looked back at it again. Maybe you can find something useful here.

Patch json

  Reveal hidden contents

	 
		  
		  
		  
		  
		    
	
	 
		  
		  
		  
		  
		    
	

 

My custom behavior class

  Hide contents
namespace fregtech
{
    internal class BehaviorFTHealth : EntityBehavior
    {
        public BehaviorFTHealth(Entity entity) : base(entity)
        {
        }

        public override void Initialize(EntityProperties properties, JsonObject typeAttributes)
        {
            base.Initialize(properties, typeAttributes);
        }

        // FALL DAMAGE OVERHAUL
        public override void OnFallToGround(Vec3d positionBeforeFalling, double withYMotion)
        {
            float fallDmgMod = 1.8f;
            IInventory inv;


            if (!this.entity.Properties.FallDamage)
            {
                return;
            }
            double yDistance = Math.Abs(positionBeforeFalling.Y - this.entity.Pos.Y);
            if (yDistance < 3.5)
            {
                return;
            }
            if (withYMotion > -0.19)
            {
                return;
            }

            // reduce from gear
            if(this.entity is EntityPlayer) // this.entity.Api.Side == EnumAppSide.Server
            {
                EntityPlayer plr = this.entity as EntityPlayer;
                // GearInventory = characterInventory:
                // 0 = head (clothes), 1 = cape (clothes), 2 = over shirt (clothes), 3 = pants (clothes), 4 = boots (clothes), 5 = gloves (misc)
                // 6 = necklace (misc), 7 = brooch (misc), 8 = mask (misc), 9 = belt (misc), 10 = bracelet (misc), 11 = under shirt (clothes)
                // 12 = helmet (armor), 13 = body (armor), 14 = legs (armor)
                inv = plr.GearInventory;
                
                if(inv != null)
                {
                    // each piece of clothing reduces fall damage by 5%
                    if (!inv[0].Empty) {fallDmgMod -= 0.05f;}
                    if (!inv[1].Empty) { fallDmgMod -= 0.05f; }
                    if (!inv[2].Empty) { fallDmgMod -= 0.05f; }
                    if (!inv[3].Empty) { fallDmgMod -= 0.05f; }
                    if (!inv[4].Empty) { // boots
                        if (inv[4].Itemstack.GetName() == "Catfeet boots") { fallDmgMod -= 0.25f; }
                        else { fallDmgMod -= 0.05f; }
                    }
                    if (!inv[11].Empty) { fallDmgMod -= 0.05f; }

                    // legs armor
                    if (!inv[14].Empty)
                    {

                    }
                }
            }

            if (fallDmgMod <= 0.0)
            {
                return;
            }
           
              
            
                
            
            
               
            
                      
            

            
                  
                  
             
        

        
            
             
        
    

 

Tal vez puedas escribir algo como esto.



	

Pero nuevamente, no estoy muy seguro de que este método reemplace completamente la mecánica básica.

 

Thank you very much for your contribution, as soon as I have some free time I will try it.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.