From 042acf39cc67e9bba61b6804e730de97ff44db75 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Mon, 14 Jun 2021 15:25:15 +0200 Subject: [PATCH] Fix skin saving --- gradle.properties | 2 +- .../samo_lego/fabrictailor/casts/TailoredPlayer.java | 6 +++++- .../samo_lego/fabrictailor/client/ClientTailor.java | 4 ++-- .../fabrictailor/client/SkinChangeScreen.java | 10 +++++----- .../samo_lego/fabrictailor/command/SkinCommand.java | 5 +++-- .../fabrictailor/mixin/MixinPlayerManager.java | 4 +--- .../mixin/ServerPlayerEntityMixin_TailoredPlayer.java | 2 ++ 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7ad786d..df5ae20 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.11.3 fabric_version=0.34.9+1.17 # Mod Properties -mod_version = 1.5.1 +mod_version = 1.5.2 maven_group = org.samo_lego archives_base_name = fabrictailor diff --git a/src/main/java/org/samo_lego/fabrictailor/casts/TailoredPlayer.java b/src/main/java/org/samo_lego/fabrictailor/casts/TailoredPlayer.java index d21d2b4..2f8bc86 100644 --- a/src/main/java/org/samo_lego/fabrictailor/casts/TailoredPlayer.java +++ b/src/main/java/org/samo_lego/fabrictailor/casts/TailoredPlayer.java @@ -1,5 +1,7 @@ package org.samo_lego.fabrictailor.casts; +import org.jetbrains.annotations.Nullable; + /** * Includes additional methods for skin changes. */ @@ -14,7 +16,7 @@ public interface TailoredPlayer { * * @param value skin texture value * @param signature skin texture signature - * @param reload + * @param reload whether to send packets around for skin reload * @return true if it was successful, otherwise false */ boolean setSkin(String value, String signature, boolean reload); @@ -24,6 +26,7 @@ public interface TailoredPlayer { * * @return skin value as string */ + @Nullable String getSkinValue(); /** @@ -31,5 +34,6 @@ public interface TailoredPlayer { * * @return skin signature as string */ + @Nullable String getSkinSignature(); } diff --git a/src/main/java/org/samo_lego/fabrictailor/client/ClientTailor.java b/src/main/java/org/samo_lego/fabrictailor/client/ClientTailor.java index ab7960d..b1dae60 100644 --- a/src/main/java/org/samo_lego/fabrictailor/client/ClientTailor.java +++ b/src/main/java/org/samo_lego/fabrictailor/client/ClientTailor.java @@ -19,14 +19,14 @@ public class ClientTailor implements ClientModInitializer { public static KeyBinding keyBinding; - private static final SkinChangeScreen SKIN_CHANGE_SCREEN = new SkinChangeScreen(); + protected static final SkinChangeScreen SKIN_CHANGE_SCREEN = new SkinChangeScreen(); @Override public void onInitializeClient() { keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( "key.fabrictailor.toggle_skin_gui", InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_K, // K for opening th window + GLFW.GLFW_KEY_K, // K for opening the window "category.fabrictailor.skin_category" )); diff --git a/src/main/java/org/samo_lego/fabrictailor/client/SkinChangeScreen.java b/src/main/java/org/samo_lego/fabrictailor/client/SkinChangeScreen.java index dba4e7c..53c25d0 100644 --- a/src/main/java/org/samo_lego/fabrictailor/client/SkinChangeScreen.java +++ b/src/main/java/org/samo_lego/fabrictailor/client/SkinChangeScreen.java @@ -73,7 +73,7 @@ protected void init() { this.renderTooltip(matrixStack, new TranslatableText("hint.fabrictailor.dragAndDrop"), width / 2 - 100, height / 2 + 10); } ); - this.addDrawable(openExplorerButton); + this.addDrawableChild(openExplorerButton); // Checkbox for slim skin model this.skinModelCheckbox = new CheckboxWidget( @@ -84,7 +84,7 @@ protected void init() { new TranslatableText("button.fabrictailor.use_slim"), false ); - this.addDrawable(skinModelCheckbox); + this.addDrawableChild(skinModelCheckbox); // Both should be hidden at first (default tab is "player") this.openExplorerButton.visible = false; @@ -100,7 +100,7 @@ protected void init() { addSelectableChild(skinInput); // "Set skin" button - this.addDrawable( + this.addDrawableChild( new ButtonWidget( width / 2, height / 2 + 30, @@ -121,7 +121,7 @@ protected void init() { ) ); - this.addDrawable( + this.addDrawableChild( new ButtonWidget( width / 2 - BUTTON_WIDTH - 2, height - BUTTON_HEIGHT - verticalSpacing, BUTTON_WIDTH, @@ -136,7 +136,7 @@ protected void init() { ); // "Cancel" button which closes the screen - this.addDrawable( + this.addDrawableChild( new ButtonWidget( width / 2 + 2, height - BUTTON_HEIGHT - verticalSpacing, BUTTON_WIDTH, diff --git a/src/main/java/org/samo_lego/fabrictailor/command/SkinCommand.java b/src/main/java/org/samo_lego/fabrictailor/command/SkinCommand.java index 548dbd8..7ea3ebc 100644 --- a/src/main/java/org/samo_lego/fabrictailor/command/SkinCommand.java +++ b/src/main/java/org/samo_lego/fabrictailor/command/SkinCommand.java @@ -238,8 +238,7 @@ public static int fetchSkinByName(ServerCommandSource src, String playername, bo THREADPOOL.submit(() -> { // If user has no skin data - // Getting skin data from ely.by api, since it can be used with usernames - // it also includes mojang skins + // Try to get Mojang skin first GameProfile profile = new GameProfile(null, playername); SkullBlockEntity.loadProperties(profile, gameProfile -> { @@ -260,6 +259,8 @@ public static int fetchSkinByName(ServerCommandSource src, String playername, bo ); } } else { + // Getting skin data from ely.by api, since it can be used with usernames + // it also includes mojang skins String reply = null; try { reply = urlRequest(new URL(String.format("http://skinsystem.ely.by/textures/signed/%s.png?proxy=true", playername)), null); diff --git a/src/main/java/org/samo_lego/fabrictailor/mixin/MixinPlayerManager.java b/src/main/java/org/samo_lego/fabrictailor/mixin/MixinPlayerManager.java index 544b729..51d8c2d 100644 --- a/src/main/java/org/samo_lego/fabrictailor/mixin/MixinPlayerManager.java +++ b/src/main/java/org/samo_lego/fabrictailor/mixin/MixinPlayerManager.java @@ -18,9 +18,7 @@ public abstract class MixinPlayerManager { private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity player, CallbackInfo ci) throws CommandSyntaxException { String value = ((TailoredPlayer) player).getSkinValue(); String signature = ((TailoredPlayer) player).getSkinSignature(); - if(value != null && signature != null) - ((TailoredPlayer) player).setSkin(value, signature, false); - else + if(value == null || signature == null) // Trying to fetch skin by playername fetchSkinByName(player.getCommandSource(), player.getGameProfile().getName(), false); } diff --git a/src/main/java/org/samo_lego/fabrictailor/mixin/ServerPlayerEntityMixin_TailoredPlayer.java b/src/main/java/org/samo_lego/fabrictailor/mixin/ServerPlayerEntityMixin_TailoredPlayer.java index ef13cd4..4041f23 100644 --- a/src/main/java/org/samo_lego/fabrictailor/mixin/ServerPlayerEntityMixin_TailoredPlayer.java +++ b/src/main/java/org/samo_lego/fabrictailor/mixin/ServerPlayerEntityMixin_TailoredPlayer.java @@ -154,6 +154,8 @@ private void readCustomDataFromNbt(NbtCompound tag, CallbackInfo ci) { if(skinDataTag != null) { this.skinValue = skinDataTag.contains("value") ? skinDataTag.getString("value") : null; this.skinSignature = skinDataTag.contains("signature") ? skinDataTag.getString("signature") : null; + + this.setSkin(this.skinValue, this.skinSignature, false); } } }