Make less calls to Pony.getBufferedImage() and actually close it.

This commit is contained in:
Matthew Messinger 2019-07-13 19:12:19 -04:00
parent 1911a6dde8
commit e3a496be16
3 changed files with 6 additions and 8 deletions

View file

@ -1,10 +1,8 @@
package com.minelittlepony.client.hdskins.gui;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.util.Identifier;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.pony.Pony;
import com.minelittlepony.hdskins.dummy.DummyPlayer;
import com.minelittlepony.hdskins.dummy.PlayerPreview;
import com.minelittlepony.pony.IPony;
@ -37,7 +35,7 @@ class PonyPreview extends PlayerPreview {
protected DummyPlayer ponify(DummyPlayer human, DummyPlayer pony) {
Identifier loc = human.getTextures().get(Type.SKIN).getId();
if (loc == null || Pony.getBufferedImage(loc) == MissingSprite.getMissingSpriteTexture().getImage()) {
if (loc == null) {
return pony;
}

View file

@ -71,8 +71,9 @@ public class Pony implements IPony {
return data;
}
NativeImage ponyTexture = getBufferedImage(resource);
return checkSkin(ponyTexture);
try (NativeImage ponyTexture = getBufferedImage(resource)) {
return checkSkin(ponyTexture);
}
}
@Override
@ -102,7 +103,7 @@ public class Pony implements IPony {
return null;
}
public static NativeImage getBufferedImage(@Nullable Identifier resource) {
private static NativeImage getBufferedImage(@Nullable Identifier resource) {
if (resource != null) {
try {
Texture texture = MinecraftClient.getInstance().getTextureManager().getTexture(resource);

View file

@ -20,7 +20,6 @@ import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
@ -99,7 +98,7 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList
Identifier skin = playerInfo.getSkinTexture();
UUID uuid = playerInfo.getProfile().getId();
if (Pony.getBufferedImage(skin) == MissingSprite.getMissingSpriteTexture().getImage()) {
if (skin == null) {
return getDefaultPony(uuid);
}