Commit 41ccdae9 by Jonathan Thomas

New Custom Player Icon support (if black/white pixel set at 31, 49), uses…

New Custom Player Icon support (if black/white pixel set at 31, 49), uses certain empty UV coordinates in player skin file.
parent 23645ee3
Pipeline #13252 failed with stages
in 16 seconds
......@@ -7,6 +7,8 @@ All notable changes to **CreatureChat** are documented in this file. The format
## Unreleased
### Added
- New Custom Player Icon support (if black/white pixel set at 31, 49), uses certain empty UV coordinates in player skin file.
- New mixin to extend PlayerSkinTexture to make a copy of the NativeImage (used later for custom skin rendering)
- Rate limiter for LLM unit tests (to prevent rate limit issues from certain providers when running all tests)
- Check friendship direction (+ or -) in LLM unit tests (to verify friendship is output correctly)
......
package com.owlmaddie.mixin.client;
import com.owlmaddie.utils.IPlayerSkinTexture;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.PlayerSkinTexture;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* The {@code MixinPlayerSkinTexture} class injects code into the PlayerSkinTexture class, to make a copy
* of the player's skin native image, so we can later use it for pixel checking (black/white key) for
* loading custom player icons in the unused UV coordinates of the player skin image.
*/
@Mixin(PlayerSkinTexture.class)
public abstract class MixinPlayerSkinTexture extends ResourceTexture implements IPlayerSkinTexture {
@Unique
private NativeImage cachedSkinImage;
public MixinPlayerSkinTexture(Identifier location) {
super(location);
}
@Inject(method = "onTextureLoaded", at = @At("HEAD"))
private void captureNativeImage(NativeImage image, CallbackInfo ci) {
// Instead of image.copy(), we do a manual clone
this.cachedSkinImage = cloneNativeImage(image);
}
@Override
public NativeImage getLoadedImage() {
return this.cachedSkinImage;
}
// Example of the utility method in the same class (or in a separate helper):
private static NativeImage cloneNativeImage(NativeImage source) {
NativeImage copy = new NativeImage(
source.getFormat(),
source.getWidth(),
source.getHeight(),
false
);
copy.copyFrom(source);
return copy;
}
}
package com.owlmaddie.utils;
import net.minecraft.client.texture.NativeImage;
import org.jetbrains.annotations.Nullable;
/**
* The {@code IPlayerSkinTexture} interface adds a new getLoadedImage method to PlayerSkinTexture instances
*/
public interface IPlayerSkinTexture {
@Nullable
NativeImage getLoadedImage();
}
\ No newline at end of file
......@@ -3,7 +3,8 @@
"package": "com.owlmaddie.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"EntityRendererMixin"
"EntityRendererMixin",
"MixinPlayerSkinTexture"
],
"injectors": {
"defaultRequire": 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment