mirror of
https://github.com/Samsuik/Sakura.git
synced 2026-01-06 15:41:49 +00:00
Add configuration for entity knockback
This commit is contained in:
@@ -592,19 +592,21 @@ index 0000000000000000000000000000000000000000..37f41089a2fb7ad11ceda07cf5de0fc8
|
||||
+}
|
||||
diff --git a/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..4e106a2bd35ff0250813b7a6f8224e7968c27722
|
||||
index 0000000000000000000000000000000000000000..311da21470ee8943b40da73c997af6625c5aa303
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
|
||||
@@ -0,0 +1,64 @@
|
||||
@@ -0,0 +1,93 @@
|
||||
+package me.samsuik.sakura.configuration;
|
||||
+
|
||||
+import com.mojang.logging.LogUtils;
|
||||
+import io.papermc.paper.configuration.Configuration;
|
||||
+import io.papermc.paper.configuration.ConfigurationPart;
|
||||
+import io.papermc.paper.configuration.PaperConfigurations;
|
||||
+import io.papermc.paper.configuration.type.number.IntOr;
|
||||
+import me.samsuik.sakura.entity.merge.MergeLevel;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+import org.slf4j.Logger;
|
||||
+import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
+import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
+
|
||||
+@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic", "RedundantSuppression"})
|
||||
@@ -659,6 +661,33 @@ index 0000000000000000000000000000000000000000..4e106a2bd35ff0250813b7a6f8224e79
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public Players players;
|
||||
+ public class Players extends ConfigurationPart {
|
||||
+ public Knockback knockback = new Knockback();
|
||||
+ public class Knockback extends ConfigurationPart {
|
||||
+ public double knockbackVertical = 0.4;
|
||||
+ public double knockbackVerticalLimit = 0.4;
|
||||
+ @Comment("In vanilla the vertical limit will only work when the entity is on the ground")
|
||||
+ public boolean verticalLimitRequireGround = true;
|
||||
+ public double knockbackHorizontal = 0.4;
|
||||
+ @Comment("Knockback caused by sweeping edge")
|
||||
+ public double sweepingEdgeKnockback = 0.4;
|
||||
+
|
||||
+ public Sprinting sprinting = new Sprinting();
|
||||
+ public class Sprinting extends ConfigurationPart {
|
||||
+ public boolean requireFullAttack = true;
|
||||
+ public double extraKnockback = 1.0;
|
||||
+ @Comment("Delay between extra knockback hits in milliseconds")
|
||||
+ public IntOr.Default knockbackDelay = IntOr.Default.USE_DEFAULT;
|
||||
+ }
|
||||
+
|
||||
+ @Comment("Knockback resistance attribute modifier")
|
||||
+ public double knockBackResistanceMod = 1.0;
|
||||
+ @Comment("Received by attacking a shielded enemy")
|
||||
+ public double shieldHitKnockback = 0.5;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/me/samsuik/sakura/configuration/mapping/InnerClassFieldDiscoverer.java b/src/main/java/me/samsuik/sakura/configuration/mapping/InnerClassFieldDiscoverer.java
|
||||
new file mode 100644
|
||||
|
||||
107
patches/server/0028-Configure-Entity-Knockback.patch
Normal file
107
patches/server/0028-Configure-Entity-Knockback.patch
Normal file
@@ -0,0 +1,107 @@
|
||||
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 c550014ff6c677a733e98d58dbe9f74fff77dd17..16343fb6b8e25789cb64ec536b7af037ad8d7e71 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -1532,7 +1532,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
d0 = (Math.random() - Math.random()) * 0.01D;
|
||||
}
|
||||
|
||||
- this.knockback(0.4000000059604645D, d0, d1, entity1); // Paper
|
||||
+ this.knockback((float) level().sakuraConfig().players.knockback.knockbackHorizontal, d0, d1, entity1); // Sakura // Paper
|
||||
if (!flag) {
|
||||
this.indicateDamage(d0, d1);
|
||||
}
|
||||
@@ -1579,7 +1579,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); // Paper
|
||||
+ target.knockback((float) level().sakuraConfig().players.knockback.shieldHitKnockback, target.getX() - this.getX(), target.getZ() - this.getZ(), this); // Sakura - configurable knockback // Paper
|
||||
}
|
||||
|
||||
private boolean checkTotemDeathProtection(DamageSource source) {
|
||||
@@ -1898,13 +1898,23 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
}
|
||||
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) * level().sakuraConfig().players.knockback.knockBackResistanceMod; // Sakura
|
||||
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 knockback
|
||||
+ double velocityX = vec3d.x / 2.0D - vec3d1.x;
|
||||
+ double velocityY = vec3d.y / 2.0D + (float) level().sakuraConfig().players.knockback.knockbackVertical;
|
||||
+ double velocityZ = vec3d.z / 2.0D - vec3d1.z;
|
||||
+
|
||||
+ if (!level().sakuraConfig().players.knockback.verticalLimitRequireGround || this.onGround()) {
|
||||
+ velocityY = Math.min(velocityY, (float) level().sakuraConfig().players.knockback.knockbackVerticalLimit);
|
||||
+ }
|
||||
+
|
||||
+ this.setDeltaMovement(velocityX, velocityY, velocityZ);
|
||||
+ // Sakura end
|
||||
// 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 8858aa55d32bda0d16ad602a5de557791c779208..41359c9783e575ead420867f207de55665850004 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
@@ -188,6 +188,7 @@ public abstract class Player extends LivingEntity {
|
||||
public boolean affectsSpawning = true;
|
||||
public net.kyori.adventure.util.TriState flyingFallDamage = net.kyori.adventure.util.TriState.NOT_SET;
|
||||
// Paper end
|
||||
+ private long lastSprintKnockback = -1; // Sakura
|
||||
|
||||
// CraftBukkit start
|
||||
public boolean fauxSleeping;
|
||||
@@ -1277,7 +1278,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;
|
||||
@@ -1327,10 +1328,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); // Paper
|
||||
+ ((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), this); // Paper
|
||||
+ target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * extraKnockback), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * extraKnockback), this); // Paper
|
||||
+ // Sakura end
|
||||
}
|
||||
|
||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
|
||||
@@ -1352,7 +1363,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); // Pa
|
||||
+ entityliving.knockback((float) level().sakuraConfig().players.knockback.sweepingEdgeKnockback, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Sakura // Pa
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
Reference in New Issue
Block a user