Files
MCCustomSkinLoader/Common/source/customskinloader/fake/FakeClientPlayer.java
T

87 lines
3.7 KiB
Java
Raw Normal View History

2018-02-10 20:21:26 +08:00
package customskinloader.fake;
2018-07-02 00:15:03 +08:00
import java.util.Map;
2018-02-10 20:21:26 +08:00
import java.util.UUID;
2018-07-02 00:15:03 +08:00
import com.google.common.collect.Maps;
2018-02-10 20:21:26 +08:00
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
2018-02-10 21:23:58 +08:00
import customskinloader.CustomSkinLoader;
2018-02-10 20:21:26 +08:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
2018-02-11 15:36:40 +08:00
import net.minecraft.client.renderer.texture.SimpleTexture;
2018-02-10 20:21:26 +08:00
import net.minecraft.client.renderer.texture.TextureManager;
2018-02-11 15:36:40 +08:00
import net.minecraft.client.resources.DefaultPlayerSkin;
2018-02-10 20:21:26 +08:00
import net.minecraft.client.resources.SkinManager;
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
2018-02-11 15:36:40 +08:00
import net.minecraft.util.StringUtils;
2018-02-10 20:21:26 +08:00
public class FakeClientPlayer {
2018-06-24 22:59:46 +08:00
//For Legacy Skin
public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username) {
//CustomSkinLoader.logger.debug("FakeClientPlayer/getDownloadImageSkin "+username);
TextureManager textman = Minecraft.getMinecraft().getTextureManager();
ITextureObject ito = textman.getTexture(resourceLocationIn);
if (ito == null || !(ito instanceof ThreadDownloadImageData)) {
//if Legacy Skin for username not loaded yet
SkinManager skinman = Minecraft.getMinecraft().getSkinManager();
UUID offlineUUID = EntityPlayer.getOfflineUUID(username);
GameProfile offlineProfile = new GameProfile(offlineUUID, username);
//Load Default Skin
ResourceLocation defaultSkin = DefaultPlayerSkin.getDefaultSkin(offlineUUID);
ITextureObject defaultSkinObj = new SimpleTexture(defaultSkin);
textman.loadTexture(resourceLocationIn, defaultSkinObj);
//Load Skin from SkinManager
skinman.loadProfileTextures(offlineProfile, new LegacyBuffer(resourceLocationIn), false);
2018-02-12 12:20:28 +08:00
}
2018-02-10 20:21:26 +08:00
2018-06-24 22:59:46 +08:00
if (ito instanceof ThreadDownloadImageData)
return (ThreadDownloadImageData) ito;
else
return null;
}
public static ResourceLocation getLocationSkin(String username) {
//CustomSkinLoader.logger.debug("FakeClientPlayer/getLocationSkin "+username);
return new ResourceLocation("skins/legacy-" + StringUtils.stripControlCodes(username));
}
2018-07-02 00:15:03 +08:00
public static Map<ResourceLocation, ITextureObject> textureCache = Maps.newHashMap();
public static class LegacyBuffer implements SkinAvailableCallback {
2018-06-24 22:59:46 +08:00
ResourceLocation resourceLocationIn;
boolean loaded = false;
public LegacyBuffer(ResourceLocation resourceLocationIn) {
CustomSkinLoader.logger.debug("Loading Legacy Texture (" + resourceLocationIn + ")");
this.resourceLocationIn = resourceLocationIn;
2018-02-12 12:20:28 +08:00
}
2018-06-24 22:59:46 +08:00
@Override
public void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
if (typeIn != Type.SKIN || loaded)
return;
TextureManager textman = Minecraft.getMinecraft().getTextureManager();
ITextureObject ito = textman.getTexture(location);
2018-07-02 00:15:03 +08:00
if (ito == null)
ito = textureCache.get(location);
2018-07-01 23:25:57 +08:00
if (ito == null)
return;
loaded = true;
textman.loadTexture(resourceLocationIn, ito);
2018-06-24 22:59:46 +08:00
CustomSkinLoader.logger.debug("Legacy Texture (" + resourceLocationIn + ") Loaded as " +
ito.toString() + " (" + location + ")");
2018-02-12 12:20:28 +08:00
}
2018-06-24 22:59:46 +08:00
}
2018-02-10 20:21:26 +08:00
}