-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace fake client player with a draggable widget
- Loading branch information
Showing
7 changed files
with
245 additions
and
356 deletions.
There are no files selected for viewing
268 changes: 0 additions & 268 deletions
268
src/main/java/io/github/gaming32/worldhost/GameProfileRenderer.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.github.gaming32.worldhost; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import net.minecraft.client.resources.SkinManager; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
|
||
//#if MC >= 1.20.2 | ||
import net.minecraft.client.resources.PlayerSkin; | ||
//#else | ||
//$$ import com.mojang.authlib.minecraft.MinecraftProfileTexture; | ||
//$$ import java.util.UUID; | ||
//$$ import java.util.concurrent.CompletableFuture; | ||
//$$ import net.minecraft.client.resources.DefaultPlayerSkin; | ||
//$$ import net.minecraft.core.UUIDUtil; | ||
//#endif | ||
|
||
// TODO: Remove in 1.20.2+ | ||
public record WHPlayerSkin( | ||
ResourceLocation texture, | ||
ResourceLocation capeTexture, | ||
Model model | ||
) { | ||
//#if MC >= 1.20.2 | ||
public static WHPlayerSkin fromPlayerSkin(PlayerSkin skin) { | ||
return new WHPlayerSkin(skin.texture(), skin.capeTexture(), Model.byName(skin.model().id())); | ||
} | ||
//#endif | ||
|
||
public static WHPlayerSkin fromSkinManager(SkinManager skinManager, GameProfile profile) { | ||
//#if MC >= 1.20.2 | ||
return fromPlayerSkin(skinManager.getInsecureSkin(profile)); | ||
//#else | ||
//$$ final var map = skinManager.getInsecureSkinInformation(profile); | ||
//$$ final MinecraftProfileTexture skin = map.get(MinecraftProfileTexture.Type.SKIN); | ||
//$$ final ResourceLocation skinTexture; | ||
//$$ final String skinModel; | ||
//$$ if (skin != null) { | ||
//$$ skinTexture = skinManager.registerTexture(skin, MinecraftProfileTexture.Type.SKIN); | ||
//$$ skinModel = skin.getMetadata("model"); | ||
//$$ } else { | ||
//$$ final UUID uuid = UUIDUtil.getOrCreatePlayerUUID(profile); | ||
//$$ skinTexture = DefaultPlayerSkin.getDefaultSkin(uuid); | ||
//$$ skinModel = DefaultPlayerSkin.getSkinModelName(uuid); | ||
//$$ } | ||
//$$ final MinecraftProfileTexture cape = map.get(MinecraftProfileTexture.Type.CAPE); | ||
//$$ return new WHPlayerSkin( | ||
//$$ skinTexture, | ||
//$$ cape != null ? skinTexture.registerTexture(cape, MinecraftProfileTexture.Type.CAPE) : null, | ||
//$$ Model.byName(skinModel) | ||
//$$ ); | ||
//#endif | ||
} | ||
|
||
public enum Model { | ||
SLIM, WIDE; | ||
|
||
public static Model byName(String name) { | ||
return switch (name) { | ||
case "slim" -> SLIM; | ||
case null, default -> WIDE; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.