11package eu .pb4 .sgui .api .elements ;
22
3+ import com .google .common .collect .ImmutableBiMap ;
4+ import com .google .common .collect .ImmutableMultimap ;
35import com .mojang .authlib .GameProfile ;
46import com .mojang .authlib .minecraft .MinecraftProfileTextures ;
57import com .mojang .authlib .properties .Property ;
68import com .mojang .authlib .properties .PropertyMap ;
9+ import com .mojang .datafixers .util .Either ;
710import eu .pb4 .sgui .api .GuiHelpers ;
11+ import eu .pb4 .sgui .mixin .StaticAccessor ;
812import it .unimi .dsi .fastutil .objects .ReferenceSortedSets ;
13+ import net .minecraft .client .ClientAssets ;
14+ import net .minecraft .client .util .SkinTextures ;
915import net .minecraft .component .ComponentType ;
1016import net .minecraft .component .DataComponentTypes ;
1117import net .minecraft .component .type .CustomModelDataComponent ;
2632import net .minecraft .util .Identifier ;
2733import net .minecraft .util .Rarity ;
2834import net .minecraft .util .Unit ;
35+ import net .minecraft .util .Util ;
2936import org .jetbrains .annotations .Nullable ;
3037
3138import java .util .*;
@@ -357,23 +364,70 @@ public AnimatedGuiElementBuilder unbreakable() {
357364 * server load the textures.
358365 *
359366 * @param profile the {@link GameProfile} of the owner
360- * @param server the server instance, used to get the textures
361367 * @return this element builder
362368 */
363- public AnimatedGuiElementBuilder setSkullOwner (GameProfile profile , @ Nullable MinecraftServer server ) {
364- if (profile .getId () != null && server != null ) {
365- if ( server . getSessionService (). getTextures (profile ) == MinecraftProfileTextures . EMPTY ) {
366- var tmp = server . getSessionService (). fetchProfile ( profile . getId (), false );
367- if (tmp != null ) {
368- profile = tmp . profile ( );
369- }
370- }
371-
369+ public AnimatedGuiElementBuilder setProfile (GameProfile profile ) {
370+ if (! profile .properties (). isEmpty () ) {
371+ return this . setProfile ( ProfileComponent . ofStatic (profile ));
372+ }
373+ if (profile . name (). isEmpty () ) {
374+ return this . setProfile ( ProfileComponent . ofDynamic ( profile . id ()) );
375+ }
376+ if ( profile . id (). equals ( Util . NIL_UUID )) {
377+ return this . setProfile ( ProfileComponent . method_74889 ( profile . name ()));
372378 }
373- this .itemStack .set (DataComponentTypes .PROFILE , new ProfileComponent (profile ));
374379 return this ;
375380 }
376381
382+ public AnimatedGuiElementBuilder setProfile (String name ) {
383+ return this .setProfile (ProfileComponent .method_74889 (name ));
384+ }
385+
386+ public AnimatedGuiElementBuilder setProfile (UUID uuid ) {
387+ return this .setProfile (ProfileComponent .ofDynamic (uuid ));
388+ }
389+
390+ public AnimatedGuiElementBuilder setProfile (Identifier textureId ) {
391+ return this .setProfile (StaticAccessor .createStatic (Either .right (ProfileComponent .Data .field_63032 ),
392+ new SkinTextures .MannequinInfo (Optional .of (new ClientAssets .AssetInfo (textureId )), Optional .empty (),
393+ Optional .empty (), Optional .empty ())));
394+ }
395+
396+ public AnimatedGuiElementBuilder setProfile (SkinTextures .MannequinInfo info ) {
397+ return this .setProfile (StaticAccessor .createStatic (Either .right (ProfileComponent .Data .field_63032 ), info ));
398+ }
399+
400+ public AnimatedGuiElementBuilder setProfile (ProfileComponent component ) {
401+ this .itemStack .set (DataComponentTypes .PROFILE , component );
402+ return this ;
403+ }
404+
405+
406+ public AnimatedGuiElementBuilder setProfileSkinTexture (String value ) {
407+ return this .setProfileSkinTexture (value , null , null );
408+ }
409+
410+ public AnimatedGuiElementBuilder setProfileSkinTexture (String value , @ Nullable String signature , @ Nullable UUID uuid ) {
411+ PropertyMap map = new PropertyMap (ImmutableMultimap .of ("textures" , new Property ("textures" , value , signature )));
412+ return this .setProfile (new GameProfile ( uuid != null ? uuid : Util .NIL_UUID , "" , map ));
413+ }
414+
415+ /**
416+ * Sets the skull owner tag of a player head.
417+ * If the server parameter is not supplied it may lag the client while it loads the texture,
418+ * otherwise if the server is provided and the {@link GameProfile} contains a UUID then the
419+ * textures will be loaded by the server. This can take some time the first load,
420+ * however the skins are cached for later uses so its often less noticeable to let the
421+ * server load the textures.
422+ *
423+ * @param profile the {@link GameProfile} of the owner
424+ * @return this element builder
425+ */
426+ @ Deprecated
427+ public AnimatedGuiElementBuilder setSkullOwner (GameProfile profile , @ Nullable MinecraftServer server ) {
428+ return this .setProfile (profile );
429+ }
430+
377431 /**
378432 * Sets the skull owner tag of a player head.
379433 * This method uses raw values required by client to display the skin
@@ -382,6 +436,7 @@ public AnimatedGuiElementBuilder setSkullOwner(GameProfile profile, @Nullable Mi
382436 * @param value texture value used by client
383437 * @return this element builder
384438 */
439+ @ Deprecated
385440 public AnimatedGuiElementBuilder setSkullOwner (String value ) {
386441 return this .setSkullOwner (value , null , null );
387442 }
@@ -396,11 +451,9 @@ public AnimatedGuiElementBuilder setSkullOwner(String value) {
396451 * @param uuid UUID of skin owner, if null default will be used
397452 * @return this element builder
398453 */
454+ @ Deprecated
399455 public AnimatedGuiElementBuilder setSkullOwner (String value , @ Nullable String signature , @ Nullable UUID uuid ) {
400- PropertyMap map = new PropertyMap ();
401- map .put ("textures" , new Property ("textures" , value , signature ));
402- this .itemStack .set (DataComponentTypes .PROFILE , new ProfileComponent (Optional .empty (), Optional .ofNullable (uuid ), map ));
403- return this ;
456+ return this .setProfileSkinTexture (value , signature , uuid );
404457 }
405458
406459 /**
0 commit comments