mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-21 18:32:14 +00:00
Fix 1.8-1.8.9 texture binding mistake
Support new UniSkinApi
This commit is contained in:
1 parent
03388e3f85
commit
bebbbb0050
6 files changed
+18
-12
No files matched your search
@@ -0,0 +1,74 @@
|
||||
package customskinloader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
|
||||
/**
|
||||
* Model Manager for 1.8 and higher.
|
||||
* A manager to check if model is available.
|
||||
* It is the only class in package 'customskinloader' which has differences in different Minecraft version.
|
||||
* @since 13.1
|
||||
*/
|
||||
public class ModelManager0 {
|
||||
private static ArrayList<String> models=null;
|
||||
|
||||
/**
|
||||
* Check if model is available.
|
||||
* @param model - default/slim
|
||||
* @since 13.1
|
||||
*/
|
||||
public static boolean checkModel(String model){
|
||||
if(models==null)
|
||||
refreshModels();
|
||||
return models.contains(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse hashMapProfile to UserProfile
|
||||
* @param profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
||||
* @return profile - UserProfile instance
|
||||
* @since 13.1
|
||||
*/
|
||||
public static UserProfile toUserProfile(Map profile){
|
||||
UserProfile userProfile=new UserProfile();
|
||||
MinecraftProfileTexture skin=(MinecraftProfileTexture)profile.get(Type.SKIN);
|
||||
userProfile.skinUrl= skin==null?null:skin.getUrl();//Avoid NullPointerException
|
||||
userProfile.model= skin==null?null:skin.getMetadata("model");
|
||||
if(userProfile.model==null||userProfile.model.equals(""))
|
||||
userProfile.model="default";
|
||||
MinecraftProfileTexture cape=(MinecraftProfileTexture)profile.get(Type.CAPE);
|
||||
userProfile.capeUrl= cape==null?null:cape.getUrl();
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse UserProfile to hashMapProfile
|
||||
* @param profile - UserProfile instance
|
||||
* @return profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
||||
* @since 13.1
|
||||
*/
|
||||
public static Map fromUserProfile(UserProfile profile){
|
||||
Map map=Maps.newHashMap();
|
||||
if(profile.skinUrl!=null){
|
||||
Map metadata=null;
|
||||
if(profile.model!=null&&profile.model.equals("slim")){
|
||||
metadata = Maps.newHashMap();
|
||||
metadata.put("model", "slim");
|
||||
}
|
||||
map.put(Type.SKIN, new MinecraftProfileTexture(profile.skinUrl,metadata));
|
||||
}
|
||||
if(profile.capeUrl!=null)
|
||||
map.put(Type.CAPE, new MinecraftProfileTexture(profile.capeUrl,null));
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void refreshModels(){
|
||||
models=new ArrayList<String>();
|
||||
models.add("default");
|
||||
models.add("slim");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user