MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / ResourceManager

Class ResourceManager

Minecraft-Utils/1.8/src/ResourceManager.java:33–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31import java.util.concurrent.*;
32
33public class ResourceManager implements IResourceManager {
34
35 private static final int PLAYER_RESOURCE_VERSION = 1;
36
37 private static final ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("5zig Texture Downloader #%d").setDaemon(true)
38 .build());
39 private static final String BASE_URL = "http://textures.5zig.net/";
40 private static final Gson gson = new Gson();
41
42 private final FaceBakery faceBakery = new FaceBakery();
43
44 private final GameProfile playerProfile;
45 private PlayerResource ownPlayerResource;
46 private final Cache<UUID, PlayerResource> playerResources = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.MINUTES).build();
47 private final Cache<Integer, String> moduleIds = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build();
48
49 public ResourceManager(GameProfile playerProfile) {
50 this.playerProfile = playerProfile;
51 }
52
53 public void loadPlayerTextures(final GameProfile gameProfile) {
54 if (gameProfile == null || gameProfile.getId() == null) {
55 return;
56 }
57 PlayerResource playerResource;
58 if (playerProfile.getName().equals(gameProfile.getName())) {
59 if (ownPlayerResource != null) {
60 playerResource = ownPlayerResource;
61 } else {
62 playerResource = ownPlayerResource = loadPlayerResource(playerProfile);
63 }
64 } else {
65 playerResource = playerResources.getIfPresent(gameProfile.getId());
66 if (playerResource != null) {
67 MinecraftFactory.getClassProxyCallback().getLogger().debug("Loaded player resource textures from cache for player " + gameProfile.getName());
68 } else {
69 playerResources.put(gameProfile.getId(), loadPlayerResource(gameProfile));
70 }
71 }
72 if (playerResource == null) {
73 return;
74 }
75
76 if (playerResource.getItemModelResources() != null) {
77 for (ItemModelResource itemModelResource : playerResource.getItemModelResources()) {
78 ResourceLocation resourceLocation = (ResourceLocation) itemModelResource.getResourceLocation();
79 if (((Variables) MinecraftFactory.getVars()).getTextureManager().b(resourceLocation) == null) {
80 ((Variables) MinecraftFactory.getVars()).getTextureManager().a(resourceLocation, (SimpleTexture) itemModelResource.getSimpleTexture());
81 }
82 }
83 }
84 }
85
86 private PlayerResource loadPlayerResource(final GameProfile gameProfile) {
87 final MinecraftProfileTexture minecraftProfileTexture = new MinecraftProfileTexture(
88 BASE_URL + "textures/" + PLAYER_RESOURCE_VERSION + "/" + Utils.getUUIDWithoutDashes(gameProfile.getId()), new HashMap<String, String>());
89 final PlayerResource playerResource = new PlayerResource();
90

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected