9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 16:29:16 +00:00
Files
SakuraMC/patches/server/0030-Configure-Entity-Knockback.patch
Samsuik 13f012eb71 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@84f6e6e Fix max temper API for llama (#10823)
PaperMC/Paper@672c077 handle BODY slot for non-mobs (#10822)
PaperMC/Paper@716b868 Use RegistryOps for loadAdvancement (#10799)
PaperMC/Paper@d9e659a Allow firework effects with no colors (#10814)
PaperMC/Paper@7e2b682 Fix skipping custom block entity tag (#10812)
PaperMC/Paper@ed85aac Flatten namespaced vanilla command alias redirects (#10821)
PaperMC/Paper@a31dc90 Several fixes and new api for experience merging/stacking (#9242)
PaperMC/Paper@efd91e5 Add registry-related argument types (#10770)
PaperMC/Paper@27d2ed8 Extend fishing API (#10634)
PaperMC/Paper@0fcf3e3 Deprecate InvAction#HOTBAR_MOVE_AND_READD (#10784)
PaperMC/Paper@8e6554a Fix sending disconnect packet in phases where it doesn't exist
PaperMC/Paper@06e69c8 Use CommandSourceStack in AsyncPlayerSendCommandsEvent (#10826)
PaperMC/Paper@a47e11d fix knockback events (#10831)
PaperMC/Paper@3181470 Add entity heal API (#10267)
PaperMC/Paper@0513374 Fire TabCompleteEvent for legacy commands (#10834)
PaperMC/Paper@5d8e53d Fix CommandSourceStack#bypassSelectorPermissions (#10837)
PaperMC/Paper@ac64751 Use RegistryOps in the correct places (#10843)
PaperMC/Paper@54fbd0c clarify what getEntityId actually returns (#10839)
PaperMC/Paper@b8f2101 Only assign blockstate data if super ctor did not (#10841)
PaperMC/Paper@4f13be9 Do not perform chunk existance check for I/O scheduling
PaperMC/Paper@79c1ce1 Add since to deprecated for removals (#10848)
PaperMC/Paper@88d76d9 Make Bogged implement Shearable (#10844)
PaperMC/Paper@bd5867a Handle alpha channel from potion_contents component (#10808)
2024-06-08 20:58:06 +01:00

135 lines
11 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 ba612c35d74be6b31495c17dbb8cf13ef28b526b..be9484d75e5c42ce784f7654e2db7b8848e124f6 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1568,7 +1568,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 ? io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE : io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
+ this.knockback((float) this.level().sakuraConfig().players.knockback.baseKnockback, d0, d1, entity1, entity1 == null ? io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE : io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events // Sakura - configure entity knockback
if (!flag) {
this.indicateDamage(d0, d1);
}
@@ -1622,7 +1622,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, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SHIELD_BLOCK); // CraftBukkit // Paper - fix attacker & knockback events
+ target.knockback((float) this.level().sakuraConfig().players.knockback.shieldHitKnockback, target.getX() - this.getX(), target.getZ() - this.getZ(), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SHIELD_BLOCK); // CraftBukkit // Paper - fix attacker & knockback events // Sakura - configure entity knockback
}
private boolean checkTotemDeathProtection(DamageSource source) {
@@ -1940,14 +1940,26 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
public void knockback(double d0, double d1, double d2, @Nullable Entity attacker, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause cause) { // Paper - knockback events
- d0 *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
+ d0 *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE) * this.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);
+ // Sakura start - configure entity knockback
+ double velocityX = vec3d.x / 2.0D - vec3d1.x;
+ double velocityY = vec3d.y / 2.0D + this.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 (!this.level().sakuraConfig().players.knockback.verticalKnockbackRequireGround || this.onGround()) {
+ velocityY = Math.min(this.level().sakuraConfig().players.knockback.knockbackVerticalLimit, velocityY);
+ } else {
+ velocityY = vec3d.y;
+ }
+ // Sakura end - configure entity knockback
// Paper start - knockback events
- Vec3 finalVelocity = new Vec3(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);
+ Vec3 finalVelocity = new Vec3(velocityX, velocityY, velocityZ); // Sakura - configure entity knockback
Vec3 diff = finalVelocity.subtract(vec3d);
io.papermc.paper.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) this.getBukkitEntity(), attacker, cause, d0, diff);
// Paper end - knockback events
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 c34de2a7303746ae236b7e81d87e7af42242baa7..3e0958f7b71fd7693d8f10d9b52144c32a039a0b 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -195,6 +195,7 @@ public abstract class Player extends LivingEntity {
public boolean ignoreFallDamageFromCurrentImpulse;
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;
@@ -1290,7 +1291,7 @@ public abstract class Player extends LivingEntity {
int i = 0;
i += EnchantmentHelper.getKnockbackBonus(this);
- if (this.isSprinting() && flag) {
+ if (this.isSprinting() && (!level().sakuraConfig().players.knockback.sprinting.requireFullAttack || flag)) { // Sakura - configure entity knockback
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;
@@ -1340,10 +1341,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, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
+ // 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().players.knockback.sprinting.knockbackDelay.value().orElse(0)) {
+ knockbackToApply = this.level().sakuraConfig().players.knockback.sprinting.extraKnockback;
+ 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, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
} 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));
@@ -1365,7 +1382,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, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SWEEP_ATTACK); // CraftBukkit // Paper - knockback events
+ entityliving.knockback((float) this.level().sakuraConfig().players.knockback.sweepingEdgeKnockback, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SWEEP_ATTACK); // CraftBukkit // Paper - knockback events // Sakura - configure entity knockback
}
// 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 7dd5e0b935d98d552c916f8412569ff4aa0e9b04..d9deb1b47b2430936d74e782cfc4a6ac32a16c91 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
@@ -298,6 +298,12 @@ public class FishingHook extends Projectile {
this.setHookedEntity(entityHitResult.getEntity());
}
+ // Sakura start - configure entity knockback
+ if (this.level().sakuraConfig().players.knockback.fishingHooksApplyKnockback) {
+ Entity entity = entityHitResult.getEntity();
+ entity.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0f);
+ }
+ // Sakura end - configure entity knockback
}
@Override