com.mojang.authlib.minecraft.MinecraftProfileTexture Java Examples

The following examples show how to use com.mojang.authlib.minecraft.MinecraftProfileTexture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NickHider.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ResourceLocation getPlayerSkin() {
    if (playerSkin == null && !startedLoadingSkin) {
        startedLoadingSkin = true;
        Minecraft.getMinecraft().getSkinManager().loadProfileTextures(Minecraft.getMinecraft().getSession().getProfile(), (type, location, profileTexture) -> {
            if (type == MinecraftProfileTexture.Type.SKIN) {
                playerSkin = location;
                playerRealSkinType = profileTexture.getMetadata("model");
                if (playerRealSkinType == null) playerRealSkinType = "default";
            } else if (type == MinecraftProfileTexture.Type.CAPE) {
                playerCape = location;
            }
        }, true);
    }

    return playerSkin;
}
 
Example #2
Source File: YggdrasilMinecraftSessionService.java    From Launcher with GNU General Public License v3.0 6 votes vote down vote up
private static void getTexturesMojang(Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures, String texturesBase64, GameProfile profile) {
    // Decode textures payload
    JsonObject texturesJSON;
    try {
        byte[] decoded = Base64.getDecoder().decode(texturesBase64);
        texturesJSON = JsonParser.parseString(new String(decoded, IOHelper.UNICODE_CHARSET)).getAsJsonObject().getAsJsonObject("textures");
    } catch (Exception ignored) {
        LogHelper.error("Could not decode textures payload, Username: '%s', UUID: '%s'", profile.getName(), profile.getUUID());
        return;
    }

    // Fetch textures from textures JSON
    for (MinecraftProfileTexture.Type type : MinecraftProfileTexture.PROFILE_TEXTURE_TYPES) {
        if (textures.containsKey(type))
            continue; // Overriden by launcher

        // Get texture from JSON
        JsonElement textureJSON = texturesJSON.get(type.name());
        if (textureJSON != null && textureJSON.isJsonObject()) {
            JsonElement urlValue = textureJSON.getAsJsonObject().get("url");
            if (urlValue.isJsonPrimitive())
                textures.put(type, new MinecraftProfileTexture(urlValue.getAsString()));
        }
    }
}
 
Example #3
Source File: PlayerSkinProviderMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Shadow
public Identifier loadSkin(MinecraftProfileTexture profileTexture,
	Type type,
	@Nullable PlayerSkinProvider.SkinTextureAvailableCallback callback)
{
	return null;
}
 
Example #4
Source File: MixinSkinManager.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "loadSkinFromCache", cancellable = true, at = @At("HEAD"))
private void injectSkinProtect(GameProfile gameProfile, CallbackInfoReturnable<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> cir) {
    if (gameProfile == null)
        return;
    
    NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if (nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (nameProtect.allPlayersValue.get() || Objects.equals(gameProfile.getId(), Minecraft.getMinecraft().getSession().getProfile().getId())) {
            cir.setReturnValue(new HashMap<>());
            cir.cancel();
        }
    }
}
 
Example #5
Source File: MixinSkinManager.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "loadSkinFromCache", cancellable = true, at = @At("HEAD"))
private void injectSkinProtect(GameProfile gameProfile, CallbackInfoReturnable<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> cir) {
    if (gameProfile == null)
        return;
    
    NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if (nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (nameProtect.allPlayersValue.get() || Objects.equals(gameProfile.getId(), Minecraft.getMinecraft().getSession().getProfile().getId())) {
            cir.setReturnValue(new HashMap<>());
            cir.cancel();
        }
    }
}
 
