Skip to content

Commit

Permalink
1.21.3 -> 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Dec 12, 2024
1 parent 90213f6 commit d10ebaa
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 210 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.8
fabric_version=0.106.1+1.21.3
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.2
loader_version=0.16.9
fabric_version=0.111.0+1.21.4

# Mod Properties
group=com.minelittlepony
Expand All @@ -19,5 +19,5 @@ org.gradle.daemon=false
modrinth_project_id=FzE9gshV

# Dependencies
modmenu_version=12.0.0-beta.1
kirin_version=1.20.1+1.21.3
modmenu_version=13.0.0-beta.1
kirin_version=1.20.3+1.21.4
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.minelittlepony.hdskins.client.gui.filesystem.FileDialogs;
import com.minelittlepony.hdskins.client.gui.filesystem.FileSystemUtil;
import com.minelittlepony.hdskins.client.gui.filesystem.WatchedFile;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTexture;
import com.minelittlepony.hdskins.client.gui.player.skins.ServerPlayerSkins.RemoteTexture;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTextureDownloader;
import com.minelittlepony.hdskins.profile.SkinType;

import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -152,12 +153,13 @@ public void openSavePNG(SkinUploader uploader, String title, String filename) {
pickingInProgress = false;

if (success) {
previewer.getRemote().getSkins().get(previewer.getActiveSkinType()).texture().ifPresent(texture -> {
RemoteTexture texture = previewer.getRemote().getSkins().get(previewer.getActiveSkinType());
if (texture.isReady() && texture.texture() != null) {
try {
Files.deleteIfExists(file);
} catch (IOException ignored) { }

try (InputStream response = texture.openStream()) {
try (InputStream response = texture.texture().openStream()) {
Files.copy(response, file);

MinecraftClient.getInstance().setScreen(new ConfirmationScreen(MinecraftClient.getInstance().currentScreen, Text.translatable("hdskins.save.completed"), () -> {
Expand All @@ -166,7 +168,7 @@ public void openSavePNG(SkinUploader uploader, String title, String filename) {
} catch (IOException e) {
LogManager.getLogger().error("Failed to save remote skin.", e);
}
});
}
}
}).launch();
}
Expand Down Expand Up @@ -209,10 +211,10 @@ protected Text acceptsSkinDimensions(NativeImage img) {
int h = img.getHeight();

if (previewer.getActiveSkinType().isVanilla()) {
if (!HDPlayerSkinTexture.isPowerOfTwo(w)) {
if (!HDPlayerSkinTextureDownloader.isPowerOfTwo(w)) {
return ERR_INVALID_POWER_OF_TWO;
}
if (!HDPlayerSkinTexture.isValidShape(w, h)) {
if (!HDPlayerSkinTextureDownloader.isValidShape(w, h)) {
return ERR_INVALID_SHAPE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ public void render(DummyPlayer player, DrawContext context, int mouseX, int mous

bounds.translate(matrices);
context.fill(0, frameWidth, bounds.width, 0, 0xA0000000);
matrices.translate(getScrollOffset(), 0, 200);

int index = (int)(mouseX - (bounds.left + getScrollOffset())) / frameWidth;

boolean hovered = bounds.contains(mouseX, mouseY);

context.enableScissor(bounds.left, bounds.top, bounds.right(), bounds.bottom());
context.enableScissor(0, 0, bounds.width, bounds.height);
matrices.translate(getScrollOffset(), 0, 200);

if (hovered && index < skins.size()) {
context.fill(index * frameWidth, 0, (index + 1) * frameWidth, frameWidth, 0xA0AAAAAA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.chunk.ChunkBuilder;
Expand Down Expand Up @@ -45,7 +44,6 @@ public void render(
boolean renderBlockOutline,
Camera camera,
GameRenderer gameRenderer,
LightmapTextureManager lightmapTextureManager,
Matrix4f positionMatrix,
Matrix4f projectionMatrix
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package com.minelittlepony.hdskins.client.gui.player.skins;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.*;

import com.minelittlepony.hdskins.client.HDSkins;
import com.minelittlepony.hdskins.client.VanillaModels;
import com.minelittlepony.hdskins.client.gui.player.skins.PlayerSkins.Posture.SkinVariant;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTexture;
import com.minelittlepony.hdskins.client.resources.Texture;
import com.minelittlepony.hdskins.client.resources.TextureLoader;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTextureDownloader;
import com.minelittlepony.hdskins.profile.SkinType;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.util.Identifier;

public class LocalPlayerSkins extends PlayerSkins<LocalPlayerSkins.LocalTexture> {
Expand Down Expand Up @@ -46,7 +40,7 @@ public class LocalTexture implements PlayerSkins.PlayerSkin {
private final Identifier id;
private final Supplier<Identifier> defaultTexture;

private Optional<Texture.MemoryTexture> local = Optional.empty();
private Optional<CompletableFuture<Identifier>> local = Optional.empty();

public LocalTexture(SkinType type, Supplier<Identifier> blank) {
this.type = type;
Expand All @@ -60,26 +54,18 @@ public Identifier getId() {
}

public void setLocal(Path file) throws IOException {
local.ifPresent(AbstractTexture::close);

try (InputStream input = Files.newInputStream(file)) {
Texture.MemoryTexture image = new Texture.MemoryTexture(
type != SkinType.SKIN
? NativeImage.read(input)
: HDPlayerSkinTexture.filterPlayerSkins(NativeImage.read(input), TextureLoader.Exclusion.NULL), id);
MinecraftClient.getInstance().getTextureManager().registerTexture(id, image);
local = Optional.of(image);
}
local.ifPresent(l -> l.cancel(true));
local = Optional.of(HDPlayerSkinTextureDownloader.downloadAndRegisterTexture(id, file, "", type));
}

@Override
public boolean isReady() {
return local.filter(Texture::isLoaded).isPresent();
return local.filter(i -> i.isDone() && !i.isCancelled() && !i.isCompletedExceptionally()).isPresent();
}

@Override
public void close() {
local.ifPresent(AbstractTexture::close);
local.ifPresent(l -> l.cancel(true));
local = Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import com.minelittlepony.hdskins.client.gui.player.skins.ServerPlayerSkins.RemoteTexture;
import com.minelittlepony.hdskins.client.resources.DynamicTextures;
import com.minelittlepony.hdskins.client.resources.EquipmentList.EquipmentSet;
import com.minelittlepony.hdskins.client.resources.Texture;
import com.minelittlepony.hdskins.client.resources.TextureLoader;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTextureDownloader;
import com.minelittlepony.hdskins.client.resources.TextureLoader.Exclusion;
import com.minelittlepony.hdskins.profile.SkinType;
import com.minelittlepony.hdskins.server.SkinServer;
Expand Down Expand Up @@ -40,13 +39,16 @@ public SkinType getType() {
@Override
protected ServerPlayerSkins.RemoteTexture createTexture(SkinType type, Supplier<Identifier> blank) {
if (type == this.type) {
String model = skin.getModel();
String uri = skin.getUri();
String hash = String.valueOf(uri.hashCode());

Identifier id = HDSkins.id(String.format("dynamic/%s/%s", type.getId().getPath(), hash));

return new RemoteTexture(blank, Optional.of(TextureLoader.loadTexture(id, Texture.UriTexture.create(id, DynamicTextures.createTempFile(hash), uri, type, model, blank.get(), null))), skin.isActive());
return new RemoteTexture(blank,
new DynamicTextures.Result(uri, HDPlayerSkinTextureDownloader.downloadAndRegisterTexture(
HDSkins.id(String.format("dynamic/%s/%s", type.getId().getPath(), hash)),
DynamicTextures.createTempFile(hash),
uri, type
)),
skin.isActive()
);
}
return fallback.get(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.*;
import java.util.function.*;

import org.jetbrains.annotations.Nullable;

import com.minelittlepony.hdskins.client.resources.DynamicTextures;
import com.minelittlepony.hdskins.client.resources.Texture;
import com.minelittlepony.hdskins.profile.SkinCallback;
import com.minelittlepony.hdskins.profile.SkinType;
import com.minelittlepony.hdskins.server.SkinServer;
Expand Down Expand Up @@ -36,7 +37,7 @@ public void loadTextures(TexturePayload payload, SkinCallback loadCallback) {

@Override
protected RemoteTexture createTexture(SkinType type, Supplier<Identifier> blank) {
return new RemoteTexture(blank, textureManager.flatMap(tpm -> tpm.loadTexture(type, blank.get())), true);
return new RemoteTexture(blank, textureManager.flatMap(tpm -> tpm.loadTexture(type, blank.get())).orElse(null), true);
}

public List<PreviousServerPlayerSkins> getProfileSkins(SkinType type) {
Expand Down Expand Up @@ -69,23 +70,27 @@ protected boolean isProvided(SkinType type) {

public record RemoteTexture (
Supplier<Identifier> blank,
Optional<Texture.UriTexture> texture,
@Nullable DynamicTextures.Result texture,
boolean active
) implements PlayerSkins.PlayerSkin {

@Override
public Identifier getId() {
return texture.filter(Texture::isLoaded).map(Texture::getId).orElseGet(blank);
if (texture == null || texture.id().isCancelled() || texture.id().isCompletedExceptionally() || !texture.id().isDone()) {
return blank.get();
}
return texture.id().getNow(blank.get());
}

@Override
public boolean isReady() {
return texture.filter(Texture::isLoaded).isPresent();
return texture != null && texture.id().isDone() && !texture.id().isCancelled();
}

@Override
public void close() {
texture.ifPresent(Texture.UriTexture::close);
if (texture != null) {
texture.id().cancel(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import com.google.common.hash.Hashing;
import com.minelittlepony.common.util.GamePaths;
import com.minelittlepony.hdskins.client.HDSkins;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTexture;
import com.minelittlepony.hdskins.client.resources.TextureLoader;
import com.minelittlepony.hdskins.client.resources.HDPlayerSkinTextureDownloader;
import com.minelittlepony.hdskins.profile.SkinType;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.util.Identifier;

class FileStore {
Expand All @@ -39,14 +37,7 @@ private CompletableFuture<Identifier> store(SkinType type, MinecraftProfileTextu
String hash = Hashing.sha1().hashUnencodedChars(texture.getHash()).toString();
Identifier id = HDSkins.id(type.getPathName() + "/" + hash);
Path path = getHDSkinsCache().resolve(type.getPathName()).resolve(hash.length() > 2 ? hash.substring(0, 2) : "xx").resolve(hash);
CompletableFuture<Identifier> future = new CompletableFuture<>();
TextureLoader.loadTexture(id, new HDPlayerSkinTexture(
path.toFile(),
texture.getUrl(),
type,
DefaultSkinHelper.getTexture(),
() -> future.complete(id)));
return future;
return HDPlayerSkinTextureDownloader.downloadAndRegisterTexture(id, path, texture.getUrl(), type);
}

private Path getHDSkinsCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import net.minecraft.util.Identifier;

import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import org.jetbrains.annotations.Nullable;

Expand All @@ -32,22 +35,36 @@ public Optional<MinecraftProfileTexture> getTextureMetadata(SkinType type) {
return Optional.ofNullable(payload.textures().getOrDefault(type, null));
}

public Optional<Texture.UriTexture> loadTexture(SkinType type, Identifier def) {
public Optional<Result> loadTexture(SkinType type, Identifier def) {
return getTextureMetadata(type).map(texture -> {
Identifier id = HDSkins.id(String.format("dynamic/%s/%s", type.getId().getPath(), texture.getHash()));
return TextureLoader.loadTexture(id, Texture.UriTexture.create(id, createTempFile(texture.getHash()), texture.getUrl(), type, texture.getMetadata("model"), def, () -> {
loadCallback.onSkinAvailable(type, id, texture);
String uri = texture.getUrl();
return new Result(uri, HDPlayerSkinTextureDownloader.downloadAndRegisterTexture(id, createTempFile(texture.getHash()), uri, type).handle((u, throwable) -> {
if (u != null) {
loadCallback.onSkinAvailable(type, u, texture);
}
return u == null ? def : u;
}));
});
}

@Nullable
public static File createTempFile(String filename) {
public static Path createTempFile(String filename) {
try {
File f = Files.createTempFile(filename, "skin-preview").toFile();
f.delete();
Path f = Files.createTempFile(filename, "skin-preview");
Files.deleteIfExists(f);
return f;
} catch (IOException ignored) {}
return null;
}

public record Result(
String uri,
CompletableFuture<Identifier> id
) {
@SuppressWarnings("deprecation")
public InputStream openStream() throws IOException {
return new URL(uri).openStream();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.resource.JsonDataLoader;
import net.minecraft.resource.ResourceFinder;
import net.minecraft.resource.ResourceManager;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
Expand All @@ -33,7 +34,7 @@ public class EquipmentList extends JsonDataLoader<EquipmentList.EquipmentSet> im
private Map<Identifier, EquipmentSet> equipmentSets = Map.of(EMPTY, emptySet);

public EquipmentList() {
super(EquipmentSet.CODEC, "hd_skins_equipment");
super(EquipmentSet.CODEC, ResourceFinder.json("hd_skins_equipment"));
}

@Override
Expand Down
Loading

0 comments on commit d10ebaa

Please sign in to comment.