mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@7fbb827 Finish API patches PaperMC/Paper@8a37f93 62 PaperMC/Paper@2055809 117 PaperMC/Paper@0b75522 194 PaperMC/Paper@ec05cb8 279 PaperMC/Paper@0bc9aee 385 PaperMC/Paper@27e29cc 487/1053 PaperMC/Paper@083bd9e 531/1053 PaperMC/Paper@ed2ea45 538 PaperMC/Paper@ba163e1 585/1053 PaperMC/Paper@8731266 650/1053 PaperMC/Paper@52b49fb 788/1053 PaperMC/Paper@33b36cd update some patches PaperMC/Paper@14c0336 922 PaperMC/Paper@a399f23 956 PaperMC/Paper@4140de2 960 PaperMC/Paper@6d4e235 988 PaperMC/Paper@6a34750 Move unapplied patches to the back PaperMC/Paper@3c04f9f Fix a few compile errors PaperMC/Paper@0d3ce2d Fix more compile issues PaperMC/Paper@a308c7c Fix more compile issues PaperMC/Paper@69d1d0a Pretend to fix compile errors PaperMC/Paper@547f09d Some work on the ItemMend events PaperMC/Paper@184a943 Adopt previous commit changes in API PaperMC/Paper@5442bff Make it compile PaperMC/Paper@038f8d9 Fixup and deprecate player profiles in ping event PaperMC/Paper@66f7b67 Fix body equipmentslot and effect enum PaperMC/Paper@38b3182 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@df633e5 DataConverter 1.21 PaperMC/Paper@f569389 Update ConcurrentUtil PaperMC/Paper@5fca3ae update generated API PaperMC/Paper@188cff2 remove old vanilla goals PaperMC/Paper@ffe310a remove api that was scheduled for removal PaperMC/Paper@730882f Chunk System and Starlight WIP PaperMC/Paper@512fd08 Update Gradle Wrapper to v8.8 PaperMC/Paper@097284d Bump tiny-remapper to 0.10.3 PaperMC/Paper@ee9b820 Update more optimization patches PaperMC/Paper@5d834b1 rebuild patches PaperMC/Paper@4bc15f1 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@0b6701d Revert DamageSource#getCausingEntity to vanilla PaperMC/Paper@5bd7f4e Update AbstractArrow item method implementations for 1.20.6 (#10885) PaperMC/Paper@fb511c6 Fix Player#sendBlockState (#10855) PaperMC/Paper@b420038 Fix ItemMeta#removeEnchantments (#10886) PaperMC/Paper@a835ad1 Merge remote-tracking branch 'origin/dev/1.21' into dev/1.21 PaperMC/Paper@04dad71 Improve enchantWithLevels logic PaperMC/Paper@0008fa1 Add back more optimization patches PaperMC/Paper@56b5b7d Fix max chunk status checks PaperMC/Paper@c1aefee correctly change enchantment registry to a 'delayed' version PaperMC/Paper@d41636f Add back RecipeIterator fixes patch (#10887) PaperMC/Paper@7df4725 Configurable damage tick when blocking with shield (#10877) PaperMC/Paper@3555a77 Properly forward DispenseEvent #getItem to saddle PaperMC/Paper@e339ec2 Deprecate BlockData#getDestroySpeed for removal PaperMC/Paper@b090c65 Remove unnecessary changes from chunk status fix PaperMC/Paper@5e7cd07 add some generated typed/tag keys PaperMC/Paper@5a5412c Owen fixing stuff!!! PaperMC/Paper@7240d9d Restore functionality to sand dupe setting PaperMC/Paper@f873bce Fix NPE in V3808 PaperMC/Paper@1f8e7a7 address compile and test issue (#10890) PaperMC/Paper@60f3bd8 De-deprecate BlockData#getDestroySpeed PaperMC/Paper@752f957 Add back more patches PaperMC/Paper@dc684c6 Remove bad server.scheduleOnMain disconnect calls from old patches PaperMC/Paper@c84a3b5 Remove fully dropped patches PaperMC/Paper@d8c2980 Add Adventure API to ServerLinks (#10891) PaperMC/Paper@ec4c712 update 'improve mass craft perf' patch PaperMC/Paper@e1c0033 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@fbc2a55 Update Wither#canTravelThroughPortals PaperMC/Paper@167961e call EntityDamageItemEvent for thorns PaperMC/Paper@106dbae Fix getAddress connection check PaperMC/Paper@d9111cc Registry Modification API (#10893) PaperMC/Paper@f8ee0a0 Fix implementations of ChunkHolder#getChunkIfPresent PaperMC/Paper@61b85e4 Fix legacy cb version in remapper PaperMC/Paper@de8220c Update ChunkMap#distanceManager mapping patch PaperMC/Paper@8dfb85c Enchantment and GameEvent Registry builders (#10889) PaperMC/Paper@fb762cf remove remaining reference to 'pgive' PaperMC/Paper@a7f6633 make EntityPortalReadyEvent#setTargetWorld work again PaperMC/Paper@152f4fe Add back improved watchdog support patch PaperMC/Paper@13992b1 Make chunk system loggers calm down a bit PaperMC/Paper@bf8552f Delegate ItemStack (#10852) PaperMC/Paper@b3e072a Fix `hasFiredAsync` parameter when `AsyncPlayerSendCommandsEvent` is called (#10896) PaperMC/Paper@21c9a7c Rebuild patches PaperMC/Paper@b9f7098 [ci skip] Fix javadoc mistake in EnchantmentRegistryEntry.Builder (#10898) PaperMC/Paper@b4b8208 Fix NPE for Jukebox#setRecord PaperMC/Paper@4514f41 Correct duplicate attribute check (#10901) PaperMC/Paper@090775e Use ItemStack.empty() when air is passed into constructor PaperMC/Paper@7bbe682 Fix CraftWorld#isChunkGenerated PaperMC/Paper@126f6d7 Remove getUnloadingChunkHolder check PaperMC/Paper@d23825a Add missing null check to getFullChunkIfLoaded PaperMC/Paper@3b1c85b Execute chunk tasks while waiting for chunk load in isChunkGenerated PaperMC/Paper@4ea696f Add ticket for chunk load in isChunkGenerated PaperMC/Paper@250e78c Re-add fixlight command PaperMC/Paper@c0268ca Copy missing diff from old chunk system patch PaperMC/Paper@38428c0 Cleanup MCUtils patch for chunk system PaperMC/Paper@f4ddd4a Fix ChunkHolder#getFullChunkNow returning non-null when it should not PaperMC/Paper@e0d9d60 Add debug for chunk system unload crash PaperMC/Paper@2df432f Re-add chunk system debug commands PaperMC/Paper@cf60574 Fix jukebox playable component not being applied on item meta (#10922) PaperMC/Paper@666bc4d Experimental annotation changes (#10914) PaperMC/Paper@bab07e0 Validate speed for tool component rule (#10923) PaperMC/Paper@2118196 Fixes exception log messages getting dropped during bootstrap (#10935) PaperMC/Paper@8b1d26d Fix diff in sprint interruption option (Closes #10939) PaperMC/Paper@0a1b133 Revert "Fixes exception log messages getting dropped during bootstrap (#10935)" (Closes #10945) PaperMC/Paper@a0fad76 Fix base damage for trident (#10948) PaperMC/Paper@d64be7e Fix NPE of AbstractArrow#getWeapon (#10933) PaperMC/Paper@081146c Validate using_converts_to for food component (#10931) PaperMC/Paper@0409a68 deprecate and update some entity tags (#10932) PaperMC/Paper@9cd0201 Preserve velocity for fireball (#10934) PaperMC/Paper@19105a9 Fix unload queue storing chunks in wrong sections PaperMC/Paper@77c763b Fix PlayerShearBlockEvent drops ignored for Pumpkin (#10956) PaperMC/Paper@76c2f16 Fix wrong diff applying delta twice (#10959) PaperMC/Paper@812701d Do not crash when an exp orb attempts to mend an unrepairable item PaperMC/Paper@19eefe9 Fix SoundEffects only to players diff (#10966) PaperMC/Paper@95aa440 Add missing effect cause and deprecate PATROL_CAPTAIN cause (#10958) PaperMC/Paper@b2e5587 Expose LivingEntity#canUseSlot (#10930) PaperMC/Paper@97afc9a Fix StackOverflowError for new dispenser interaction (#10949) PaperMC/Paper@5ae4758 Fix speed for launched trident using api (#10936) PaperMC/Paper@897ece4 Call EntityPortalEnterEvent on endgateways and make cancellable (#10892) PaperMC/Paper@1d3fc0e Bump reflection-rewriter to 0.0.2 (#10927) PaperMC/Paper@b99d071 Swap some nullable annotations (#10960) PaperMC/Paper@dd31654 bump reflection-rewriter to 0.0.3 (#10969) PaperMC/Paper@dd49fba Fix NPE when retrieving an entity with a null UUID
201 lines
11 KiB
Diff
201 lines
11 KiB
Diff
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 5a7f7de0bcdd3d6ed946f0d3e3100e21ff1cbea9..7d451c2924ab944e453c56a02fb02dd0b81381ef 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -299,6 +299,79 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
++this.noActionTime; // Above all the floats
|
|
}
|
|
// Spigot end
|
|
+ // Sakura start - legacy combat mechanics
|
|
+ private static final ResourceLocation LEGACY_COMBAT_MODIFIER_ID = ResourceLocation.fromNamespaceAndPath("sakura", "legacy_combat");
|
|
+ private static final AttributeModifier LEGACY_ATTACK_SPEED_MODIFIER = new AttributeModifier(LEGACY_COMBAT_MODIFIER_ID, 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 defaultModifiers = itemstack.getItem().components().get(DataComponents.ATTRIBUTE_MODIFIERS);
|
|
+ if (defaultModifiers != null && !defaultModifiers.modifiers().isEmpty()) { // exists
|
|
+ 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_MODIFIER_ID, attackDifference, AttributeModifier.Operation.ADD_VALUE);
|
|
+ }
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ protected final float calculateLegacySharpnessDamage(ItemStack itemstack, DamageSource damageSource) {
|
|
+ net.minecraft.core.RegistryAccess registryAccess = net.minecraft.server.MinecraftServer.getServer().registryAccess();
|
|
+ net.minecraft.core.HolderLookup.RegistryLookup<Enchantment> enchantments = registryAccess.lookupOrThrow(net.minecraft.core.registries.Registries.ENCHANTMENT);
|
|
+ Holder<Enchantment> sharpness = enchantments.getOrThrow(net.minecraft.world.item.enchantment.Enchantments.SHARPNESS);
|
|
+
|
|
+ int enchantmentLevel = itemstack.getEnchantments().getLevel(sharpness);
|
|
+ ServerLevel serverLevel = (ServerLevel) this.level();
|
|
+
|
|
+ org.apache.commons.lang3.mutable.MutableFloat damage = new org.apache.commons.lang3.mutable.MutableFloat();
|
|
+ sharpness.value().modifyDamage(serverLevel, enchantmentLevel, itemstack, this, damageSource, damage);
|
|
+
|
|
+ // legacy - modern
|
|
+ return enchantmentLevel * 1.25F - damage.getValue();
|
|
+ }
|
|
+ // Sakura end - legacy combat mechanics
|
|
|
|
protected LivingEntity(EntityType<? extends LivingEntity> type, Level world) {
|
|
super(type, world);
|
|
@@ -2173,7 +2246,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(this, 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;
|
|
@@ -3297,6 +3379,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
|
|
});
|
|
}
|
|
+
|
|
+ // Sakura start - legacy combat mechanics
|
|
+ if (this instanceof ServerPlayer && enumitemslot1 == 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 1967a38277d12e09bf39af271eb6c7ed75fe0218..57f891099e7b66e75e9d8eb0f961c4395ed875ff 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1277,14 +1277,20 @@ public abstract class Player extends LivingEntity {
|
|
if (playerAttackEntityEvent.callEvent() && willAttack) { // Logic moved to willAttack local variable.
|
|
{
|
|
// Paper end - PlayerAttackEntityEvent
|
|
- float f = this.isAutoSpinAttack() ? this.autoSpinAttackDmg : (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE);
|
|
+ float f = this.isAutoSpinAttack() ? this.autoSpinAttackDmg : this.getAttackDamageFromAttributes(); // Sakura - legacy combat mechanics
|
|
ItemStack itemstack = this.getWeaponItem();
|
|
DamageSource damagesource = this.damageSources().playerAttack(this);
|
|
float f1 = this.getEnchantedDamage(target, f, damagesource) - f;
|
|
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(itemstack, damagesource);
|
|
+ }
|
|
+ // 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;
|
|
@@ -1312,7 +1318,7 @@ public abstract class Player extends LivingEntity {
|
|
}
|
|
|
|
f += itemstack.getItem().getAttackDamageBonus(target, f, damagesource);
|
|
- boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && !this.isSprinting();
|
|
+ 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
|
|
|
|
flag2 = flag2 && !this.level().paperConfig().entities.behavior.disablePlayerCrits; // Paper - Toggleable player crits
|
|
if (flag2) {
|