mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 15:59:26 +00:00
111 lines
9.1 KiB
Diff
111 lines
9.1 KiB
Diff
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 6162631e863dd15c7fdb70dbde2f85d273c7020b..e75322367764805443f9a9f5639d804b87a0ab5e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1549,7 +1549,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
d0 = (Math.random() - Math.random()) * 0.01D;
|
|
}
|
|
|
|
- this.knockback(0.4000000059604645D, d0, d1, entity1, entity1 == null ? EntityKnockbackEvent.KnockbackCause.DAMAGE : EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
|
|
+ this.knockback((float) level().sakuraConfig().players.knockback.baseKnockback, d0, d1, entity1, entity1 == null ? EntityKnockbackEvent.KnockbackCause.DAMAGE : EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // Sakura - configure entity knockback // CraftBukkit
|
|
if (!flag) {
|
|
this.indicateDamage(d0, d1);
|
|
}
|
|
@@ -1596,7 +1596,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
}
|
|
|
|
protected void blockedByShield(LivingEntity target) {
|
|
- target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this, EntityKnockbackEvent.KnockbackCause.SHIELD_BLOCK); // CraftBukkit // Paper - fix attacker
|
|
+ target.knockback((float) level().sakuraConfig().players.knockback.shieldHitKnockback, target.getX() - this.getX(), target.getZ() - this.getZ(), this, EntityKnockbackEvent.KnockbackCause.SHIELD_BLOCK); // Sakura - configure entity knockback // CraftBukkit // Paper - fix attacker
|
|
}
|
|
|
|
private boolean checkTotemDeathProtection(DamageSource source) {
|
|
@@ -1914,13 +1914,26 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
}
|
|
|
|
public void knockback(double d0, double d1, double d2, @Nullable Entity attacker, EntityKnockbackEvent.KnockbackCause cause) { // Paper - add nullable to attacker param
|
|
- d0 *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
|
|
+ d0 *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE) * level().sakuraConfig().players.knockback.knockbackResistanceModifier; // Sakura - configure entity knockback
|
|
if (true || d0 > 0.0D) { // CraftBukkit - Call event even when force is 0
|
|
//this.hasImpulse = true; // CraftBukkit - Move down
|
|
Vec3 vec3d = this.getDeltaMovement();
|
|
Vec3 vec3d1 = (new Vec3(d1, 0.0D, d2)).normalize().scale(d0);
|
|
|
|
- EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) this.getBukkitEntity(), attacker, cause, d0, vec3d1, vec3d.x / 2.0D - vec3d1.x, this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : 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 + level().sakuraConfig().players.knockback.knockbackVertical.or(d0);
|
|
+ double velocityZ = vec3d.z / 2.0D - vec3d1.z;
|
|
+
|
|
+ // this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : vec3d.y
|
|
+ if (!level().sakuraConfig().players.knockback.verticalKnockbackRequireGround || this.onGround()) {
|
|
+ velocityY = Math.min(level().sakuraConfig().players.knockback.knockbackVerticalLimit, velocityY);
|
|
+ } else {
|
|
+ velocityY = vec3d.y;
|
|
+ }
|
|
+
|
|
+ EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) this.getBukkitEntity(), attacker, cause, d0, vec3d1, velocityX, velocityY, velocityZ);
|
|
+ // Sakura end - configure entity knockback
|
|
if (event.isCancelled()) {
|
|
return;
|
|
}
|
|
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 74dcfabdc66ef289b8d6a5c6606579b5321af1db..94577ca6de11d23d2a2561b645212a7717088974 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -183,6 +183,7 @@ public abstract class Player extends LivingEntity {
|
|
public float hurtDir; // Paper - protected -> public
|
|
public boolean affectsSpawning = true; // Paper - Affects Spawning API
|
|
public net.kyori.adventure.util.TriState flyingFallDamage = net.kyori.adventure.util.TriState.NOT_SET; // Paper - flying fall damage
|
|
+ private long lastSprintKnockback = -1; // Sakura - configure entity knockback
|
|
|
|
// CraftBukkit start
|
|
public boolean fauxSleeping;
|
|
@@ -1274,7 +1275,7 @@ public abstract class Player extends LivingEntity {
|
|
byte b0 = 0;
|
|
int i = b0 + EnchantmentHelper.getKnockbackBonus(this);
|
|
|
|
- if (this.isSprinting() && flag) {
|
|
+ if (this.isSprinting() && (!level().sakuraConfig().players.knockback.sprinting.requireFullAttack || 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;
|
|
@@ -1324,10 +1325,20 @@ public abstract class Player extends LivingEntity {
|
|
|
|
if (flag5) {
|
|
if (i > 0) {
|
|
+ // Sakura start - configure extra sprinting knockback
|
|
+ float extraKnockback = (float) i * 0.5F;
|
|
+ long millis = System.currentTimeMillis();
|
|
+ long sinceLastKnockback = millis - lastSprintKnockback;
|
|
+
|
|
+ if (flag1 && sinceLastKnockback >= level().sakuraConfig().players.knockback.sprinting.knockbackDelay.value().orElse(0)) {
|
|
+ extraKnockback += -0.5F + (float) level().sakuraConfig().players.knockback.sprinting.extraKnockback;
|
|
+ lastSprintKnockback = millis;
|
|
+ }
|
|
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, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
|
|
+ ((LivingEntity) target).knockback((double) (extraKnockback), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
|
|
} 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), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
+ target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * extraKnockback), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * extraKnockback), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
+ // Sakura end - configure extra sprinting knockback
|
|
}
|
|
|
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
|
|
@@ -1349,7 +1360,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(this.damageSources().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, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit
|
|
+ entityliving.knockback((float) level().sakuraConfig().players.knockback.sweepingEdgeKnockback, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // Sakura - configure entity knockback // CraftBukkit
|
|
}
|
|
// CraftBukkit end
|
|
}
|