9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2026-01-04 15:31:43 +00:00

Add legacy combat mechanics

This commit is contained in:
Samsuik
2024-06-06 21:55:44 +01:00
parent 5382720389
commit fdea20bfa3
9 changed files with 351 additions and 3 deletions

View File

@@ -606,10 +606,10 @@ index 0000000000000000000000000000000000000000..a22139d6f6775b7b8d635e126d2ea2bf
+}
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..bfac7683f768fbd27ba7f45cdbf964f1dcd0c174
index 0000000000000000000000000000000000000000..c52187c77d1012e8be494c5171915af4d7c202e4
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
@@ -0,0 +1,204 @@
@@ -0,0 +1,217 @@
+package me.samsuik.sakura.configuration;
+
+import com.mojang.logging.LogUtils;
@@ -732,6 +732,15 @@ index 0000000000000000000000000000000000000000..bfac7683f768fbd27ba7f45cdbf964f1
+
+ public Players players;
+ public class Players extends ConfigurationPart {
+ public Combat combat = new Combat();
+ public class Combat extends ConfigurationPart {
+ public boolean legacyCombatMechanics = false;
+ public boolean allowSweepAttacks = true;
+ public boolean shieldDamageReduction = false;
+ public boolean oldEnchantedGoldenApple = false;
+ public boolean fastHealthRegen = true;
+ }
+
+ public Knockback knockback = new Knockback();
+ public class Knockback extends ConfigurationPart {
+ public DoubleOr.Default knockbackVertical = DoubleOr.Default.USE_DEFAULT;
@@ -749,6 +758,9 @@ index 0000000000000000000000000000000000000000..bfac7683f768fbd27ba7f45cdbf964f1
+ public IntOr.Default knockbackDelay = IntOr.Default.USE_DEFAULT;
+ }
+
+ @NestedSetting({"projectiles", "fishing-hooks-apply-knockback"})
+ public boolean fishingHooksApplyKnockback;
+
+ @Comment("Knockback resistance attribute modifier")
+ public double knockbackResistanceModifier = 1.0;
+ @Comment("Received by attacking a shielded enemy")
@@ -757,6 +769,7 @@ index 0000000000000000000000000000000000000000..bfac7683f768fbd27ba7f45cdbf964f1
+
+ @Comment("Prevents players swimming using elytra or riptide to enter holes")
+ public boolean posesShrinkCollisionBox = true;
+ public boolean fishingHooksPullEntities = true;
+ }
+
+ public Entity entity;

View File

@@ -115,3 +115,20 @@ index 74130ccef989757b81507f084cc30a0e593ecaf3..898c3e44f36462acab9068c9665d08a3
}
// 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 882de08963c72614a3d26cd917916e42b7136042..a58dea66af79b15d78407e4b4b19dfcece011ba6 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

View File

