From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samsuik <40902469+Samsuik@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:52:56 +0000 Subject: [PATCH] Configure Entity Knockback diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java index d6ef140bcc35b10f78f2ec2f10c8a153395fc9df..5c967f9c77e75a84c4f584f729a00c4177082a8d 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -1436,7 +1436,7 @@ public abstract class LivingEntity extends Entity { } this.hurtDir = (float) (Mth.atan2(d1, d0) * 57.2957763671875D - (double) this.getYRot()); - this.knockback(0.4000000059604645D, d0, d1, entity1); + this.knockback((float) this.level.sakuraConfig.baseKnockback, d0, d1, entity1); // Sakura - configure entity knockback } else { this.hurtDir = (float) ((int) (Math.random() * 2.0D) * 180); } @@ -1483,7 +1483,7 @@ public abstract class LivingEntity extends Entity { } protected void blockedByShield(LivingEntity target) { - target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this); + target.knockback((float) this.level.sakuraConfig.shieldHitKnockback, target.getX() - this.getX(), target.getZ() - this.getZ(), this); // Sakura - configure entity knockback } private boolean checkTotemDeathProtection(DamageSource source) { @@ -1793,13 +1793,26 @@ public abstract class LivingEntity extends Entity { } public void knockback(double strength, double x, double z, Entity knockingBackEntity) { // Paper end - add knockbacking entity parameter - strength *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE); + strength *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE) * this.level.sakuraConfig.knockbackResistanceModifier; // Sakura - configure entity knockback if (strength > 0.0D) { this.hasImpulse = true; Vec3 vec3d = this.getDeltaMovement(); Vec3 vec3d1 = (new Vec3(x, 0.0D, z)).normalize().scale(strength); - this.setDeltaMovement(vec3d.x / 2.0D - vec3d1.x, this.onGround ? Math.min(0.4D, vec3d.y / 2.0D + strength) : vec3d.y, vec3d.z / 2.0D - vec3d1.z); + // Sakura start - configure entity knockback + double velocityX = vec3d.x / 2.0D - vec3d1.x; + double velocityY = vec3d.y / 2.0D + this.level.sakuraConfig.knockbackVertical.orElse(strength); + double velocityZ = vec3d.z / 2.0D - vec3d1.z; + + // this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : vec3d.y + if (!this.level.sakuraConfig.verticalKnockbackRequireGround || this.onGround) { + velocityY = Math.min(this.level.sakuraConfig.knockbackVerticalLimit, velocityY); + } else { + velocityY = vec3d.y; + } + + this.setDeltaMovement(velocityX, velocityY, velocityZ); + // Sakura end - configure entity knockback // Paper start - call EntityKnockbackByEntityEvent Vec3 currentMovement = this.getDeltaMovement(); org.bukkit.util.Vector delta = new org.bukkit.util.Vector(currentMovement.x - vec3d.x, currentMovement.y - vec3d.y, currentMovement.z - vec3d.z); diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java index 5c16235115a9233bce1f5b30bb020d105bdca3d1..92a7962edb01d5ef36a9e35cc0b6bacc879ccff2 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java +++ b/src/main/java/net/minecraft/world/entity/player/Player.java @@ -181,6 +181,7 @@ public abstract class Player extends LivingEntity { // Paper start public boolean affectsSpawning = true; // Paper end + private long lastSprintKnockback = -1; // Sakura - configure entity knockback // CraftBukkit start public boolean fauxSleeping; @@ -1229,7 +1230,7 @@ public abstract class Player extends LivingEntity { byte b0 = 0; int i = b0 + EnchantmentHelper.getKnockbackBonus(this); - if (this.isSprinting() && flag) { + if (this.isSprinting() && (!this.level.sakuraConfig.sprintingRequireFullAttack || flag)) { // Sakura sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility ++i; flag1 = true; @@ -1279,10 +1280,26 @@ public abstract class Player extends LivingEntity { if (flag5) { if (i > 0) { - if (target instanceof LivingEntity) { - ((LivingEntity) target).knockback((double) ((float) i * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper + // Sakura start - configure extra sprinting knockback + float extraKnockback = (float) i * 0.5F; + long millis = System.currentTimeMillis(); + long sinceLastKnockback = millis - this.lastSprintKnockback; + if (flag1) { // attackHasExtraKnockback + double knockbackToApply = 0.0; + if (sinceLastKnockback >= this.level.sakuraConfig.sprintingKnockbackDelay.orElse(0)) { + knockbackToApply = this.level.sakuraConfig.sprintingExtraKnockback; + this.lastSprintKnockback = millis; + } + // -0.5 is to negate the vanilla sprinting knockback + extraKnockback += -0.5F + (float) knockbackToApply; + } + if (extraKnockback == 0.0) { + // required + } else if (target instanceof LivingEntity) { + ((LivingEntity) target).knockback((double) (extraKnockback), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper } else { - target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F)); + target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * extraKnockback), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * extraKnockback)); + // Sakura end - configure extra sprinting knockback } this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D)); @@ -1304,7 +1321,7 @@ public abstract class Player extends LivingEntity { if (entityliving != this && entityliving != target && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) { // CraftBukkit start - Only apply knockback if the damage hits if (entityliving.hurt(DamageSource.playerAttack(this).sweep().critical(flag2), f4)) { // Paper - add critical damage API - entityliving.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper + entityliving.knockback((float) this.level.sakuraConfig.sweepingEdgeKnockback, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Sakura - configure entity knockback // Paper } // CraftBukkit end } diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java index 3789a0db398766f0fbc9e5ac5bf4228a0a0dac88..5ad727d59f67a49c2ed5cb09be11c86e0b74d9f0 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java +++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java @@ -290,6 +290,12 @@ public class FishingHook extends Projectile { this.setHookedEntity(entityHitResult.getEntity()); } + // Sakura start - configure entity knockback + if (this.level.sakuraConfig.fishingHooksApplyKnockback) { + Entity entity = entityHitResult.getEntity(); + entity.hurt(net.minecraft.world.damagesource.DamageSource.thrown(this, this.getOwner()), 0.0f); + } + // Sakura end - configure entity knockback } @Override