Skip to content

Commit

Permalink
Fix skin saving
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jun 14, 2021
1 parent b3f2f48 commit 042acf3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.samo_lego.fabrictailor.casts;

import org.jetbrains.annotations.Nullable;

/**
* Includes additional methods for skin changes.
*/
Expand All @@ -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);
Expand All @@ -24,12 +26,14 @@ public interface TailoredPlayer {
*
* @return skin value as string
*/
@Nullable
String getSkinValue();

/**
* Gets player's skin signature.
*
* @return skin signature as string
*/
@Nullable
String getSkinSignature();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -100,7 +100,7 @@ protected void init() {
addSelectableChild(skinInput);

// "Set skin" button
this.addDrawable(
this.addDrawableChild(
new ButtonWidget(
width / 2,
height / 2 + 30,
Expand All @@ -121,7 +121,7 @@ protected void init() {
)
);

this.addDrawable(
this.addDrawableChild(
new ButtonWidget(
width / 2 - BUTTON_WIDTH - 2, height - BUTTON_HEIGHT - verticalSpacing,
BUTTON_WIDTH,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 042acf3

Please sign in to comment.