From 5243c1800ea53f27d93d4c187f0c0180b2887379 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 20 Jun 2024 12:51:35 +0200 Subject: [PATCH] entity effect magic Fixes #3927 --- .../BlockItemPacketRewriter1_20_5.java | 24 +++++++++++++++---- .../rewriter/EntityPacketRewriter1_20_5.java | 2 +- .../storage/EfficiencyAttributeStorage.java | 21 ++++------------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java index 1fa5f59a8..194468c3d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java @@ -225,18 +225,32 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter (level * level) + 1); - public static final EnchantAttributeModifier SOUL_SPEED = new EnchantAttributeModifier("minecraft:enchantment.soul_speed", 21, 0.1, level -> 0.04D + ((level - 1) * 0.01D)); - public static final EnchantAttributeModifier SWIFT_SNEAK = new EnchantAttributeModifier("minecraft:enchantment.swift_sneak", 25, 0.3, level -> level * 0.15D); - public static final EnchantAttributeModifier DEPTH_STRIDER = new EnchantAttributeModifier("minecraft:enchantment.depth_strider", 30, 0, level -> level / 3D); + private static final EnchantAttributeModifier EFFICIENCY = new EnchantAttributeModifier("minecraft:enchantment.efficiency/mainhand", 19, 0, level -> (level * level) + 1); + private static final EnchantAttributeModifier SOUL_SPEED = new EnchantAttributeModifier("minecraft:enchantment.soul_speed", 21, 0.1, level -> 0.04D + ((level - 1) * 0.01D)); + private static final EnchantAttributeModifier SWIFT_SNEAK = new EnchantAttributeModifier("minecraft:enchantment.swift_sneak", 25, 0.3, level -> level * 0.15D); + private static final EnchantAttributeModifier DEPTH_STRIDER = new EnchantAttributeModifier("minecraft:enchantment.depth_strider", 30, 0, level -> level / 3D); private static final ActiveEnchants DEFAULT = new ActiveEnchants(-1, new ActiveEnchant(EFFICIENCY, 0), new ActiveEnchant(SOUL_SPEED, 0), @@ -115,18 +115,7 @@ public final class EfficiencyAttributeStorage implements StorableObject { public record ActiveEnchant(EnchantAttributeModifier modifier, int level) { } - public static final class EnchantAttributeModifier { // Private constructor, equals by reference - private final String key; - private final int attributeId; - private final double baseValue; - private final LevelToModifier modifierFunction; - - private EnchantAttributeModifier(final String key, final int attributeId, final double baseValue, final LevelToModifier modifierFunction) { - this.key = key; - this.attributeId = attributeId; - this.baseValue = baseValue; - this.modifierFunction = modifierFunction; - } + public record EnchantAttributeModifier(String key, int attributeId, double baseValue, LevelToModifier modifierFunction) { } @FunctionalInterface