Skip to content

Commit

Permalink
Fix hd skins
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed May 8, 2024
1 parent cfe6cc6 commit 14f0b04
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {

// Carpet
modCompileOnly("com.github.gnembon:fabric-carpet:${project.carpet_core_version}")
modCompileOnly('com.github.samolego.Taterzens:taterzens-fabric:1.11.4-beta3')
modCompileOnly('com.github.samolego.Taterzens:taterzens-fabric:1.11.6')
}

processResources {
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdk:
- openjdk17
before_install:
- sdk install java 17.0.1-open
- sdk use java 17.0.1-open
- sdk install java 21.0.1-open
- sdk use java 21.0.1-open
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.advancements.AdvancementsScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import org.samo_lego.fabrictailor.casts.TailoredPlayer;
Expand All @@ -24,6 +25,7 @@
import org.samo_lego.fabrictailor.client.screen.tabs.SkinTabType;
import org.samo_lego.fabrictailor.client.screen.tabs.UrlSkinTab;
import org.samo_lego.fabrictailor.mixin.client.AAbstractClientPlayer;
import org.samo_lego.fabrictailor.network.payload.DefaultSkinPayload;
import org.samo_lego.fabrictailor.util.TextTranslations;

import java.io.File;
Expand Down Expand Up @@ -139,7 +141,9 @@ protected void init() {
this.addRenderableWidget(
Button.builder(TextTranslations.create("button.fabrictailor.set_default_skin"),
onClick -> {
minecraft.player.connection.sendUnsignedCommand("skin default");
var profile = ((AAbstractClientPlayer) this.minecraft.player).ft_getPlayerInfo().getProfile();
var payload = new DefaultSkinPayload(profile.getProperties().get(TailoredPlayer.PROPERTY_TEXTURES).iterator().next());
ClientPlayNetworking.send(payload);
this.onClose();
})
.pos(width / 2 - BUTTON_WIDTH / 2 - 1, buttonY)
Expand Down Expand Up @@ -236,16 +240,16 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
float yHeadRotO = player.yHeadRotO;
float yHeadRot = player.yHeadRot;

player.yBodyRot = f * 20.0f;
player.setYRot(f * 40.0f);
player.setXRot(-g * 20.0f);
player.yHeadRot = player.getYRot();
player.yHeadRotO = player.getYRot();
player.yBodyRot += 180.0f;
player.setYRot(yRot + 180f);
player.setXRot(xRot + 180.0f);
player.yHeadRot += 180.0f;
player.yHeadRotO += 180.0f;


int x = this.startX + 24;
int y = this.startY - 76;
InventoryScreen.renderEntityInInventoryFollowsMouse(guiGraphics, x, y, x + 75, y + 208, 48, 1.0f, mouseX + 2, mouseY - 16, this.minecraft.player);
InventoryScreen.renderEntityInInventoryFollowsMouse(guiGraphics, x, y, x + 75, y + 208, 48, 1.0f, -mouseX - 2, mouseY - 16, this.minecraft.player);

player.yBodyRot = yBodyRot;
player.setYRot(yRot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Optional<CustomPacketPayload> getSkinChangePacket(LocalPlayer player, Str
}

// Check if tld is allowed
String tld = InternetDomainName.from(skinUrl.getHost()).topPrivateDomain().toString();
String tld = InternetDomainName.from(skinUrl.getHost()).topDomainUnderRegistrySuffix().toString();
if (!config.allowedTextureDomains.contains(tld)) {
// Redirect to duckduckgo
// e.g. convert https://image.com/image.png to https://external-content.duckduckgo.com/iu/?u=https://image.com/image.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static void setSkin(ServerPlayer player, Supplier<Property> skinProvider)
THREADPOOL.submit(() -> {
Property skinData = skinProvider.get();

if(skinData == null) {
if (skinData == null) {
player.displayClientMessage(SKIN_SET_ERROR, false);
} else {
if (!TATERZENS_LOADED || !TaterzenSkins.setTaterzenSkin(player, skinData)) {
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/org/samo_lego/fabrictailor/util/SkinFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand All @@ -31,9 +32,9 @@ public class SkinFetcher {
public static Property setSkinFromFile(String skinFilePath, boolean useSlim) {
File skinFile = new File(skinFilePath);
try (FileInputStream input = new FileInputStream(skinFile)) {
if(input.read() == 137) {
if (input.read() == 137) {
try {
String reply = urlRequest(new URL("https://api.mineskin.org/generate/upload?model=" + (useSlim ? "slim" : "steve")), false, skinFile);
String reply = urlRequest(URI.create("https://api.mineskin.org/generate/upload?model=" + (useSlim ? "slim" : "steve")).toURL(), false, skinFile);
return getSkinFromReply(reply);
} catch (IOException e) {
// Error uploading
Expand All @@ -56,7 +57,7 @@ public static Property setSkinFromFile(String skinFilePath, boolean useSlim) {
@Nullable
public static Property fetchSkinByUrl(String skinUrl, boolean useSlim) {
try {
URL url = new URL(String.format("https://api.mineskin.org/generate/url?url=%s&model=%s", URLEncoder.encode(skinUrl, StandardCharsets.UTF_8), useSlim ? "slim" : "steve"));
URL url = URI.create(String.format("https://api.mineskin.org/generate/url?url=%s&model=%s", URLEncoder.encode(skinUrl, StandardCharsets.UTF_8), useSlim ? "slim" : "steve")).toURL();
String reply = urlRequest(url, false, null);
return getSkinFromReply(reply);
} catch (IOException e) {
Expand All @@ -74,13 +75,13 @@ public static Property fetchSkinByUrl(String skinUrl, boolean useSlim) {
@Nullable
public static Property fetchSkinByName(String playername) {
try {
String reply = urlRequest(new URL("https://api.mojang.com/users/profiles/minecraft/" + playername), true, null);
String reply = urlRequest(URI.create("https://api.mojang.com/users/profiles/minecraft/" + playername).toURL(), true, null);

if(reply == null || !reply.contains("id")) {
reply = urlRequest(new URL(String.format("http://skinsystem.ely.by/textures/signed/%s.png?proxy=true", playername)), false, null);
if (reply == null || !reply.contains("id")) {
reply = urlRequest(URI.create(String.format("http://skinsystem.ely.by/textures/signed/%s.png?proxy=true", playername)).toURL(), false, null);
} else {
String uuid = JsonParser.parseString(reply).getAsJsonObject().get("id").getAsString();
reply = urlRequest(new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"), true, null);
reply = urlRequest(URI.create("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false").toURL(), true, null);
}
return getSkinFromReply(reply);
} catch (IOException e) {
Expand Down Expand Up @@ -123,12 +124,13 @@ private static String urlRequest(URL url, boolean useGetMethod, @Nullable File i

String reply = null;

if(connection instanceof HttpsURLConnection httpsConnection) {
if (connection instanceof HttpsURLConnection httpsConnection) {
httpsConnection.setUseCaches(false);
httpsConnection.setDoOutput(true);
httpsConnection.setDoInput(true);
httpsConnection.setRequestMethod(useGetMethod ? "GET" : "POST");
if(image != null) {
if (image != null) {
// Do a POST request with image
String boundary = UUID.randomUUID().toString();
httpsConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
httpsConnection.setRequestProperty("User-Agent", "User-Agent");
Expand All @@ -151,8 +153,8 @@ private static String urlRequest(URL url, boolean useGetMethod, @Nullable File i
writer.append(LINE);
writer.flush();

byte[] fileBytes = Files.readAllBytes(image.toPath());
outputStream.write(fileBytes, 0, fileBytes.length);
byte[] fileBytes = Files.readAllBytes(image.toPath());
outputStream.write(fileBytes, 0, fileBytes.length);

outputStream.flush();
writer.append(LINE);
Expand All @@ -161,11 +163,12 @@ private static String urlRequest(URL url, boolean useGetMethod, @Nullable File i
writer.append("--").append(boundary).append("--").append(LINE);
writer.close();
}
if(httpsConnection.getResponseCode() == HttpURLConnection.HTTP_OK)

if (httpsConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
reply = getContent(connection);
}
httpsConnection.disconnect();
}
else {
} else {
reply = getContent(connection);
}
return reply;
Expand All @@ -186,9 +189,9 @@ private static String getContent(URLConnection connection) throws IOException {
Scanner scanner = new Scanner(isr)
) {
StringBuilder reply = new StringBuilder();
while(scanner.hasNextLine()) {
while (scanner.hasNextLine()) {
String line = scanner.next();
if(line.trim().isEmpty())
if (line.trim().isEmpty())
continue;
reply.append(line);
}
Expand Down
16 changes: 13 additions & 3 deletions src/test/java/org/samo_lego/fabrictailor/testmod/TailorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.client.gui.components.tabs.Tab;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import org.samo_lego.fabrictailor.client.screen.tabs.CapeTab;
import org.samo_lego.fabrictailor.client.screen.tabs.UrlSkinTab;
import org.samo_lego.fabrictailor.command.SkinCommand;
import org.samo_lego.fabrictailor.util.SkinFetcher;


public class TailorTest implements ModInitializer {
public class TailorTest implements ModInitializer, ClientModInitializer {
@Override
public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
this.serversideSkinCmd(dispatcher);
});
}


@Override
public void onInitializeClient() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, environment) -> {
this.hdSkinCmd(dispatcher);
this.capeCmd(dispatcher);
Expand All @@ -33,6 +41,8 @@ private void hdSkinCmd(CommandDispatcher<FabricClientCommandSource> dispatcher)
}

private int hdSkinCmd(CommandContext<FabricClientCommandSource> context) {
new UrlSkinTab().getSkinChangePacket(context.getSource().getPlayer(), "https://raw.githubusercontent.com/ClassicFaithful/32x-Jappa/1.20.4/assets/minecraft/textures/entity/player/wide/steve.png", false)
.ifPresent(ClientPlayNetworking::send);
return 0;
}

Expand All @@ -44,7 +54,7 @@ private int capeCmd(CommandContext<FabricClientCommandSource> context) {
LocalPlayer player = context.getSource().getPlayer();

new CapeTab().getSkinChangePacket(player, "https://static.wikia.nocookie.net/minecraft_gamepedia/images/6/65/Millionth_Customer_Cape_%28texture%29.png", false)
.ifPresent(packet -> ClientPlayNetworking.send(packet.getFirst(), packet.getSecond()));
.ifPresent(ClientPlayNetworking::send);
return 0;
}

Expand All @@ -55,7 +65,7 @@ private void serversideSkinCmd(CommandDispatcher<CommandSourceStack> dispatcher)
return 1;
}))
.then(Commands.literal("url").executes(ctx -> {
SkinCommand.setSkin(ctx.getSource().getPlayer(), () -> SkinFetcher.fetchSkinByUrl("https://skinmc.net/en/api/v1/skins/uuid/853c80ef-3c37-49fd-aa49-938b674adae6", false));
SkinCommand.setSkin(ctx.getSource().getPlayer(), () -> SkinFetcher.fetchSkinByUrl("https://textures.minecraft.net/texture/2736a21f4f7ccbc791ca44527445b2bea3d5bedd11cff16bf1d4d08044d51fc6", false));
return 1;
})));

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"entrypoints": {
"main": [
"org.samo_lego.fabrictailor.testmod.TailorTest"
],
"client": [
"org.samo_lego.fabrictailor.testmod.TailorTest"
]
},
"mixins": [ ],
Expand Down

0 comments on commit 14f0b04

Please sign in to comment.