@@ -30,23 +30,27 @@ public final class EfficiencyAttributeStorage implements StorableObject {
3030 private static final EnchantAttributeModifier EFFICIENCY = new EnchantAttributeModifier ("minecraft:enchantment.efficiency/mainhand" , 19 , 0 , level -> (level * level ) + 1 );
3131 private static final EnchantAttributeModifier SOUL_SPEED = new EnchantAttributeModifier ("minecraft:enchantment.soul_speed" , 21 , 0.1 , level -> 0.04D + ((level - 1 ) * 0.01D ));
3232 private static final EnchantAttributeModifier SWIFT_SNEAK = new EnchantAttributeModifier ("minecraft:enchantment.swift_sneak" , 25 , 0.3 , level -> level * 0.15D );
33+ private static final EnchantAttributeModifier AQUA_AFFINITY = new EnchantAttributeModifier ("minecraft:enchantment.aqua_affinity" , 28 , 0.2 , level -> level * 4 , (byte ) 2 );
3334 private static final EnchantAttributeModifier DEPTH_STRIDER = new EnchantAttributeModifier ("minecraft:enchantment.depth_strider" , 30 , 0 , level -> level / 3D );
3435 private static final ActiveEnchants DEFAULT = new ActiveEnchants (-1 ,
3536 new ActiveEnchant (EFFICIENCY , 0 ),
3637 new ActiveEnchant (SOUL_SPEED , 0 ),
3738 new ActiveEnchant (SWIFT_SNEAK , 0 ),
39+ new ActiveEnchant (AQUA_AFFINITY , 0 ),
3840 new ActiveEnchant (DEPTH_STRIDER , 0 )
3941 );
4042 private final Object lock = new Object ();
41- private volatile ActiveEnchants activeEnchants = DEFAULT ;
4243 private volatile boolean attributesSent = true ;
4344 private volatile boolean loginSent ;
45+ private ActiveEnchants activeEnchants = DEFAULT ;
4446
45- public void setEnchants (final int entityId , final UserConnection connection , final int efficiency , final int soulSpeed , final int swiftSneak , final int depthStrider ) {
47+ public void setEnchants (final int entityId , final UserConnection connection , final int efficiency , final int soulSpeed ,
48+ final int swiftSneak , final int aquaAffinity , final int depthStrider ) {
4649 // Always called from the main thread
4750 if (efficiency == activeEnchants .efficiency .level
4851 && soulSpeed == activeEnchants .soulSpeed .level
4952 && swiftSneak == activeEnchants .swiftSneak .level
53+ && aquaAffinity == activeEnchants .aquaAffinity .level
5054 && depthStrider == activeEnchants .depthStrider .level ) {
5155 return ;
5256 }
@@ -56,6 +60,7 @@ public void setEnchants(final int entityId, final UserConnection connection, fin
5660 new ActiveEnchant (EFFICIENCY , efficiency ),
5761 new ActiveEnchant (SOUL_SPEED , soulSpeed ),
5862 new ActiveEnchant (SWIFT_SNEAK , swiftSneak ),
63+ new ActiveEnchant (AQUA_AFFINITY , aquaAffinity ),
5964 new ActiveEnchant (DEPTH_STRIDER , depthStrider )
6065 );
6166 this .attributesSent = false ;
@@ -99,7 +104,7 @@ private void sendAttributesPacket(final UserConnection connection) {
99104 attributesPacket .write (Types .VAR_INT , 1 ); // Modifiers
100105 attributesPacket .write (Types .STRING , modifier .key );
101106 attributesPacket .write (Types .DOUBLE , enchant .modifier .modifierFunction .get (enchant .level ));
102- attributesPacket .write (Types .BYTE , ( byte ) 0 ); // 'Add' operation
107+ attributesPacket .write (Types .BYTE , modifier . operation );
103108 } else {
104109 attributesPacket .write (Types .VAR_INT , 0 ); // Modifiers
105110 }
@@ -108,14 +113,18 @@ private void sendAttributesPacket(final UserConnection connection) {
108113 attributesPacket .scheduleSend (Protocol1_20_5To1_21 .class );
109114 }
110115
111- public record ActiveEnchants (int entityId , ActiveEnchant efficiency , ActiveEnchant soulSpeed ,
112- ActiveEnchant swiftSneak , ActiveEnchant depthStrider ) {
116+ public record ActiveEnchants (int entityId , ActiveEnchant efficiency , ActiveEnchant aquaAffinity ,
117+ ActiveEnchant soulSpeed , ActiveEnchant swiftSneak , ActiveEnchant depthStrider ) {
113118 }
114119
115120 public record ActiveEnchant (EnchantAttributeModifier modifier , int level ) {
116121 }
117122
118- public record EnchantAttributeModifier (String key , int attributeId , double baseValue , LevelToModifier modifierFunction ) {
123+ public record EnchantAttributeModifier (String key , int attributeId , double baseValue , LevelToModifier modifierFunction , byte operation ) {
124+
125+ private EnchantAttributeModifier (String key , int attributeId , double baseValue , LevelToModifier modifierFunction ) {
126+ this (key , attributeId , baseValue , modifierFunction , (byte ) 0 );
127+ }
119128 }
120129
121130 @ FunctionalInterface
0 commit comments