@@ -0,0 +1,191 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 23 Feb 2024 01:48:08 +0000
Subject: [PATCH] Legacy player combat mechanics
diff --git a/src/main/java/me/samsuik/sakura/utils/CombatUtil.java b/src/main/java/me/samsuik/sakura/utils/CombatUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..b1c55ef758f61914e6df9b2c8096bce639b26353
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/utils/CombatUtil.java
@@ -0,0 +1,39 @@
+package me.samsuik.sakura.utils;
+
+import it.unimi.dsi.fastutil.objects.*;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.world.item.*;
+
+public final class CombatUtil {
+ private static final Reference2FloatMap<Item> LEGACY_ITEM_DAMAGE_MAP = new Reference2FloatOpenHashMap<>();
+
+ public static float getLegacyItemDamage(Item item) {
+ return LEGACY_ITEM_DAMAGE_MAP.getFloat(item);
+ }
+
+ private static float baseToolDamage(TieredItem item) {
+ return switch (item) {
+ case SwordItem swordItem -> 4.0f;
+ case AxeItem axeItem -> 3.0f;
+ case PickaxeItem pickaxeItem -> 2.0f;
+ case ShovelItem shovelItem -> 1.0f;
+ case null, default -> 0.0f;
+ };
+ }
+
+ static {
+ LEGACY_ITEM_DAMAGE_MAP.defaultReturnValue(Float.MIN_VALUE);
+
+ for (Item item : BuiltInRegistries.ITEM) {
+ if (item instanceof TieredItem tieredItem) {
+ LEGACY_ITEM_DAMAGE_MAP.put(item, baseToolDamage(tieredItem) + tieredItem.getTier().getAttackDamageBonus());
+ }
+
+ if (item instanceof HoeItem) {
+ LEGACY_ITEM_DAMAGE_MAP.put(item, 0.0f);
+ }
+ }
+
+ //LEGACY_ITEM_DAMAGE_MAP.put(Items.TRIDENT, LEGACY_ITEM_DAMAGE_MAP.getFloat(Items.DIAMOND_SWORD));
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 629d1190a6becabaa46210dfcb2eb45673847e6f..82f430eb1f2b43ccf7f621e119d58190964c1806 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -287,6 +287,72 @@ public abstract class LivingEntity extends Entity implements Attackable {
++this.noActionTime; // Above all the floats
}
// Spigot end
+ // Sakura start - legacy combat mechanics
+ private static final UUID LEGACY_COMBAT_MECHANICS_UUID = UUID.fromString("84ef96f8-9f48-4ae4-a26c-e04551324816");
+ private static final AttributeModifier LEGACY_ATTACK_SPEED_MODIFIER = new AttributeModifier(LEGACY_COMBAT_MECHANICS_UUID, "Legacy attack speed", 100.0, AttributeModifier.Operation.ADD_VALUE);
+
+ private void updateAttackSpeedModifier() {
+ AttributeInstance attackSpeed = this.getAttribute(Attributes.ATTACK_SPEED);
+ if (attackSpeed != null) {
+ attackSpeed.removeModifier(LEGACY_ATTACK_SPEED_MODIFIER);
+
+ if (this.level().sakuraConfig().players.combat.legacyCombatMechanics) {
+ attackSpeed.addTransientModifier(LEGACY_ATTACK_SPEED_MODIFIER);
+ }
+ }
+ }
+
+ protected final float getAttackDamageFromAttributes() {
+ AttributeInstance attackDamage = this.getAttribute(Attributes.ATTACK_DAMAGE);
+ AttributeModifier legacyModifier = null;
+
+ if (this.level().sakuraConfig().players.combat.legacyCombatMechanics) {
+ legacyModifier = this.getLegacyAttackModifier();
+ }
+
+ final double damage;
+ if (attackDamage == null || legacyModifier == null) {
+ damage = this.getAttributeValue(Attributes.ATTACK_DAMAGE);
+ } else {
+ attackDamage.addTransientModifier(legacyModifier);
+ damage = this.getAttributeValue(Attributes.ATTACK_DAMAGE);
+ attackDamage.removeModifier(legacyModifier);
+ }
+
+ return (float) damage;
+ }
+
+ private @Nullable AttributeModifier getLegacyAttackModifier() {
+ ItemStack itemstack = this.getLastHandItem(EquipmentSlot.MAINHAND);
+ net.minecraft.world.item.component.ItemAttributeModifiers modifiers = itemstack.get(DataComponents.ATTRIBUTE_MODIFIERS);
+ if (modifiers == null || modifiers.modifiers().isEmpty()) {
+ net.minecraft.world.item.component.ItemAttributeModifiers defaultModifiers = itemstack.getItem().getDefaultAttributeModifiers();
+ double baseAttack = 0.0;
+
+ for (net.minecraft.world.item.component.ItemAttributeModifiers.Entry entry : defaultModifiers.modifiers()) {
+ if (!entry.slot().test(EquipmentSlot.MAINHAND) || !entry.attribute().is(Attributes.ATTACK_DAMAGE))
+ continue;
+ if (entry.modifier().operation() != AttributeModifier.Operation.ADD_VALUE)
+ return null;
+ baseAttack += entry.modifier().amount();
+ }
+
+ float legacyAttack = me.samsuik.sakura.utils.CombatUtil.getLegacyItemDamage(itemstack.getItem());
+ double attackDifference = (double) legacyAttack - baseAttack;
+
+ if (baseAttack != 0.0f && legacyAttack != Float.MIN_VALUE) {
+ return new AttributeModifier(LEGACY_COMBAT_MECHANICS_UUID, "Legacy attack damage", attackDifference, AttributeModifier.Operation.ADD_VALUE);
+ }
+ }
+ return null;
+ }
+
+ protected final float calculateLegacySharpnessDamage() {
+ ItemStack itemstack = this.getMainHandItem();
+ int level = EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.SHARPNESS, itemstack);
+ return level * 1.25F - net.minecraft.world.item.enchantment.Enchantments.SHARPNESS.getDamageBonus(level, null);
+ }
+ // Sakura end - legacy combat mechanics
protected LivingEntity(EntityType<? extends LivingEntity> type, Level world) {
super(type, world);
@@ -2198,7 +2264,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
protected float getDamageAfterArmorAbsorb(DamageSource source, float amount) {
if (!source.is(DamageTypeTags.BYPASSES_ARMOR)) {
// this.hurtArmor(damagesource, f); // CraftBukkit - Moved into actuallyHurt(DamageSource, float)
+ // Sakura start - legacy combat mechanics
+ if (!this.level().sakuraConfig().players.combat.legacyCombatMechanics) {
amount = CombatRules.getDamageAfterAbsorb(amount, source, (float) this.getArmorValue(), (float) this.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
+ } else {
+ // See: applyArmorModifier(DamageSource, float)
+ int i = 25 - this.getArmorValue();
+ float f1 = amount * (float) i;
+ amount = f1 / 25.0F;
+ }
+ // Sakura end - legacy combat mechanics
}
return amount;
@@ -3294,6 +3369,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
});
}
+
+ // Sakura start - legacy combat mechanics
+ if (this instanceof ServerPlayer && enumitemslot == EquipmentSlot.MAINHAND) {
+ this.updateAttackSpeedModifier();
+ }
+ // Sakura end - legacy combat mechanics
}
}
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 70e3c8b1082d16cdbb9a4c179c53dafcc59ac1ed..951fa13dfe333e1e4aa467897d45bbe56d67f6b0 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1267,12 +1267,18 @@ public abstract class Player extends LivingEntity {
if (playerAttackEntityEvent.callEvent() && willAttack) { // Logic moved to willAttack local variable.
{
// Paper end - PlayerAttackEntityEvent
- float f = (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE);
+ float f = this.getAttackDamageFromAttributes(); // Sakura - legacy combat mechanics
float f1 = EnchantmentHelper.getDamageBonus(this.getMainHandItem(), target.getType());
float f2 = this.getAttackStrengthScale(0.5F);
+ // Sakura start - legacy combat mechanics
+ if (!this.level().sakuraConfig().players.combat.legacyCombatMechanics) {
f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2;
+ } else if (f1 != 0.0) {
+ f1 += this.calculateLegacySharpnessDamage();
+ }
+ // Sakura end - legacy combat mechanics
// this.resetAttackStrengthTicker(); // CraftBukkit - Moved to EntityLiving to reset the cooldown after the damage is dealt
if (target.getType().is(EntityTypeTags.REDIRECTABLE_PROJECTILE) && target instanceof Projectile) {
Projectile iprojectile = (Projectile) target;
@@ -1298,7 +1304,7 @@ public abstract class Player extends LivingEntity {
}
f += this.getItemInHand(InteractionHand.MAIN_HAND).getItem().getAttackDamageBonus(this, f);
- boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && !this.isSprinting(); // Paper - Add critical damage API; diff on change
+ boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && (this.level().sakuraConfig().players.combat.legacyCombatMechanics || !this.isSprinting()); // Sakura - legacy combat mechanics // Paper - Add critical damage API; diff on change
flag2 = flag2 && !this.level().paperConfig().entities.behavior.disablePlayerCrits; // Paper - Toggleable player crits
if (flag2) {

View File

@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 23 Feb 2024 01:49:20 +0000
Subject: [PATCH] Allow disabling sweep attacks
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 951fa13dfe333e1e4aa467897d45bbe56d67f6b0..72ce42011eea9b155c161bb03b02ba0a8f142039 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1377,7 +1377,7 @@ public abstract class Player extends LivingEntity {
// Paper end - Configurable sprint interruption on attack
}
- if (flag3) {
+ if (flag3 && this.level().sakuraConfig().players.combat.allowSweepAttacks) { // Sakura - allow disabling sweep attacks
float f4 = 1.0F + EnchantmentHelper.getSweepingDamageRatio(this) * f;
List<LivingEntity> list = this.level().getEntitiesOfClass(LivingEntity.class, target.getBoundingBox().inflate(1.0D, 0.25D, 1.0D));
Iterator iterator = list.iterator();

View File

@@ -0,0 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 23 Feb 2024 02:07:03 +0000
Subject: [PATCH] Change shields to reduce damage
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 82f430eb1f2b43ccf7f621e119d58190964c1806..a41e63a7672ae526062a86f03ddda82bee4e1fdb 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -2340,7 +2340,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
Function<Double, Double> blocking = new Function<Double, Double>() {
@Override
public Double apply(Double f) {
+ // Sakura start - shield damage reduction
+ if (!level().sakuraConfig().players.combat.shieldDamageReduction || damagesource.getDirectEntity() instanceof AbstractArrow) {
return -((LivingEntity.this.isDamageSourceBlocked(damagesource)) ? f : 0.0);
+ } else {
+ return -(LivingEntity.this.isBlocking() ? f * 0.5 : 0.0);
+ }
+ // Sakura end - shield damage reduction
}
};
float blockingModifier = blocking.apply((double) f).floatValue();

View File

@@ -0,0 +1,42 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 23 Feb 2024 14:40:32 +0000
Subject: [PATCH] Old enchanted golden apples
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a41e63a7672ae526062a86f03ddda82bee4e1fdb..78fb078bad84a984624ee17d0b060fd9d3cfb146 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -4498,6 +4498,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
public ItemStack eat(Level world, ItemStack stack) {
FoodProperties foodinfo = (FoodProperties) stack.get(DataComponents.FOOD);
+ // Sakura start - old enchanted golden apple
+ if (this.level().sakuraConfig().players.combat.oldEnchantedGoldenApple && foodinfo == net.minecraft.world.food.Foods.ENCHANTED_GOLDEN_APPLE) {
+ foodinfo = net.minecraft.world.food.Foods.LEGACY_ENCHANTED_GOLDEN_APPLE;
+ }
+ // Sakura end - old enchanted golden apple
if (foodinfo != null) {
world.playSound((net.minecraft.world.entity.player.Player) null, this.getX(), this.getY(), this.getZ(), this.getEatingSound(stack), SoundSource.NEUTRAL, 1.0F, 1.0F + (world.random.nextFloat() - world.random.nextFloat()) * 0.4F);
diff --git a/src/main/java/net/minecraft/world/food/Foods.java b/src/main/java/net/minecraft/world/food/Foods.java
index 60fd0e89552aeaa78b98dda32caa6766097d3108..7ced9d09ad09b53979214dae57a6347620e55569 100644
--- a/src/main/java/net/minecraft/world/food/Foods.java
+++ b/src/main/java/net/minecraft/world/food/Foods.java
@@ -36,6 +36,15 @@ public class Foods {
.effect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 3), 1.0F)
.alwaysEdible()
.build();
+ public static final FoodProperties LEGACY_ENCHANTED_GOLDEN_APPLE = new FoodProperties.Builder()
+ .nutrition(4)
+ .saturationModifier(1.2F)
+ .effect(new MobEffectInstance(MobEffects.REGENERATION, 600, 4), 1.0F)
+ .effect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 6000, 0), 1.0F)
+ .effect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 6000, 0), 1.0F)
+ .effect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 0), 1.0F)
+ .alwaysEdible()
+ .build();
public static final FoodProperties GOLDEN_APPLE = new FoodProperties.Builder()
.nutrition(4)
.saturationModifier(1.2F)

View File

@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Thu, 6 Jun 2024 18:18:28 +0100
Subject: [PATCH] Configure fast health regen
diff --git a/src/main/java/net/minecraft/world/food/FoodData.java b/src/main/java/net/minecraft/world/food/FoodData.java
index b89860d451d92ddda64b7e4144542b7fc5fd86f0..bb3e1a81356bda63e64f519cce96659801022925 100644
--- a/src/main/java/net/minecraft/world/food/FoodData.java
+++ b/src/main/java/net/minecraft/world/food/FoodData.java
@@ -83,7 +83,7 @@ public class FoodData {
boolean flag = player.level().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION);
- if (flag && this.saturationLevel > 0.0F && player.isHurt() && this.foodLevel >= 20) {
+ if (flag && this.saturationLevel > 0.0F && player.isHurt() && this.foodLevel >= 20 && player.level().sakuraConfig().players.combat.fastHealthRegen) { // Sakura - configure fast health regen
++this.tickTimer;
if (this.tickTimer >= this.saturatedRegenRate) { // CraftBukkit
float f = Math.min(this.saturationLevel, 6.0F);

View File

@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Thu, 6 Jun 2024 20:34:29 +0100
Subject: [PATCH] Add option for fishing hooks pulling entities
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 a58dea66af79b15d78407e4b4b19dfcece011ba6..92d381b0e824f734b0b6b186fa4c8601ab433241 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
@@ -601,7 +601,7 @@ public class FishingHook extends Projectile {
public void pullEntity(Entity entity) {
Entity entity1 = this.getOwner();
- if (entity1 != null) {
+ if (entity1 != null && (this.level().sakuraConfig().players.fishingHooksPullEntities || entity instanceof ItemEntity)) { // Sakura - Add option for fishing hooks pulling entities
Vec3 vec3d = (new Vec3(entity1.getX() - this.getX(), entity1.getY() - this.getY(), entity1.getZ() - this.getZ())).scale(0.1D);
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d));