Example #6
Source File: YggdrasilMinecraftSessionService.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile profile, boolean requireSecure) {
    if (LogHelper.isDebugEnabled()) {
        LogHelper.debug("getTextures, Username: '%s', UUID: '%s'", profile.getName(), profile.getUUID());
    }
    Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures = new EnumMap<>(MinecraftProfileTexture.Type.class);

    // Add textures
    if (!NO_TEXTURES) {
        // Add skin URL to textures map
        Property skinURL = Iterables.getFirst(profile.getProperties().get(Launcher.SKIN_URL_PROPERTY), null);
        Property skinDigest = Iterables.getFirst(profile.getProperties().get(Launcher.SKIN_DIGEST_PROPERTY), null);
        if (skinURL != null && skinDigest != null)
            textures.put(MinecraftProfileTexture.Type.SKIN, new MinecraftProfileTexture(skinURL.getValue(), skinDigest.getValue()));

        // Add cloak URL to textures map
        Property cloakURL = Iterables.getFirst(profile.getProperties().get(Launcher.CLOAK_URL_PROPERTY), null);
        Property cloakDigest = Iterables.getFirst(profile.getProperties().get(Launcher.CLOAK_DIGEST_PROPERTY), null);
        if (cloakURL != null && cloakDigest != null)
            textures.put(MinecraftProfileTexture.Type.CAPE, new MinecraftProfileTexture(cloakURL.getValue(), cloakDigest.getValue()));

        // Try to find missing textures in textures payload (now always true because launcher is not passing elytra skins)
        if (textures.size() != MinecraftProfileTexture.PROFILE_TEXTURE_COUNT) {
            Property texturesMojang = Iterables.getFirst(profile.getProperties().get("textures"), null);
            if (texturesMojang != null)
                getTexturesMojang(textures, texturesMojang.getValue(), profile);
        }
    }

    // Return filled textures
    return textures;
}
 
Example #7
Source File: GuiSkinsMineLP.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
public void onSetRemoteSkin(SkinType type, Identifier location, MinecraftProfileTexture profileTexture) {
    super.onSetRemoteSkin(type, location, profileTexture);

    MineLittlePony.logger.debug("Invalidating old remote skin, checking updated remote skin");
    if (type == SkinType.SKIN) {
        ponyManager.removePony(location);
    }
}
 
Example #8
Source File: SkinsProxy.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Nullable
public Identifier getSkinTexture(GameProfile profile) {
    PlayerSkinProvider skins = MinecraftClient.getInstance().getSkinProvider();

    @Nullable
    MinecraftProfileTexture texture = skins.getTextures(profile).get(MinecraftProfileTexture.Type.SKIN);

    if (texture == null) {
        return null;
    }

    return skins.loadSkin(texture, MinecraftProfileTexture.Type.SKIN);
}
 
Example #9
Source File: NewSkinManager.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public ResourceLocation func_152789_a(final MinecraftProfileTexture texture, final Type type, final SkinManager.SkinAvailableCallback callBack) {
	if (type != Type.SKIN)
		return super.func_152789_a(texture, type, callBack);

	final boolean isSpecialCallBack = callBack instanceof ISkinDownloadCallback;
	final ResourceLocation resLocationOld = new ResourceLocation("skins/" + texture.getHash());
	final ResourceLocation resLocation = new ResourceLocation(Reference.MOD_ID, resLocationOld.getResourcePath());
	ITextureObject itextureobject = textureManager.getTexture(resLocation);

	if (itextureobject != null) {
		if (callBack != null)
			callBack.func_152121_a(type, resLocation);
	} else {
		File file1 = new File(skinFolder, texture.getHash().substring(0, 2));
		File file2 = new File(file1, texture.getHash());
		final NewImageBufferDownload imgDownload = new NewImageBufferDownload();
		ITextureObject imgData = new NewThreadDownloadImageData(file2, texture.getUrl(), field_152793_a, imgDownload, resLocationOld, new IImageBuffer() {

			@Override
			public BufferedImage parseUserSkin(BufferedImage buffImg) {
				if (buffImg != null)
					PlayerModelManager.analyseTexture(buffImg, resLocation);
				return imgDownload.parseUserSkin(buffImg);
			}

			@Override
			public void func_152634_a() {
				imgDownload.func_152634_a();
				if (callBack != null)
					callBack.func_152121_a(type, isSpecialCallBack ? resLocation : resLocationOld);
			}
		});
		textureManager.loadTexture(resLocation, imgData);
		textureManager.loadTexture(resLocationOld, imgData); // Avoid thrown exception if the image is requested before the download is done
	}

	return isSpecialCallBack ? resLocation : resLocationOld;
}
 
Example #10
Source File: StaticCape.java    From DeveloperCapes with MIT License 5 votes vote down vote up
@Override
public void loadTexture(AbstractClientPlayer player) {
    ResourceLocation location = this.getLocation();
    player.func_152121_a(MinecraftProfileTexture.Type.CAPE, location);

    Minecraft.getMinecraft().renderEngine.loadTexture(location, this.getTexture());
}
 
