2020import java .io .File ;
2121import java .io .IOException ;
2222import java .io .InputStream ;
23+ import java .lang .reflect .Field ;
2324import java .net .URL ;
2425import java .net .URLConnection ;
2526import java .util .UUID ;
2627import java .util .concurrent .ExecutionException ;
2728
28- /* These imports require forge and provided support for dynamic skins
29- * Comment them out if compiled as a standalone library.
30- */
31-
3229/**
3330 * Provided the interface to interact with Mojang codes
3431 */
@@ -51,7 +48,24 @@ public UniSkinCore(UniSkinConfig configuration, File localSkin) {
5148 for (String str : cfg .legacyCapeURIs ) UniSkinMod .log .info ("Added Cape URI: {}" , str );
5249 mojangProfileRepo = new YggdrasilAuthenticationService (Minecraft .getMinecraft ().getProxy (), UUID .randomUUID ().toString ())
5350 .createProfileRepository ();
54- dynamicSkinManager = new DynamicSkinManager (cfg .rootURIs , localSkin );
51+
52+ File assertDir ;
53+ try {
54+ Field f ;
55+ try {
56+ f = Minecraft .class .getDeclaredField ("field_110446_Y" );
57+ } catch (NoSuchFieldException ex ) {
58+ f = null ;
59+ }
60+ if (f == null ) f = Minecraft .class .getDeclaredField ("fileAssets" );
61+ f .setAccessible (true );
62+ Object obj = f .get (Minecraft .getMinecraft ());
63+ assertDir = (File ) obj ;
64+ } catch (ReflectiveOperationException ex ) {
65+ throw new RuntimeException ("Unable to determine skin cache dir." , ex );
66+ }
67+ if (assertDir == null ) throw new RuntimeException ("Unable to determine skin cache dir." );
68+ dynamicSkinManager = new DynamicSkinManager (cfg .rootURIs , localSkin , new File (assertDir , "skins" ));
5569 }
5670
5771 public void injectProfile (GameProfile profile ) {
@@ -219,7 +233,8 @@ private void injectLegacyProfile(GameProfile profile) {
219233 try {
220234 File localFile = new File (localTexture , hash );
221235 FileUtils .writeByteArrayToFile (localFile , skinData );
222- payload .addSkin (localFile .toURI ().toString (), "default" );
236+ dynamicSkinManager .forceLoadTexture (localFile , MinecraftProfileTexture .Type .SKIN , false );
237+ payload .addSkin ("http://127.0.0.1/" + hash , "default" );
223238 UniSkinMod .log .info ("Injecting legacy skin: {} {}" , playerName , hash );
224239 } catch (IOException ex ) {
225240 UniSkinMod .log .catching (Level .WARN , ex );
@@ -240,7 +255,8 @@ private void injectLegacyProfile(GameProfile profile) {
240255 try {
241256 File localFile = new File (localTexture , hash );
242257 FileUtils .writeByteArrayToFile (localFile , capeData );
243- payload .addCape (localFile .toURI ().toString ());
258+ dynamicSkinManager .forceLoadTexture (localFile , MinecraftProfileTexture .Type .CAPE , false );
259+ payload .addCape ("http://127.0.0.1/" + hash );
244260 UniSkinMod .log .info ("Injecting legacy cape: {} {}" , playerName , hash );
245261 } catch (IOException ex ) {
246262 UniSkinMod .log .catching (Level .WARN , ex );
@@ -251,10 +267,10 @@ private void injectLegacyProfile(GameProfile profile) {
251267 payload .dumpIntoGameProfile (profile );
252268 }
253269
270+
254271 /* Codes below require forge and provided support for dynamic skins
255272 * Comment them out if compiled as a standalone library. */
256273
257-
258274 /**
259275 * called from AbstractClientPlayer.getLocationSkin()
260276 */
@@ -264,7 +280,6 @@ public ResourceLocation getDynamicSkinResource(NetworkPlayerInfo player) {
264280
265281 /**
266282 * called from TileEntitySkllRenderer.renderSkull()
267- * <pre>resourcelocation = UniSkinMod.getDynamicSkinResourceForSkull(p_188190_7_,DefaultPlayerSkin.getDefaultSkin(uuid));</pre>
268283 */
269284 public ResourceLocation getDynamicSkinResourceForSkull (GameProfile gp , ResourceLocation def ) {
270285 if (gp == null ) return def ;
@@ -278,6 +293,8 @@ public ResourceLocation getDynamicSkinResourceForSkull(GameProfile gp, ResourceL
278293 return s .skin [id ];
279294 }
280295 } catch (ExecutionException ex ) {
296+ UniSkinMod .log .catching (Level .WARN , ex );
297+ return def ;
281298 }
282299 return def ;
283300 }
@@ -297,6 +314,8 @@ public String getDynamicSkinModel(NetworkPlayerInfo player) {
297314 return s .model ;
298315 }
299316 } catch (ExecutionException ex ) {
317+ UniSkinMod .log .catching (Level .WARN , ex );
318+ return null ;
300319 }
301320 }
302321 }
@@ -315,11 +334,13 @@ public ResourceLocation getDynamicCapeResource(NetworkPlayerInfo player) {
315334 try {
316335 DynamicSkinManager .CachedDynamicSkin s = dynamicSkinManager .cache .get (name );
317336 if (s .cape != null && s .cape .length != 0 ) {
318- double spf = (double ) s .skinInterval / (double ) s .skin .length ;
337+ double spf = (double ) s .capeInterval / (double ) s .cape .length ;
319338 int id = ((int ) Math .floor ((double ) (System .currentTimeMillis () % s .capeInterval ) / spf )) % (s .cape .length );
320339 return s .cape [id ];
321340 }
322341 } catch (ExecutionException ex ) {
342+ UniSkinMod .log .catching (Level .WARN , ex );
343+ return null ;
323344 }
324345 }
325346 }
@@ -338,11 +359,13 @@ public ResourceLocation getDynamicElytraResource(NetworkPlayerInfo player) {
338359 try {
339360 DynamicSkinManager .CachedDynamicSkin s = dynamicSkinManager .cache .get (name );
340361 if (s .elytra != null && s .elytra .length != 0 ) {
341- double spf = (double ) s .skinInterval / (double ) s .skin .length ;
362+ double spf = (double ) s .elytraInterval / (double ) s .elytra .length ;
342363 int id = ((int ) Math .floor ((double ) (System .currentTimeMillis () % s .elytraInterval ) / spf )) % (s .elytra .length );
343364 return s .elytra [id ];
344365 }
345366 } catch (ExecutionException ex ) {
367+ UniSkinMod .log .catching (Level .WARN , ex );
368+ return null ;
346369 }
347370 }
348371 }
0 commit comments