blob: e460c64dad6b97d420c3fd1120c285809e8716fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
package com.mondecitronne.homunculus.skin;
import java.util.Map;
import javax.annotation.Nullable;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.mondecitronne.homunculus.GameProfileFetcher;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
public class PlayerSkin extends Skin {
private final GameProfile profile;
private final GameProfileFetcher profileFetcher;
private final boolean isRemote;
public PlayerSkin(GameProfile profile, boolean isRemote) {
this.profile = profile;
profileFetcher = new GameProfileFetcher(this.profile);
this.isRemote = isRemote;
}
@Override
public boolean isLoaded() {
if (this.isRemote) {
return getTexture() != null;
} else {
return profileFetcher.getGameProfile() != null;
}
}
public GameProfile getPlayerProfile() {
GameProfile fetchProfile = profileFetcher.getGameProfile();
if (fetchProfile != null) {
return profileFetcher.getGameProfile();
} else {
return profile;
}
}
protected MinecraftProfileTexture getProfileTexture() {
assert(this.isRemote);
GameProfile playerProfile = getPlayerProfile();
if (playerProfile != null) {
Minecraft minecraft = Minecraft.getMinecraft();
Map<Type, MinecraftProfileTexture> map = minecraft.getSkinManager().loadSkinFromCache(playerProfile);
if (map != null) {
return map.get(Type.SKIN);
} else {
return null;
}
} else {
return null;
}
}
@Override
public String getModelType() {
assert(this.isRemote);
if (getTexture() != null) {
MinecraftProfileTexture tex = getProfileTexture();
if (tex != null && tex.getMetadata("model") != null) {
return tex.getMetadata("model");
}
}
return null;
}
@Override
@Nullable
public ResourceLocation getTexture() {
assert(this.isRemote);
MinecraftProfileTexture tex = getProfileTexture();
if (tex != null) {
ResourceLocation location = Minecraft.getMinecraft().getSkinManager().loadSkin(tex, Type.SKIN);
if (location != null) {
return location;
}
}
return null;
}
}
|