11
11
import net .bettercombat .logic .WeaponRegistry ;
12
12
import net .bettercombat .logic .knockback .ConfigurableKnockback ;
13
13
import net .bettercombat .mixin .LivingEntityAccessor ;
14
- import net .bettercombat .utils .MathHelp ;
14
+ import net .bettercombat .utils .MathHelper ;
15
15
import net .bettercombat .utils .SoundHelper ;
16
16
import net .fabricmc .fabric .api .networking .v1 .PacketByteBufs ;
17
17
import net .fabricmc .fabric .api .networking .v1 .PlayerLookup ;
18
18
import net .fabricmc .fabric .api .networking .v1 .ServerPlayConnectionEvents ;
19
19
import net .fabricmc .fabric .api .networking .v1 .ServerPlayNetworking ;
20
+ import net .minecraft .enchantment .EnchantmentHelper ;
21
+ import net .minecraft .enchantment .Enchantments ;
20
22
import net .minecraft .entity .Entity ;
21
23
import net .minecraft .entity .ExperienceOrbEntity ;
22
24
import net .minecraft .entity .ItemEntity ;
26
28
import net .minecraft .entity .attribute .EntityAttributes ;
27
29
import net .minecraft .entity .decoration .ArmorStandEntity ;
28
30
import net .minecraft .entity .projectile .PersistentProjectileEntity ;
31
+ import net .minecraft .item .SwordItem ;
29
32
import net .minecraft .network .PacketByteBuf ;
30
33
import net .minecraft .network .packet .c2s .play .PlayerInteractEntityC2SPacket ;
34
+ import net .minecraft .particle .ParticleTypes ;
31
35
import net .minecraft .server .world .ServerWorld ;
36
+ import net .minecraft .sound .SoundEvents ;
32
37
import net .minecraft .text .Text ;
33
38
import org .slf4j .Logger ;
34
39
@@ -39,6 +44,10 @@ public class ServerNetwork {
39
44
40
45
private static PacketByteBuf configSerialized = PacketByteBufs .create ();
41
46
47
+ private static final UUID COMBO_DAMAGE_MODIFIER_ID = UUID .randomUUID ();
48
+ private static final UUID DUAL_WIELDING_MODIFIER_ID = UUID .randomUUID ();
49
+ private static final UUID SWEEPING_MODIFIER_ID = UUID .randomUUID ();
50
+
42
51
public static void initializeHandlers () {
43
52
configSerialized = Packets .ConfigSync .write (BetterCombat .config );
44
53
ServerPlayConnectionEvents .JOIN .register ( (handler , sender , server ) -> {
@@ -88,6 +97,7 @@ public static void initializeHandlers() {
88
97
((PlayerAttackProperties )player ).setComboCount (request .comboCount ());
89
98
Multimap <EntityAttribute , EntityAttributeModifier > comboAttributes = null ;
90
99
Multimap <EntityAttribute , EntityAttributeModifier > dualWieldingAttributes = null ;
100
+ Multimap <EntityAttribute , EntityAttributeModifier > sweepingModifiers = HashMultimap .create ();
91
101
double range = 18.0 ;
92
102
if (attributes != null && attack != null ) {
93
103
range = attributes .attackRange ();
@@ -96,15 +106,15 @@ public static void initializeHandlers() {
96
106
double comboMultiplier = attack .damageMultiplier () - 1 ;
97
107
comboAttributes .put (
98
108
EntityAttributes .GENERIC_ATTACK_DAMAGE ,
99
- new EntityAttributeModifier (UUID . randomUUID () , "COMBO_DAMAGE_MULTIPLIER" , comboMultiplier , EntityAttributeModifier .Operation .MULTIPLY_BASE ));
109
+ new EntityAttributeModifier (COMBO_DAMAGE_MODIFIER_ID , "COMBO_DAMAGE_MULTIPLIER" , comboMultiplier , EntityAttributeModifier .Operation .MULTIPLY_BASE ));
100
110
player .getAttributes ().addTemporaryModifiers (comboAttributes );
101
111
102
112
var dualWieldingMultiplier = PlayerAttackHelper .getDualWieldingAttackDamageMultiplier (player , hand ) - 1 ;
103
113
if (dualWieldingMultiplier != 0 ) {
104
114
dualWieldingAttributes = HashMultimap .create ();
105
115
dualWieldingAttributes .put (
106
116
EntityAttributes .GENERIC_ATTACK_DAMAGE ,
107
- new EntityAttributeModifier (UUID . randomUUID () , "DUAL_WIELDING_DAMAGE_MULTIPLIER" , dualWieldingMultiplier , EntityAttributeModifier .Operation .MULTIPLY_TOTAL ));
117
+ new EntityAttributeModifier (DUAL_WIELDING_MODIFIER_ID , "DUAL_WIELDING_DAMAGE_MULTIPLIER" , dualWieldingMultiplier , EntityAttributeModifier .Operation .MULTIPLY_TOTAL ));
108
118
player .getAttributes ().addTemporaryModifiers (dualWieldingAttributes );
109
119
}
110
120
@@ -113,17 +123,42 @@ public static void initializeHandlers() {
113
123
}
114
124
115
125
SoundHelper .playSound (world , player , attack .swingSound ());
126
+
127
+ if (BetterCombat .config .allow_reworked_sweeping && request .entityIds ().length > 1 ) {
128
+ double multiplier = 1.0
129
+ - (BetterCombat .config .reworked_sweeping_maximum_damage_penalty / BetterCombat .config .reworked_sweeping_extra_target_count )
130
+ * Math .min (BetterCombat .config .reworked_sweeping_extra_target_count , request .entityIds ().length - 1 );
131
+ int sweepingLevel = EnchantmentHelper .getLevel (Enchantments .SWEEPING , hand .itemStack ());
132
+ double sweepingSteps = BetterCombat .config .reworked_sweeping_enchant_restores / ((double )Enchantments .SWEEPING .getMaxLevel ());
133
+ multiplier += sweepingLevel * sweepingSteps ;
134
+ multiplier = Math .min (multiplier , 1 );
135
+ sweepingModifiers .put (
136
+ EntityAttributes .GENERIC_ATTACK_DAMAGE ,
137
+ new EntityAttributeModifier (SWEEPING_MODIFIER_ID , "SWEEPING_DAMAGE_MODIFIER" , multiplier - 1 , EntityAttributeModifier .Operation .MULTIPLY_TOTAL ));
138
+ // System.out.println("Applied sweeping multiplier " + multiplier + " , sweepingSteps " + sweepingSteps + " , enchant bonus: " + (sweepingLevel * sweepingSteps));
139
+ player .getAttributes ().addTemporaryModifiers (sweepingModifiers );
140
+
141
+ boolean playEffects = !BetterCombat .config .reworked_sweeping_sound_and_particles_only_for_swords
142
+ || (hand .itemStack ().getItem () instanceof SwordItem );
143
+ if (BetterCombat .config .reworked_sweeping_plays_sound && playEffects ) {
144
+ world .playSound (null , player .getX (), player .getY (), player .getZ (), SoundEvents .ENTITY_PLAYER_ATTACK_SWEEP , player .getSoundCategory (), 1.0f , 1.0f );
145
+ }
146
+ if (BetterCombat .config .reworked_sweeping_emits_particles && playEffects ) {
147
+ player .spawnSweepAttackParticles ();
148
+ }
149
+ }
116
150
}
117
151
118
152
var attackCooldown = PlayerAttackHelper .getAttackCooldownTicksCapped (player );
119
153
var knockbackMultiplier = BetterCombat .config .knockback_reduced_for_fast_attacks
120
- ? MathHelp .clamp (attackCooldown / 12.5F , 0.1F , 1F )
154
+ ? MathHelper .clamp (attackCooldown / 12.5F , 0.1F , 1F )
121
155
: 1F ;
122
156
var lastAttackedTicks = ((LivingEntityAccessor )player ).getLastAttackedTicks ();
123
157
if (!useVanillaPacket ) {
124
158
player .setSneaking (request .isSneaking ());
125
159
}
126
160
161
+
127
162
for (int entityId : request .entityIds ()) {
128
163
// getEntityById(entityId);
129
164
boolean isBossPart = false ;
@@ -183,6 +218,9 @@ public static void initializeHandlers() {
183
218
if (dualWieldingAttributes != null ) {
184
219
player .getAttributes ().removeModifiers (dualWieldingAttributes );
185
220
}
221
+ if (!sweepingModifiers .isEmpty ()) {
222
+ player .getAttributes ().removeModifiers (sweepingModifiers );
223
+ }
186
224
((PlayerAttackProperties )player ).setComboCount (-1 );
187
225
});
188
226
});
0 commit comments