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;
|
2019-09-18 22:15:58 +08:00
|
|
|
import customskinloader.utils.MinecraftUtil;
|
2018-02-10 20:21:26 +08:00
|
|
|
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.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 {
|
2022-12-07 19:38:24 +08:00
|
|
|
/**
|
|
|
|
|
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager.SkinAvailableCallback)}
|
|
|
|
|
*/
|
|
|
|
|
public static ThreadDownloadImageData putCache(ThreadDownloadImageData threaddownloadimagedata, SkinManager.SkinAvailableCallback skinAvailableCallback, ResourceLocation resourcelocation) {
|
|
|
|
|
if (skinAvailableCallback instanceof FakeClientPlayer.LegacyBuffer) {//Cache for client player
|
|
|
|
|
textureCache.put(resourcelocation, threaddownloadimagedata);
|
|
|
|
|
}
|
|
|
|
|
return threaddownloadimagedata;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2019-09-18 22:15:58 +08:00
|
|
|
TextureManager textman = MinecraftUtil.getTextureManager();
|
2018-06-24 22:59:46 +08:00
|
|
|
ITextureObject ito = textman.getTexture(resourceLocationIn);
|
|
|
|
|
|
|
|
|
|
if (ito == null || !(ito instanceof ThreadDownloadImageData)) {
|
|
|
|
|
//if Legacy Skin for username not loaded yet
|
2019-09-18 22:15:58 +08:00
|
|
|
SkinManager skinman = MinecraftUtil.getSkinManager();
|
2018-08-26 07:04:25 +08:00
|
|
|
UUID offlineUUID = getOfflineUUID(username);
|
2018-06-24 22:59:46 +08:00
|
|
|
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));
|
|
|
|
|
}
|
2019-09-18 22:15:58 +08:00
|
|
|
|
|
|
|
|
public static UUID getOfflineUUID(String username) {
|
2018-08-26 07:04:25 +08:00
|
|
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes());
|
|
|
|
|
}
|
2018-06-24 22:59:46 +08:00
|
|
|
|
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;
|
|
|
|
|
|
2019-09-18 22:15:58 +08:00
|
|
|
TextureManager textman = MinecraftUtil.getTextureManager();
|
2018-06-24 22:59:46 +08:00
|
|
|
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)
|
2018-07-01 23:15:06 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
loaded = true;
|
|
|
|
|
textman.loadTexture(resourceLocationIn, ito);
|
2018-06-24 22:59:46 +08:00
|
|
|
CustomSkinLoader.logger.debug("Legacy Texture (" + resourceLocationIn + ") Loaded as " +
|
2018-07-01 23:15:06 +08:00
|
|
|
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
|
|
|
}
|