Example #11
Source File: PlayerSkinProviderMixin.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {
		"loadSkin(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/texture/PlayerSkinProvider$SkinTextureAvailableCallback;Z)V"},
	cancellable = true)
private void onLoadSkin(GameProfile profile,
	PlayerSkinProvider.SkinTextureAvailableCallback callback,
	boolean requireSecure, CallbackInfo ci)
{
	// Can't @Inject nicely because everything is wrapped in a lambda.
	// Had to replace the whole method.
	
	Runnable runnable = () -> {
		HashMap<MinecraftProfileTexture.Type, MinecraftProfileTexture> map =
			Maps.newHashMap();
		
		try
		{
			map.putAll(sessionService.getTextures(profile, requireSecure));
		}catch(InsecureTextureException var7)
		{
			
		}
		
		if(map.isEmpty())
		{
			profile.getProperties().clear();
			if(profile.getId().equals(MinecraftClient.getInstance()
				.getSession().getProfile().getId()))
			{
				profile.getProperties().putAll(
					MinecraftClient.getInstance().getSessionProperties());
				map.putAll(sessionService.getTextures(profile, false));
			}else
			{
				sessionService.fillProfileProperties(profile,
					requireSecure);
				
				try
				{
					map.putAll(
						sessionService.getTextures(profile, requireSecure));
				}catch(InsecureTextureException var6)
				{
					
				}
			}
		}
		
		addWurstCape(profile, map);
		
		MinecraftClient.getInstance().execute(() -> {
			RenderSystem.recordRenderCall(() -> {
				ImmutableList.of(Type.SKIN, Type.CAPE).forEach((type) -> {
					if(map.containsKey(type))
						loadSkin(map.get(type), type, callback);
				});
			});
		});
	};
	Util.getServerWorkerExecutor().execute(runnable);
	
	ci.cancel();
}
 
Example #12
Source File: PaperMinecraftSessionService.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile profile, boolean requireSecure) {
    return super.getTextures(profile, requireSecure);
}
 
Example #13
Source File: TileEntityFancySkullRenderer.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void renderSkull(float x, float y, float z, int meta, float rotation, int type, GameProfile profile) {
	ModelHead model = model1;

	switch (type) {
		case 0:
		default:
			bindTexture(skeleton_texture);
			break;
		case 1:
			bindTexture(wither_skeleton_texture);
			break;
		case 2:
			bindTexture(zombie_texture);
			model = model2;
			break;
		case 3:
			ResourceLocation texture = AbstractClientPlayer.locationStevePng;
			if (profile != null) {
				Minecraft minecraft = Minecraft.getMinecraft();
				Map<Type, MinecraftProfileTexture> map = minecraft.func_152342_ad().func_152788_a(profile);
				if (map.containsKey(Type.SKIN))
					texture = minecraft.func_152342_ad().func_152792_a(map.get(Type.SKIN), Type.SKIN);
			}
			bindTexture(texture);
			break;
		case 4:
			bindTexture(creeper_texture);
	}

	OpenGLHelper.pushMatrix();
	OpenGLHelper.disableCull();

	if (meta != 1)
		switch (meta) {
			case 2:
				OpenGLHelper.translate(x + 0.5F, y + 0.25F, z + 0.74F);
				break;
			case 3:
				OpenGLHelper.translate(x + 0.5F, y + 0.25F, z + 0.26F);
				rotation = 180.0F;
				break;
			case 4:
				OpenGLHelper.translate(x + 0.74F, y + 0.25F, z + 0.5F);
				rotation = 270.0F;
				break;
			case 5:
			default:
				OpenGLHelper.translate(x + 0.26F, y + 0.25F, z + 0.5F);
				rotation = 90.0F;
		}
	else
		GL11.glTranslatef(x + 0.5F, y, z + 0.5F);

	OpenGLHelper.enableRescaleNormal();
	OpenGLHelper.scale(-1.0F, -1.0F, 1.0F);
	OpenGLHelper.enableAlpha();
	model.render(rotation);
	OpenGLHelper.popMatrix();
}