Add: support OptiFine cape

This commit is contained in:
33 committed 2023-01-11 18:51:44 +08:00
1 parent 2d00e12f0a
commit 84072c62f3
4 files changed
+109 -43

No files matched your search

@@ -2,11 +2,7 @@ package customskinloader.config;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.*;
import customskinloader.CustomSkinLoader;
import customskinloader.loader.ProfileLoader;
@@ -29,7 +25,7 @@ public class Config {
public boolean enableDynamicSkull = true;
public boolean enableTransparentSkin = true;
public boolean forceIgnoreHttpsCertificate = false;
public boolean forceLoadAllTextures = false;
public boolean forceLoadAllTextures = true;
public boolean enableCape = true;
public int threadPoolSize = 3;
/**
@@ -233,7 +229,7 @@ public class Config {
profiles.addAll(defaultProfiles);
}
}
profiles.sort((c1, c2) -> Integer.compare(c1.getPriority(), c2.getPriority()));
profiles.sort(Comparator.comparingInt(ICustomSkinLoaderPlugin.IDefaultProfile::getPriority));
List<SkinSiteProfile> loadlist = new ArrayList<>();
for (ICustomSkinLoaderPlugin.IDefaultProfile profile : profiles) {
@@ -30,14 +30,15 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
image = resetImageFormat(image, 22, 0, 46, 22);
return image;
}
} catch (IOException | NoSuchElementException ignored) { }
} catch (IOException | NoSuchElementException ignored) {
}
return null;
}
private int loaded = 0;
private double ratioX = -1;
private double ratioY = -1;
private ResourceLocation location;
private final ResourceLocation location;
private String type = null;
public FakeCapeBuffer(ResourceLocation location) {
@@ -47,11 +48,19 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
@Override
public FakeImage parseUserSkin(FakeImage image) {
if (image == null) return null;
this.image = image;
if (isOptiFineCape(image)) {
//OptiFine cape should be converted to standard cape
this.image = convertOptiFineCape(image);
//OptiFine cape contains elytra texture
//this.type = "elytra";//But its elytra texture doesn't work
} else {
this.image = image;
}
// When resource packs were changed, the elytra image needs to be reloaded, and here will be entered again
// The first cape which find elytra texture is outdated will reload it
if (this.loaded == loadedGlobal) {
elytraImage = loadElytra(image);
elytraImage = loadElytra(this.image);
}
this.loaded = loadedGlobal;
if (elytraImage != null) {
@@ -126,15 +135,16 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
/**
* Traverse every elytra pixel
* @param predicate the predicate with x and y
* @param returnValue if the condition flag equals the condition, then return this value
*
* @param predicate the predicate with x and y
* @param returnValue if the condition flag equals the condition, then return this value
* @param defaultReturnValue otherwise return this value
*/
private <R> R withElytraPixels(BiPredicate<Integer, Integer> predicate, R returnValue, R defaultReturnValue) {
int startX = (int) Math.ceil(22 * ratioX), endX = (int) Math.ceil(46 * ratioX);
int startY = (int) Math.ceil(0 * ratioY), endY = (int) Math.ceil(22 * ratioY);
int startY = (int) Math.ceil(0 * ratioY), endY = (int) Math.ceil(22 * ratioY);
int excludeX0 = (int) Math.ceil(24 * ratioX), excludeX1 = (int) Math.ceil(44 * ratioX);
int excludeY = (int) Math.ceil(2 * ratioY);
int excludeY = (int) Math.ceil(2 * ratioY);
for (int x = startX; x < endX; ++x) {
for (int y = startY; y < endY; ++y) {
if (y < excludeY && (x < excludeX0 || x >= excludeX1)) continue;
@@ -167,24 +177,27 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
/**
* Scale image
* @param image the image to scale.
*
* @param image the image to scale.
* @param closeOldImage whether close old image
* @param scaleWidth width enlargement ratio
* @param scaleHeight height enlargement ratio
* @param ratioX the ratio of 64 of the old image width
* @param ratioY the ratio of 32 of the old image height
* @param width the width after scaling.
* @param height the height after scaling.
* @param startX the x where start to copy.
* @param startY the y where start to copy.
* @param endX the x where end to copy.
* @param endY the y where end to copy.
* @param scaleWidth width enlargement ratio
* @param scaleHeight height enlargement ratio
* @param ratioX the ratio of 64 of the old image width
* @param ratioY the ratio of 32 of the old image height
* @param width the width after scaling.
* @param height the height after scaling.
* @param startX the x where start to copy.
* @param startY the y where start to copy.
* @param endX the x where end to copy.
* @param endY the y where end to copy.
* @return the image after scaling.
*/
private static FakeImage scaleImage(FakeImage image, boolean closeOldImage, double scaleWidth, double scaleHeight, double ratioX, double ratioY, int width, int height, int startX, int startY, int endX, int endY) {
FakeImage newImage = image.createImage(width, height);
startX = (int) (startX * ratioX); endX = (int) (endX * ratioX);
startY = (int) (startY * ratioY); endY = (int) (endY * ratioY);
startX = (int) (startX * ratioX);
endX = (int) (endX * ratioX);
startY = (int) (startY * ratioY);
endY = (int) (endY * ratioY);
int x0 = (int) (startX * scaleWidth), x1 = (int) ((startX + 1) * scaleWidth), dx0 = x1 - x0;
for (int x = startX; x < endX; ++x) {
@@ -196,12 +209,45 @@ public class FakeCapeBuffer extends FakeSkinBuffer {
newImage.setRGBA(x0 + dx, y0 + dy, rgba);
}
}
y0 = y1; y1 = (int) ((y + 2) * scaleHeight); dy0 = y1 - y0;
y0 = y1;
y1 = (int) ((y + 2) * scaleHeight);
dy0 = y1 - y0;
}
x0 = x1; x1 = (int) ((x + 2) * scaleWidth); dx0 = x1 - x0;
x0 = x1;
x1 = (int) ((x + 2) * scaleWidth);
dx0 = x1 - x0;
}
if (closeOldImage)
image.close();
return newImage;
}
/**
* Judge OptiFine cape.
* OptiFine cape is 46*22 or 92*44 pixels.
* <a href="https://optifine.net/capes/Notch.png">46*22 example</a>
* <a href="https://optifine.net/capes/OptiFineCape.png">92*44 example</a>
*
* @param image cape image
* @return true if is OptiFine cape
* @since 14.16
*/
private static boolean isOptiFineCape(FakeImage image) {
int ratio = image.getWidth() / 46;
return image.getHeight() == 22 * ratio && image.getWidth() == 46 * ratio;
}
/**
* Convert OptiFine cape to standard cape
*
* @param image OptiFine cape image
* @return standard cape image
* @since 14.16
*/
private static FakeImage convertOptiFineCape(FakeImage image) {
int ratio = image.getWidth() / 46;
FakeImage newImage = image.createImage(64 * ratio, 32 * ratio);
newImage.copyImageData(image);
return newImage;
}
}
@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import customskinloader.CustomSkinLoader;
import customskinloader.config.SkinSiteProfile;
@@ -14,6 +15,7 @@ import customskinloader.profile.UserProfile;
import customskinloader.utils.HttpRequestUtil;
import customskinloader.utils.HttpTextureUtil;
import customskinloader.utils.HttpUtil0;
import scala.actors.threadpool.Arrays;
public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
@@ -24,7 +26,7 @@ public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IPro
@Override
public List<IDefaultProfile> getDefaultProfiles() {
return Collections.singletonList(new LocalSkin(this));
return Lists.newArrayList(new LocalSkin(this), new OptiFineCape(this));
}
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
@@ -94,15 +96,36 @@ public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IPro
}
}
// // Minecrack could not load skin correctly
// public static class Minecrack extends LegacyLoader.DefaultProfile {
// public Minecrack(LegacyLoader loader) { super(loader); }
// @Override public String getName() { return "Minecrack"; }
// @Override public int getPriority() { return 600; }
// @Override public String getSkinRoot() { return "http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png"; }
// @Override public String getCapeRoot() { return "http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"; }
// @Override public String getElytraRoot() { return null; }
// }
public static class OptiFineCape extends LegacyLoader.DefaultProfile {
public OptiFineCape(LegacyLoader loader) {
super(loader);
}
@Override
public String getName() {
return "OptiFineCape";
}
@Override
public int getPriority() {
return 750;
}
@Override
public String getSkinRoot() {
return null;
}
@Override
public String getCapeRoot() {
return "https://optifine.net/capes/{USERNAME}.png";
}
@Override
public String getElytraRoot() {
return null;
}
}
public static final String USERNAME_PLACEHOLDER = "{USERNAME}";
public static final String UUID_PLACEHOLDER = "{UUID}";
+4 -3
View File
@@ -1,12 +1,12 @@
# CustomSkinLoader
![Version](https://img.shields.io/github/v/release/xfl03/MCCustomSkinLoader?label=&logo=V&labelColor=E1F5FE&color=5D87BF&style=for-the-badge)
[![Version](https://img.shields.io/github/v/release/xfl03/MCCustomSkinLoader?label=&logo=V&labelColor=E1F5FE&color=5D87BF&style=for-the-badge)](https://github.com/xfl03/MCCustomSkinLoader/tags)
[![CurseForge](https://cf.way2muchnoise.eu/short_CustomSkinLoader.svg?badge_style=for_the_badge)](https://www.curseforge.com/minecraft/mc-mods/customskinloader)
[![Modrinth](https://img.shields.io/modrinth/dt/idMHQ4n2?label=&logo=Modrinth&labelColor=white&color=00AF5C&style=for-the-badge)](https://modrinth.com/mod/customskinloader)
[![License](https://img.shields.io/github/license/xfl03/MCCustomSkinLoader?label=&logo=c&style=for-the-badge&color=A8B9CC&labelColor=455A64)](https://github.com/xfl03/MCCustomSkinLoader/blob/14-develop/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/xfl03/MCCustomSkinLoader/beta.yml?style=for-the-badge&label=&logo=Gradle&labelColor=388E3C)](https://github.com/xfl03/MCCustomSkinLoader/actions)
[![Star](https://img.shields.io/github/stars/xfl03/MCCustomSkinLoader?label=&logo=GitHub&labelColor=black&color=FAFAFA&style=for-the-badge)](https://github.com/xfl03/MCCustomSkinLoader/stargazers)
![Minecraft Version](https://img.shields.io/badge/Minecraft-1.19%20|%201.18%20|%201.17%20|%201.16%20|%201.15%20|%201.14%20|%201.13%20|%201.12%20|%201.11%20|%201.10%20|%201.9%20|%201.8-green?style=for-the-badge&labelColor=388E3C&color=8BC34A)
[![Minecraft Version](https://img.shields.io/badge/Minecraft-1.19%20|%201.18%20|%201.17%20|%201.16%20|%201.15%20|%201.14%20|%201.13%20|%201.12%20|%201.11%20|%201.10%20|%201.9%20|%201.8-green?style=for-the-badge&labelColor=388E3C&color=8BC34A)](https://github.com/xfl03/MCCustomSkinLoader)
## What's this?
Custom Skin Loader mod for Minecraft.
@@ -76,12 +76,13 @@ By using this mod, you can see correct avatar of players in Spectator Menu rathe
## Default Load List
- [Mojang](http://www.minecraft.net/) (MojangAPI)
- [LittleSkin](https://littleskin.cn/) (CustomSkinAPI)
- [Blessing Skin](http://skin.prinzeugen.net/) (CustomSkinAPI)
- [BlessingSkin](http://skin.prinzeugen.net/) (CustomSkinAPI)
- [ElyBy](http://docs.ely.by/) (ElyByAPI)
- SkinMe (UniSkinAPI)
- [TLauncher](https://tlauncher.org/) (ElyByAPI)
- LocalSkin (Legacy)
- [Glitchless](https://games.glitchless.ru/games/minecraft/)
- [OptiFineCape](https://optifine.net/home)
- [MinecraftCapes](https://minecraftcapes.net/)
If you want to apply to add other skin server to default list, please go to [issue](https://github.com/JLChnToZ/MCCustomSkinLoader/issues).