9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 08:19:26 +00:00
Files
SakuraMC/patches/server/0028-Configure-Entity-Knockback.patch
Samsuik 80f6368f2a Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@00ef8bd Fix Entity#isTicking and update Paper entity command (#11590)
PaperMC/Paper@6483ecb Updated Upstream (Bukkit/CraftBukkit)
PaperMC/Paper@17dbf74 Improve CraftEntity and CraftPlayer equals
PaperMC/Paper@0af4e84 [ci skip] Add identifying line to some larger/optimization patches
PaperMC/Paper@bcbd108 Call CraftPlayer#onEntityRemove for all online players (#11598)
PaperMC/Paper@e47f79a Configure mockito agent (#11560)
PaperMC/Paper@94ea770 Re-add exact choice shapeless support (#11546)
PaperMC/Paper@2e6eafb Improve Minecart#getMinecartMaterial (#11544)
PaperMC/Paper@9d1c91d [ci skip] Fix UseCooldownComponent jd (#11565)
PaperMC/Paper@59b79c8 Fix NPE with enchantable (#11557)
PaperMC/Paper@6da7b9e Update Eigencraft patch to 1.21.3 (#11553)
PaperMC/Paper@1ef4c0e Improve performance of RecipeMap#removeRecipe (#11547)
PaperMC/Paper@52fb265 Optimize custom map rendering (#11000)
PaperMC/Paper@661839e Fix and optimize getChunkCount (#11610)
PaperMC/Paper@c60af44 Fix experimental minecart collisions on sloped rails
PaperMC/Paper@13f48d8 [ci skip] Rebuild patches
PaperMC/Paper@be886cf Fix Naming issue inside Add PlayerArmorChangeEvent (#11614)
PaperMC/Paper@7b13d93 Updated Upstream (Bukkit/CraftBukkit) (#11626)
PaperMC/Paper@4e2291e chore: refactor issue templates
PaperMC/Paper@bc4a705 [ci skip] chore: change paste.gg links to mclo.gs (#11629)
PaperMC/Paper@3480489 Update Alternate Current patch to 1.21.3 (#11602)
PaperMC/Paper@575c1c4 Update disableGameRuleLimits casing
PaperMC/Paper@11d708d [ci skip] Add missing feature patch identifiers
PaperMC/Paper@daf3113 Make logs less annoying
PaperMC/Paper@4e01ede Fix inverted global skip check
PaperMC/Paper@d8b66dd fix: move to jline-terminal-ffm on java 22+ and fall back to jni on 21, fixes #10405
PaperMC/Paper@6735c60 Fix enderchest opening animation (#11635)
PaperMC/Paper@de6173b Item DataComponent API (#10845)
PaperMC/Paper@8c5b837 Rework async chunk api implementation
PaperMC/Paper@37b9630 Do not create unneccessary callback in ChunkTaskScheduler#scheduleChunkLoad
PaperMC/Paper@878da16 Fix non block ticking chunks not sending block/light updates
PaperMC/Paper@fdef6d3 Add missing NotNull annotation for getChunksAtAsync cb param
PaperMC/Paper@01dd50f [ci skip] Rebuild patches
PaperMC/Paper@f9f964d Fix drops for shearing bogged (#11628)
PaperMC/Paper@21cc763 Fix drops for shearing mushroom cow (#11632)
PaperMC/Paper@57eab3e Add PlayerItemGroupCooldownEvent (#11625)
PaperMC/Paper@d0dcd7d Fix incorrect invulnerability damage reduction (#11599)
PaperMC/Paper@85bfdc0 Fix NPE when EntityResurrectEvent is uncancelled (#11636)
PaperMC/Paper@c28d89d Update spark
PaperMC/Paper@55475f0 [ci skip] Fix typos
PaperMC/Paper@f8e2a67 Check for AbstractBoat instead of Boat in EAR ignore list
2024-11-21 18:21:18 +00:00

131 lines
9.7 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 e6b6987b46294a96f10d3aa56e8bdc4e25a4c9bf..daf37223c47f30f6da23a996c8b0473e473cbba2 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1604,7 +1604,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
// Paper end - Check distance in entity interactions
- 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);
}
@@ -1674,7 +1674,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) {
@@ -2024,7 +2024,7 @@ 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
@@ -2035,9 +2035,21 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
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, 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 c3e90356ab409f408b767618db718e3926edf8d1..e50b64ba18fe8a4536b6f8aadca93064cd9f47f7 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -197,6 +197,7 @@ public abstract class Player extends LivingEntity {
private int currentImpulseContextResetGraceTime;
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;
@@ -1261,7 +1262,7 @@ public abstract class Player extends LivingEntity {
boolean flag = f2 > 0.9F;
boolean flag1;
- if (this.isSprinting() && flag) {
+ if (this.isSprinting() && (!this.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
flag1 = true;
} else {
@@ -1304,7 +1305,21 @@ public abstract class Player extends LivingEntity {
float f5 = this.getKnockback(target, damagesource) + (flag1 ? 1.0F : 0.0F);
if (f5 > 0.0F) {
- if (target instanceof LivingEntity) {
+ // Sakura start - configure entity knockback; extra sprinting knockback
+ 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;
+ }
+ f5 = (f5 - 1.0f) + ((float) knockbackToApply * 2.0f);
+ }
+ if (f5 == 0.0f) {
+ // required
+ } else if (target instanceof LivingEntity) {
+ // Sakura end - configure entity knockback; extra sprinting knockback
LivingEntity entityliving1 = (LivingEntity) target;
entityliving1.knockback((double) (f5 * 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); // Paper - knockback events
@@ -1337,7 +1352,7 @@ public abstract class Player extends LivingEntity {
continue;
}
// CraftBukkit end
- entityliving2.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
+ entityliving2.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); // Sakura - configure entity knockback // CraftBukkit // Paper - knockback events
// entityliving2.hurt(damagesource, f7); // CraftBukkit - moved up
Level world = this.level();
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 4daa69c6be6d48563e30343a7e40e4da9ec7e5ad..c563f71fb79990771d032b8044b8f676d8d21058 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
@@ -304,6 +304,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