Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/main/java/lain/mods/skinport/init/forge/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ public class ClientProxy extends CommonProxy {

public static ResourceLocation bindTexture(GameProfile profile, ResourceLocation result) {
if (profile != null) {
LOGGER.debug("Binding texture for profile: {}", profile.getName());
ISkin skin = SkinProviderAPI.SKIN.getSkin(PlayerProfile.wrapGameProfile(profile));
if (skin != null && skin.isDataReady()) {
ResourceLocation location = ClientProxy.getOrCreateTexture(skin.getData(), skin)
.getLocation();
LOGGER.debug("Bound texture for {}: {}", profile.getName(), location);
return location;
}
LOGGER.debug("No skin data ready for {}", profile.getName());
}
return null;
}
Expand All @@ -95,28 +92,22 @@ public static ModelSkeletonHead getHumanoidHead(ResourceLocation location, Model
}

public static ResourceLocation getLocationCape(AbstractClientPlayer player, ResourceLocation result) {
LOGGER.debug("Getting cape location for player: {}", player.getCommandSenderName());
ISkin skin = SkinProviderAPI.CAPE.getSkin(PlayerProfile.wrapGameProfile(player.getGameProfile()));
if (skin != null && skin.isDataReady()) {
ResourceLocation location = ClientProxy.getOrCreateTexture(skin.getData(), skin)
.getLocation();
LOGGER.debug("Cape location for {}: {}", player.getCommandSenderName(), location);
return location;
}
LOGGER.debug("No cape data ready for {}", player.getCommandSenderName());
return null;
}

public static ResourceLocation getLocationSkin(AbstractClientPlayer player, ResourceLocation result) {
LOGGER.debug("Getting skin location for player: {}", player.getCommandSenderName());
ISkin skin = SkinProviderAPI.SKIN.getSkin(PlayerProfile.wrapGameProfile(player.getGameProfile()));
if (skin != null && skin.isDataReady()) {
ResourceLocation location = ClientProxy.getOrCreateTexture(skin.getData(), skin)
.getLocation();
LOGGER.debug("Skin location for {}: {}", player.getCommandSenderName(), location);
return location;
}
LOGGER.debug("No skin data ready for {}", player.getCommandSenderName());
return null;
}

Expand Down Expand Up @@ -160,12 +151,6 @@ public static Render getPlayerRenderer(RenderManager manager, AbstractClientPlay
}
String skinType = getSkinType(player);
result = renderers.getOrDefault(skinType, result);
LOGGER.debug(
"Selected renderer for {} with skin type {}: {}",
player.getCommandSenderName(),
skinType,
result.getClass()
.getSimpleName());
if (result instanceof SpecialRenderer) ((SpecialRenderer) result).onGetRenderer(manager, player);
return result;
}
Expand All @@ -175,12 +160,9 @@ public static String getSkinType(AbstractClientPlayer player) {
if (location != null) {
ISkin skin = SkinProviderAPI.SKIN.getSkin(PlayerProfile.wrapGameProfile(player.getGameProfile()));
if (skin != null && skin.isDataReady()) {
String skinType = skin.getSkinType();
LOGGER.debug("Skin type for {}: {}", player.getCommandSenderName(), skinType);
return skinType;
return skin.getSkinType();
}
}
LOGGER.debug("Using default skin type for {}", player.getCommandSenderName());
return "default";
}

Expand Down
53 changes: 28 additions & 25 deletions src/main/java/lain/mods/skinport/init/forge/ForgeSkinPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.UUID;
Expand Down Expand Up @@ -43,44 +44,46 @@ private static class DefaultSkinProvider implements ISkinProvider {

private static final int HASH_MASK = 0x1;

private final ISkin defaultSteve;
private final ISkin defaultAlex;
private final byte[] defaultSteve;
private final byte[] defaultAlex;

DefaultSkinProvider() {
ISkin steve = null;
ISkin alex = null;
this.defaultSteve = loadDefaultSkin("/DefaultSteve.png");
this.defaultAlex = loadDefaultSkin("/DefaultAlex.png");
}

private static byte[] loadDefaultSkin(String resource) {
LOGGER.debug("Loading default skin: {}", resource);
URL url = DefaultSkinProvider.class.getResource(resource);
if (url == null) {
LOGGER.error("Default skin resource not found on classpath: {}", resource);
return null;
}
try {
LOGGER.debug("Loading default Steve skin");
byte[] steveData = IOUtils.toByteArray(DefaultSkinProvider.class.getResource("/DefaultSteve.png"));
SkinData steveSkin = new SkinData();
steveSkin.put(steveData, "default");
steve = steveSkin;
LOGGER.debug("Default Steve skin loaded successfully");

LOGGER.debug("Loading default Alex skin");
byte[] alexData = IOUtils.toByteArray(DefaultSkinProvider.class.getResource("/DefaultAlex.png"));
SkinData alexSkin = new SkinData();
alexSkin.put(alexData, "slim");
alex = alexSkin;
LOGGER.debug("Default Alex skin loaded successfully");
byte[] data = IOUtils.toByteArray(url);
LOGGER.debug("Default skin loaded successfully: {} ({} bytes)", resource, data.length);
return data;
} catch (IOException e) {
LOGGER.error("Failed to load default skins", e);
LOGGER.error("Failed to load default skin: {}", resource, e);
return null;
}

this.defaultSteve = steve;
this.defaultAlex = alex;
}

@Override
public ISkin getSkin(IPlayerProfile profile) {
UUID uuid = profile.getPlayerID();
if (uuid != null && (uuid.hashCode() & HASH_MASK) == 1) {
LOGGER.debug("Using default Alex skin for player: {} (UUID: {})", profile.getPlayerName(), uuid);
return defaultAlex;
return createSkin(defaultAlex, "slim");
}
LOGGER.debug("Using default Steve skin for player: {} (UUID: {})", profile.getPlayerName(), uuid);
return defaultSteve;
return createSkin(defaultSteve, "default");
}

private ISkin createSkin(byte[] data, String type) {
if (data == null) return null;

SkinData skin = new SkinData();
skin.put(data, type);
return skin;
}

}
Expand Down