88import com .mrcrayfish .goblintraders .trades .GoblinOffers ;
99import com .mrcrayfish .goblintraders .trades .type .BaseTrade ;
1010import com .mrcrayfish .goblintraders .util .Utils ;
11+ import net .minecraft .core .UUIDUtil ;
1112import net .minecraft .core .particles .ItemParticleOption ;
1213import net .minecraft .core .particles .ParticleTypes ;
1314import net .minecraft .nbt .*;
3940import net .minecraft .world .item .trading .MerchantOffers ;
4041import net .minecraft .world .level .Level ;
4142import net .minecraft .world .level .portal .TeleportTransition ;
43+ import net .minecraft .world .level .storage .ValueInput ;
44+ import net .minecraft .world .level .storage .ValueOutput ;
4245import net .minecraft .world .phys .Vec3 ;
4346import org .jetbrains .annotations .Nullable ;
4447
@@ -330,7 +333,7 @@ protected InteractionResult mobInteract(Player player, InteractionHand hand)
330333 if (result .consumesAction ())
331334 {
332335 // Remove the wandering restriction once named
333- this .clearRestriction ();
336+ this .clearHome ();
334337 }
335338 return result ;
336339 }
@@ -410,59 +413,28 @@ public void setDespawnDelay(int despawnDelay)
410413 }
411414
412415 @ Override
413- public void readAdditionalSaveData (CompoundTag compound )
416+ public void readAdditionalSaveData (ValueInput input )
414417 {
415- super .readAdditionalSaveData (compound );
416- if (compound .contains ("Offers" ))
417- {
418- this .offers = new GoblinOffers (compound .getCompoundOrEmpty ("Offers" ));
419- }
420- if (compound .contains ("DespawnDelay" ))
421- {
422- this .despawnDelay = compound .getIntOr ("DespawnDelay" , 0 );
423- }
424- if (compound .contains ("RestockDelay" ))
425- {
426- this .restockDelay = compound .getIntOr ("RestockDelay" , 0 );
427- }
428- if (compound .contains ("TradedCustomers" ))
429- {
418+ super .readAdditionalSaveData (input );
419+ input .read ("Offers" , GoblinOffers .CODEC ).ifPresent (offers -> this .offers = new GoblinOffers (offers ));
420+ input .getInt ("DespawnDelay" ).ifPresent (delay -> this .despawnDelay = delay );
421+ input .getInt ("RestockDelay" ).ifPresent (delay -> this .restockDelay = delay );
422+ input .list ("TradedCustomers" , UUIDUtil .CODEC ).ifPresent (uuids -> {
430423 this .tradedCustomers .clear ();
431- ListTag list = compound .getListOrEmpty ("TradedCustomers" );
432- list .forEach (tag -> {
433- if (tag instanceof StringTag (String value )) {
434- UUID id = Utils .parseUuid (value );
435- if (id != null ) {
436- this .tradedCustomers .add (id );
437- }
438- }
439- });
440- }
424+ uuids .forEach (this .tradedCustomers ::add );
425+ });
441426 }
442427
443428 @ Override
444- public void addAdditionalSaveData (CompoundTag compound )
429+ public void addAdditionalSaveData (ValueOutput output )
445430 {
446- super .addAdditionalSaveData (compound );
431+ super .addAdditionalSaveData (output );
447432 MerchantOffers offers = this .getOffers ();
448- if (!offers .isEmpty ())
449- {
450- MerchantOffers .CODEC .encodeStart (NbtOps .INSTANCE , offers ).result ()
451- .ifPresent (tag -> {
452- compound .put ("Offers" , tag );
453- });
454- }
455- compound .putInt ("DespawnDelay" , this .despawnDelay );
456- compound .putInt ("RestockDelay" , this .restockDelay );
457-
458- if (!this .tradedCustomers .isEmpty ())
459- {
460- ListTag list = new ListTag ();
461- this .tradedCustomers .forEach (id -> {
462- list .add (StringTag .valueOf (id .toString ()));
463- });
464- compound .put ("TradedCustomers" , list );
465- }
433+ output .store ("Offers" , GoblinOffers .CODEC , offers );
434+ output .putInt ("DespawnDelay" , this .despawnDelay );
435+ output .putInt ("RestockDelay" , this .restockDelay );
436+ ValueOutput .TypedOutputList <UUID > uuids = output .list ("TradedCustomers" , UUIDUtil .CODEC );
437+ this .tradedCustomers .forEach (uuids ::add );
466438 }
467439
468440 @ Nullable
@@ -591,7 +563,7 @@ public void die(DamageSource source)
591563 }
592564
593565 @ Override
594- protected Vec3 getLeashOffset ()
566+ public Vec3 getLeashOffset ()
595567 {
596568 return new Vec3 (0 , this .getEyeHeight () - 0.25 , 0 );
597569 }
@@ -601,7 +573,7 @@ public void setLeashedTo(Entity entity, boolean broadcast)
601573 {
602574 // When goblin becomes leashed, remove restriction
603575 super .setLeashedTo (entity , broadcast );
604- this .clearRestriction ();
576+ this .clearHome ();
605577 }
606578
607579 @ Override
0 commit comments