Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall Damage In Water #74

Open
DayzePvP opened this issue Sep 26, 2020 · 1 comment
Open

Fall Damage In Water #74

DayzePvP opened this issue Sep 26, 2020 · 1 comment

Comments

@DayzePvP
Copy link

Expected Behavior

Water will keep you from taking fall damage
Ex: You jump from 20 blocks up in the air, you land in water to save your fall; taking no fall damage.

Actual Behavior

Fall damage calculations are messed up. Jumping from 20 blocks up will not save you from fall damage.
If you go into water and swim to the bottom of the ocean the fall damage carries so that once you meet the bottom you take damage just like if you fell from the same height but there was no water. To help you understand: https://youtu.be/j6SSEFDlg7g

Steps to Reproduce

  1. Make a tower in water
  2. Jump into water in survival
@TheShermanTanker
Copy link

@DayzePvP

Could you do me a favour and check to see if this bug still happens? For my own reference the relevant code is here:

protected void updateFallState(boolean onGround) {
        if (onGround) {
            fallDistance = this.highestPosition - this.getY();

            if (fallDistance > 0) {
                // check if we fell into at least 1 block of water
                if (this instanceof EntityLiving && !(this.level.getBlock(this.position) instanceof BlockBehaviorWater)) {
                    this.fall(fallDistance);
                }
                this.resetFallDistance();
            }
        }
    }

    public void fall(float fallDistance) {
        if (this.isPlayer && !level.getGameRules().get(GameRules.FALL_DAMAGE)) {
            return;
        }

        float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0));

        if (damage > 0) {
            this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.FALL, damage));
        }

        if (fallDistance > 0.75) {
            Block down = this.level.getBlock(Direction.DOWN.getUnitVector().add(this.getPosition().toInt()));

            if (down.getState().getType() == FARMLAND) {
                Event ev;

                if (this instanceof Player) {
                    ev = new PlayerInteractEvent((Player) this, null, down, null, PlayerInteractEvent.Action.PHYSICAL);
                } else {
                    ev = new EntityInteractEvent(this, down);
                }

                this.server.getEventManager().fire(ev);
                if (ev.isCancelled()) {
                    return;
                }
                this.level.setBlock(down.getPosition(), BlockState.get(BlockIds.DIRT), false, true);
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants