@@ -36,6 +36,36 @@ public static <T> void writeFilterable(ByteBuf buf, Filterable<T> filterable, Bi
3636 MinecraftTypes .writeNullable (buf , filterable .getOptional (), writer );
3737 }
3838
39+ public static UseEffects readUseEffects (ByteBuf buf ) {
40+ boolean canSprint = buf .readBoolean ();
41+ float speedMultiplier = buf .readFloat ();
42+
43+ return new UseEffects (canSprint , speedMultiplier );
44+ }
45+
46+ public static void writeUseEffects (ByteBuf buf , UseEffects useEffects ) {
47+ buf .writeBoolean (useEffects .canSprint ());
48+ buf .writeFloat (useEffects .speedMultiplier ());
49+ }
50+
51+ public static Holder <Key > readDamageType (ByteBuf buf ) {
52+ if (buf .readBoolean ()) {
53+ return Holder .ofId (MinecraftTypes .readVarInt (buf ));
54+ } else {
55+ return Holder .ofCustom (MinecraftTypes .readResourceLocation (buf ));
56+ }
57+ }
58+
59+ public static void writeDamageType (ByteBuf buf , Holder <Key > variant ) {
60+ if (variant .isId ()) {
61+ buf .writeBoolean (true );
62+ MinecraftTypes .writeVarInt (buf , variant .id ());
63+ } else {
64+ buf .writeBoolean (false );
65+ MinecraftTypes .writeResourceLocation (buf , variant .custom ());
66+ }
67+ }
68+
3969 public static ItemEnchantments readItemEnchantments (ByteBuf buf ) {
4070 Map <Integer , Integer > enchantments = new HashMap <>();
4171 int enchantmentCount = MinecraftTypes .readVarInt (buf );
@@ -106,10 +136,16 @@ public static void writeBlockPredicate(ByteBuf buf, AdventureModePredicate.Block
106136
107137 public static DataComponentMatchers readDataComponentMatchers (ByteBuf buf ) {
108138 Map <DataComponentType <?>, DataComponent <?, ?>> exactMatchers = MinecraftTypes .readExactComponentMatcher (buf );
139+ Map <DataComponentMatchers .PredicateType , NbtMap > partialMatchers = new HashMap <>();
109140
110- int [] partialMatchers = new int [MinecraftTypes .readVarInt (buf )];
111- for (int i = 0 ; i < partialMatchers .length ; i ++) {
112- partialMatchers [i ] = MinecraftTypes .readVarInt (buf );
141+ int count = MinecraftTypes .readVarInt (buf );
142+ if (count > 64 ) {
143+ throw new IllegalArgumentException (count + " elements exceeds max size of: " + 64 );
144+ }
145+
146+ for (int i = 0 ; i < count ; i ++) {
147+ DataComponentMatchers .PredicateType type = new DataComponentMatchers .PredicateType (buf .readBoolean (), MinecraftTypes .readVarInt (buf ));
148+ partialMatchers .put (type , MinecraftTypes .readCompoundTag (buf ));
113149 }
114150
115151 return new DataComponentMatchers (exactMatchers , partialMatchers );
@@ -118,9 +154,16 @@ public static DataComponentMatchers readDataComponentMatchers(ByteBuf buf) {
118154 public static void writeDataComponentMatchers (ByteBuf buf , DataComponentMatchers matchers ) {
119155 MinecraftTypes .writeExactComponentMatcher (buf , matchers .exactMatchers ());
120156
121- MinecraftTypes .writeVarInt (buf , matchers .partialMatchers ().length );
122- for (int id : matchers .partialMatchers ()) {
123- MinecraftTypes .writeVarInt (buf , id );
157+ int count = matchers .partialMatchers ().size ();
158+ if (count > 64 ) {
159+ throw new IllegalArgumentException (count + " elements exceeds max size of: " + 64 );
160+ }
161+
162+ MinecraftTypes .writeVarInt (buf , count );
163+ for (Map .Entry <DataComponentMatchers .PredicateType , NbtMap > entry : matchers .partialMatchers ().entrySet ()) {
164+ buf .writeBoolean (entry .getKey ().isPredicate ());
165+ MinecraftTypes .writeVarInt (buf , entry .getKey ().id ());
166+ MinecraftTypes .writeAnyTag (buf , entry .getValue ());
124167 }
125168 }
126169
@@ -229,6 +272,85 @@ public static void writeBlocksAttacks(ByteBuf buf, BlocksAttacks blocksAttacks)
229272 MinecraftTypes .writeNullable (buf , blocksAttacks .disableSound (), MinecraftTypes ::writeSound );
230273 }
231274
275+ public static PiercingWeapon readPiercingWeapon (ByteBuf buf ) {
276+ float minReach = buf .readFloat ();
277+ float maxReach = buf .readFloat ();
278+ float hitboxMargin = buf .readFloat ();
279+ boolean dealsKnockback = buf .readBoolean ();
280+ boolean dismounts = buf .readBoolean ();
281+ Sound sound = MinecraftTypes .readNullable (buf , MinecraftTypes ::readSound );
282+ Sound hitSound = MinecraftTypes .readNullable (buf , MinecraftTypes ::readSound );
283+
284+ return new PiercingWeapon (minReach , maxReach , hitboxMargin , dealsKnockback , dismounts , sound , hitSound );
285+ }
286+
287+ public static void writePiercingWeapon (ByteBuf buf , PiercingWeapon piercingWeapon ) {
288+ buf .writeFloat (piercingWeapon .minReach ());
289+ buf .writeFloat (piercingWeapon .maxReach ());
290+ buf .writeFloat (piercingWeapon .hitboxMargin ());
291+ buf .writeBoolean (piercingWeapon .dealsKnockback ());
292+ buf .writeBoolean (piercingWeapon .dismounts ());
293+ MinecraftTypes .writeNullable (buf , piercingWeapon .sound (), MinecraftTypes ::writeSound );
294+ MinecraftTypes .writeNullable (buf , piercingWeapon .hitSound (), MinecraftTypes ::writeSound );
295+ }
296+
297+ public static KineticWeapon readKineticWeapon (ByteBuf buf ) {
298+ float minReach = buf .readFloat ();
299+ float maxReach = buf .readFloat ();
300+ float hitboxMargin = buf .readFloat ();
301+ int delayTicks = MinecraftTypes .readVarInt (buf );
302+ KineticWeapon .Condition dismountConditions = MinecraftTypes .readNullable (buf , ItemTypes ::readKineticCondition );
303+ KineticWeapon .Condition knockbackConditions = MinecraftTypes .readNullable (buf , ItemTypes ::readKineticCondition );
304+ KineticWeapon .Condition damageConditions = MinecraftTypes .readNullable (buf , ItemTypes ::readKineticCondition );
305+ float forwardMovement = buf .readFloat ();
306+ float damageMultiplier = buf .readFloat ();
307+ Sound sound = MinecraftTypes .readNullable (buf , MinecraftTypes ::readSound );
308+ Sound hitSound = MinecraftTypes .readNullable (buf , MinecraftTypes ::readSound );
309+
310+ return new KineticWeapon (minReach , maxReach , hitboxMargin , delayTicks , dismountConditions ,
311+ knockbackConditions , damageConditions , forwardMovement , damageMultiplier , sound , hitSound );
312+ }
313+
314+ public static void writeKineticWeapon (ByteBuf buf , KineticWeapon kineticWeapon ) {
315+ buf .writeFloat (kineticWeapon .minReach ());
316+ buf .writeFloat (kineticWeapon .maxReach ());
317+ buf .writeFloat (kineticWeapon .hitboxMargin ());
318+ MinecraftTypes .writeVarInt (buf , kineticWeapon .delayTicks ());
319+ MinecraftTypes .writeNullable (buf , kineticWeapon .dismountConditions (), ItemTypes ::writeKineticCondition );
320+ MinecraftTypes .writeNullable (buf , kineticWeapon .knockbackConditions (), ItemTypes ::writeKineticCondition );
321+ MinecraftTypes .writeNullable (buf , kineticWeapon .damageConditions (), ItemTypes ::writeKineticCondition );
322+ buf .writeFloat (kineticWeapon .forwardMovement ());
323+ buf .writeFloat (kineticWeapon .damageMultiplier ());
324+ MinecraftTypes .writeNullable (buf , kineticWeapon .sound (), MinecraftTypes ::writeSound );
325+ MinecraftTypes .writeNullable (buf , kineticWeapon .hitSound (), MinecraftTypes ::writeSound );
326+ }
327+
328+ public static KineticWeapon .Condition readKineticCondition (ByteBuf buf ) {
329+ int maxDurationTicks = MinecraftTypes .readVarInt (buf );
330+ float minSpeed = buf .readFloat ();
331+ float minRelativeSpeed = buf .readFloat ();
332+
333+ return new KineticWeapon .Condition (maxDurationTicks , minSpeed , minRelativeSpeed );
334+ }
335+
336+ public static void writeKineticCondition (ByteBuf buf , KineticWeapon .Condition condition ) {
337+ MinecraftTypes .writeVarInt (buf , condition .maxDurationTicks ());
338+ buf .writeFloat (condition .minSpeed ());
339+ buf .writeFloat (condition .minRelativeSpeed ());
340+ }
341+
342+ public static SwingAnimation readSwingAnimation (ByteBuf buf ) {
343+ SwingAnimation .Type type = SwingAnimation .Type .from (MinecraftTypes .readVarInt (buf ));
344+ int duration = MinecraftTypes .readVarInt (buf );
345+
346+ return new SwingAnimation (type , duration );
347+ }
348+
349+ public static void writeSwingAnimation (ByteBuf buf , SwingAnimation swingAnimation ) {
350+ MinecraftTypes .writeVarInt (buf , swingAnimation .type ().ordinal ());
351+ MinecraftTypes .writeVarInt (buf , swingAnimation .duration ());
352+ }
353+
232354 public static ItemAttributeModifiers readItemAttributeModifiers (ByteBuf buf ) {
233355 List <ItemAttributeModifiers .Entry > modifiers = MinecraftTypes .readList (buf , (input ) -> {
234356 int attribute = MinecraftTypes .readVarInt (input );
0 commit comments