Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode head textures from hash part of skin URL #126

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
576 changes: 288 additions & 288 deletions src/main/java/xyz/nucleoid/extras/lobby/NEBlocks.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import xyz.nucleoid.extras.util.SkinEncoder;

public class DiceTaterBlock extends TinyPotatoBlock {
private static final int ROLLING_FACE = 0;
private static final int MAX_FACE = 6;
private static final int ROLLING_TICKS = 8;
private static final IntProperty FACE = IntProperty.of("face", ROLLING_FACE, MAX_FACE);
private static final String[] TEXTURES = {
"ewogICJ0aW1lc3RhbXAiIDogMTYzOTMzNzEwMTMwNSwKICAicHJvZmlsZUlkIiA6ICJjNjc3MGJjZWMzZjE0ODA3ODc4MTU0NWRhMGFmMDI1NCIsCiAgInByb2ZpbGVOYW1lIiA6ICJDVUNGTDE2IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2I0ZDQxMjY1NzRjM2RjYjk4NDc1NDdmMjlmMDRlNWRmNmNmMGZjNmQ4NjJiNGFiZTc1OTI2ZjM1OWQ1ZDZhOTEiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==",
"ewogICJ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iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2ExNGIwODA3OGJmOTdlODJiYjcwNTZiN2E0ZjgyMDYyNmE0MmZlNzIzOTVjYmJmMzNhMGVlYTcyYWYwZTdhMTIiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==",
"ewogICJ0aW1lc3RhbXAiIDogMTYzOTMzNzAyMjk5MSwKICAicHJvZmlsZUlkIiA6ICJiNjc3NTgwYzExYmU0ZjNiODI1OGM0YjBkNzNhNzg0ZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJPZmZpY2lhbGx5SksiLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWM0MGJmNzBmMTY0OGI3ZWU0MzhhNmEyMjkwNDIyOGFiNWZiYmQ0OTI2YWYzMGFlOGFkZTRkZjAxYjhkNzQxMyIsCiAgICAgICJtZXRhZGF0YSIgOiB7CiAgICAgICAgIm1vZGVsIiA6ICJzbGltIgogICAgICB9CiAgICB9CiAgfQp9",
SkinEncoder.encode("b4d4126574c3dcb9847547f29f04e5df6cf0fc6d862b4abe75926f359d5d6a91"),
SkinEncoder.encode("59b568e3d4eb5309e3660f4acfc04ecaa84825d2fe4a1312591d128b26859eaf"),
SkinEncoder.encode("753e1961ebc1de62ddb1316dba84348a7aa8c07c322b8f4e8f6f58f55cf28060"),
SkinEncoder.encode("57eb8f0e36d98818caee1067625d8eaa5d766f51d0f7fa75595a48f430345986"),
SkinEncoder.encode("613731d224be1fd184ff759a5e17a896c3c26d35057c6d9989f07ae7ffe47120"),
SkinEncoder.encode("a14b08078bf97e82bb7056b7a4f820626a42fe72395cbbf33a0eea72af0e7a12"),
SkinEncoder.encode("9c40bf70f1648b7ee438a6a22904228ab5fbbd4926af30ae8ade4df01b8d7413"),
};

public DiceTaterBlock(Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import xyz.nucleoid.extras.NucleoidExtras;
import xyz.nucleoid.extras.util.SkinEncoder;

public class LuckyTaterBlock extends TinyPotatoBlock {
private static final BooleanProperty COOLDOWN = BooleanProperty.of("cooldown");
Expand All @@ -40,7 +41,7 @@ public class LuckyTaterBlock extends TinyPotatoBlock {

public LuckyTaterBlock(Settings settings, String texture, String cooldownTexture) {
super(settings, (ParticleEffect) null, texture);
this.cooldownTexture = cooldownTexture;
this.cooldownTexture = SkinEncoder.encode(cooldownTexture);

this.setDefaultState(this.stateManager.getDefaultState().with(COOLDOWN, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import xyz.nucleoid.extras.util.SkinEncoder;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,7 +38,7 @@ public class TinyPotatoBlock extends Block implements PolymerHeadBlock {
public TinyPotatoBlock(Settings settings, ParticleEffect particleEffect, String texture, int particleRate) {
super(settings);
this.particleEffect = particleEffect;
this.texture = texture;
this.texture = SkinEncoder.encode(texture);
this.particleRate = particleRate;

TATERS.add(this);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/xyz/nucleoid/extras/util/PagedGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static DisplayElement nextPage(PagedGui gui) {
new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.DARK_GRAY))
.hideFlags()
.setSkullOwner("ewogICJ0aW1lc3RhbXAiIDogMTY0MDYxNjExMDQ4OCwKICAicHJvZmlsZUlkIiA6ICIxZjEyNTNhYTVkYTQ0ZjU5YWU1YWI1NmFhZjRlNTYxNyIsCiAgInByb2ZpbGVOYW1lIiA6ICJOb3RNaUt5IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzdlNTc3MjBhNDg3OGM4YmNhYjBlOWM5YzQ3ZDllNTUxMjhjY2Q3N2JhMzQ0NWE1NGE5MWUzZTFlMWEyNzM1NmUiLAogICAgICAibWV0YWRhdGEiIDogewogICAgICAgICJtb2RlbCIgOiAic2xpbSIKICAgICAgfQogICAgfQogIH0KfQ==")
.setSkullOwner(SkinEncoder.encode("7e57720a4878c8bcab0e9c9c47d9e55128ccd77ba3445a54a91e3e1e1a27356e"))
);
}
}
Expand All @@ -159,7 +159,7 @@ public static DisplayElement previousPage(PagedGui gui) {
new GuiElementBuilder(Items.PLAYER_HEAD)
.setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.DARK_GRAY))
.hideFlags()
.setSkullOwner("ewogICJ0aW1lc3RhbXAiIDogMTY0MDYxNjE5MjE0MiwKICAicHJvZmlsZUlkIiA6ICJmMjc0YzRkNjI1MDQ0ZTQxOGVmYmYwNmM3NWIyMDIxMyIsCiAgInByb2ZpbGVOYW1lIiA6ICJIeXBpZ3NlbCIsCiAgInNpZ25hdHVyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS81MDgyMGY3NmUzZTA0MWM3NWY3NmQwZjMwMTIzMmJkZjQ4MzIxYjUzNGZlNmE4NTljY2I4NzNkMjk4MWE5NjIzIiwKICAgICAgIm1ldGFkYXRhIiA6IHsKICAgICAgICAibW9kZWwiIDogInNsaW0iCiAgICAgIH0KICAgIH0KICB9Cn0=")
.setSkullOwner(SkinEncoder.encode("50820f76e3e041c75f76d0f301232bdf48321b534fe6a859ccb873d2981a9623"))
);
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/xyz/nucleoid/extras/util/SkinEncoder.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on what @Patbox thinks, it might make more sense for this portion to be in Polymer instead.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package xyz.nucleoid.extras.util;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class SkinEncoder {
/**
* @param hash a hash part of the skin URL after <a href="http://textures.minecraft.net/texture/">http://textures.minecraft.net/texture/</a>
* @return Base64-encoded skin texture for player heads
*/
public static String encode(String hash) {
if (hash == null) return null;
return encodeUrl("http://textures.minecraft.net/texture/" + hash);
}

/**
* @return Base64-encoded skin texture for player heads
*/
public static String encodeUrl(String url) {
if (url == null) return null;
var value = """
{"textures":{"SKIN":{"url":"%s"}}}""".formatted(url);
return new String(Base64.getEncoder().encode(value.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
}
}