From 91f741fa08008194a4783c022bb5b625b39eab4a Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Sun, 26 Aug 2018 18:30:04 -0400 Subject: [PATCH] Fix PonyLevel.PONIES not working correctly. --- .../voxelmodpack/hdskins/HDSkinManager.java | 4 ++-- .../com/voxelmodpack/hdskins/ISkinParser.java | 4 +++- .../mixin/MixinNetworkPlayerInfo$1.java | 2 +- .../hdskins/mixin/MixinNetworkPlayerInfo.java | 2 +- .../java/com/minelittlepony/PonyManager.java | 8 ++++++-- .../com/minelittlepony/PonySkinParser.java | 6 ++++-- .../hdskins/gui/RenderPonyModel.java | 2 +- .../com/minelittlepony/pony/data/Pony.java | 20 +++++++++++-------- .../render/skull/PlayerSkullRenderer.java | 17 ++++++++++------ 9 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java index ce640d8d..7f952fe7 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java @@ -257,7 +257,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener { clearListeners.removeIf(this::onSkinCacheCleared); } - public void parseSkin(Type type, ResourceLocation resource, MinecraftProfileTexture texture) { + public void parseSkin(GameProfile profile, Type type, ResourceLocation resource, MinecraftProfileTexture texture) { // grab the metadata object via reflection. Object is live. Map metadata = ProfileTextureUtil.getMetadata(texture); boolean wasNull = metadata == null; @@ -265,7 +265,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener { metadata = new HashMap<>(); } for (ISkinParser parser : skinParsers) { - parser.parse(type, resource, metadata); + parser.parse(profile, type, resource, metadata); } if (wasNull && !metadata.isEmpty()) { ProfileTextureUtil.setMetadata(texture, metadata); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/ISkinParser.java b/src/hdskins/java/com/voxelmodpack/hdskins/ISkinParser.java index 8998cc52..d75bb198 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/ISkinParser.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/ISkinParser.java @@ -1,5 +1,6 @@ package com.voxelmodpack.hdskins; +import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import net.minecraft.util.ResourceLocation; @@ -15,9 +16,10 @@ public interface ISkinParser { * Parses the texture for metadata. Any discovered data should be put into * the metadata Map parameter. * + * @param profile The profile whose skin is being parsed. * @param type The texture type * @param resource The texture location * @param metadata The metadata previously parsed */ - void parse(Type type, ResourceLocation resource, Map metadata); + void parse(GameProfile profile, Type type, ResourceLocation resource, Map metadata); } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo$1.java b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo$1.java index 01e90a20..dbe8a5a1 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo$1.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo$1.java @@ -33,7 +33,7 @@ public abstract class MixinNetworkPlayerInfo$1 implements SkinManager.SkinAvaila CompletableFuture.runAsync(Runnables.doNothing()) .thenAcceptAsync((v) -> { // schedule parsing next tick, texture may not be uploaded at this point - HDSkinManager.INSTANCE.parseSkin(typeIn, location, profileTexture); + HDSkinManager.INSTANCE.parseSkin(player.getGameProfile(), typeIn, location, profileTexture); // re-set the skin-type because vanilla has already set it String model = profileTexture.getMetadata("model"); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo.java b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo.java index 1db10deb..3948599d 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinNetworkPlayerInfo.java @@ -74,7 +74,7 @@ public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo { CompletableFuture.runAsync(Runnables.doNothing()) // schedule parsing next tick .thenAcceptAsync((v) -> { - HDSkinManager.INSTANCE.parseSkin(typeIn, location, profileTexture); + HDSkinManager.INSTANCE.parseSkin(gameProfile, typeIn, location, profileTexture); }, Minecraft.getMinecraft()::addScheduledTask); customTextures.put(type, location); customProfiles.put(type, profileTexture); diff --git a/src/main/java/com/minelittlepony/PonyManager.java b/src/main/java/com/minelittlepony/PonyManager.java index 0c90bf5e..9ea6ec97 100644 --- a/src/main/java/com/minelittlepony/PonyManager.java +++ b/src/main/java/com/minelittlepony/PonyManager.java @@ -68,7 +68,9 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl ResourceLocation skin = player.getLocationSkin(); UUID uuid = player.getGameProfile().getId(); - if (skin == null) return getDefaultPony(uuid); + if (Pony.getBufferedImage(skin) == null) { + return getDefaultPony(uuid); + } return getPony(skin, uuid); } @@ -78,7 +80,9 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl ResourceLocation skin = playerInfo.getLocationSkin(); UUID uuid = playerInfo.getGameProfile().getId(); - if (skin == null) return getDefaultPony(uuid); + if (Pony.getBufferedImage(skin) == null) { + return getDefaultPony(uuid); + } return getPony(skin, uuid); } diff --git a/src/main/java/com/minelittlepony/PonySkinParser.java b/src/main/java/com/minelittlepony/PonySkinParser.java index 18e8930a..056233b1 100644 --- a/src/main/java/com/minelittlepony/PonySkinParser.java +++ b/src/main/java/com/minelittlepony/PonySkinParser.java @@ -1,5 +1,6 @@ package com.minelittlepony; +import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.voxelmodpack.hdskins.ISkinParser; import net.minecraft.util.ResourceLocation; @@ -9,13 +10,14 @@ import java.util.Map; public class PonySkinParser implements ISkinParser { @Override - public void parse(MinecraftProfileTexture.Type type, ResourceLocation resource, Map metadata) { + public void parse(GameProfile profile, MinecraftProfileTexture.Type type, ResourceLocation resource, + Map metadata) { if (type == MinecraftProfileTexture.Type.SKIN) { boolean slim = "slim".equals(metadata.get("model")); // TODO use proper model metadata system metadata.put("model", MineLittlePony.getInstance().getManager() - .getPony(resource) + .getPony(resource, profile.getId()) .getRace(false) .getModel() .getId(slim)); diff --git a/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java b/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java index 02779d8a..4340f9b0 100644 --- a/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java +++ b/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java @@ -64,7 +64,7 @@ public class RenderPonyModel extends RenderPlayerModel implemen renderingAsHuman = true; ResourceLocation loc = getEntityTexture(playermodel); - if (loc == null) { + if (loc == null || Pony.getBufferedImage(loc) == null) { return super.getEntityModel(playermodel); } diff --git a/src/main/java/com/minelittlepony/pony/data/Pony.java b/src/main/java/com/minelittlepony/pony/data/Pony.java index 56e5901b..1e3e7141 100644 --- a/src/main/java/com/minelittlepony/pony/data/Pony.java +++ b/src/main/java/com/minelittlepony/pony/data/Pony.java @@ -1,6 +1,7 @@ package com.minelittlepony.pony.data; import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; import com.minelittlepony.MineLittlePony; import com.voxelmodpack.hdskins.IBufferedTexture; import net.minecraft.block.material.Material; @@ -42,9 +43,11 @@ public class Pony { private IPonyData checkSkin(ResourceLocation resource) { IPonyData data = checkPonyMeta(resource); - if (data != null) return data; + if (data != null) { + return data; + } - BufferedImage skinImage = getBufferedImage(resource); + BufferedImage skinImage = Preconditions.checkNotNull(getBufferedImage(resource), "bufferedImage: " + resource); return this.checkSkin(skinImage); } @@ -74,7 +77,8 @@ public class Pony { MineLittlePony.logger.debug("Obtained skin from resource location {}", resource); return skinImage; - } catch (IOException ignored) { } + } catch (IOException ignored) { + } ITextureObject texture = Minecraft.getMinecraft().getTextureManager().getTexture(resource); @@ -85,8 +89,7 @@ public class Pony { return null; } - private IPonyData checkSkin(@Nullable BufferedImage bufferedimage) { - if (bufferedimage == null) return new PonyData(); + private IPonyData checkSkin(BufferedImage bufferedimage) { MineLittlePony.logger.debug("\tStart skin check for pony #{} with image {}.", ponyId, bufferedimage); return PonyData.parse(bufferedimage); } @@ -101,13 +104,14 @@ public class Pony { } public boolean isFullySubmerged(EntityLivingBase entity) { - return entity.isInWater() && entity.getEntityWorld().getBlockState(new BlockPos(getVisualEyePosition(entity))).getMaterial() == Material.WATER; + return entity.isInWater() + && entity.getEntityWorld().getBlockState(new BlockPos(getVisualEyePosition(entity))).getMaterial() == Material.WATER; } protected Vec3d getVisualEyePosition(EntityLivingBase entity) { PonySize size = entity.isChild() ? PonySize.FOAL : metadata.getSize(); - return new Vec3d(entity.posX, entity.posY + (double)entity.getEyeHeight() * size.getScaleFactor(), entity.posZ); + return new Vec3d(entity.posX, entity.posY + (double) entity.getEyeHeight() * size.getScaleFactor(), entity.posZ); } public boolean isWearingHeadgear(EntityLivingBase entity) { @@ -119,7 +123,7 @@ public class Pony { Item item = stack.getItem(); - return !(item instanceof ItemArmor) || ((ItemArmor)item).getEquipmentSlot() != EntityEquipmentSlot.HEAD; + return !(item instanceof ItemArmor) || ((ItemArmor) item).getEquipmentSlot() != EntityEquipmentSlot.HEAD; } public PonyRace getRace(boolean ignorePony) { diff --git a/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java b/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java index db14de76..3200369e 100644 --- a/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java +++ b/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java @@ -18,6 +18,8 @@ import net.minecraft.util.ResourceLocation; import java.util.Map; import javax.annotation.Nullable; +import static com.mojang.authlib.minecraft.MinecraftProfileTexture.*; + public class PlayerSkullRenderer extends PonySkull { private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears(); @@ -41,19 +43,22 @@ public class PlayerSkullRenderer extends PonySkull { if (profile != null) { deadMau5.setVisible("deadmau5".equals(profile.getName())); - ResourceLocation skin = HDSkinManager.INSTANCE.getTextures(profile).get(MinecraftProfileTexture.Type.SKIN); + ResourceLocation skin = HDSkinManager.INSTANCE.getTextures(profile).get(Type.SKIN); if (skin != null && Pony.getBufferedImage(skin) != null) { return skin; } Minecraft minecraft = Minecraft.getMinecraft(); - Map map = minecraft.getSkinManager().loadSkinFromCache(profile); + Map map = minecraft.getSkinManager().loadSkinFromCache(profile); - if (map.containsKey(MinecraftProfileTexture.Type.SKIN)) { - return minecraft.getSkinManager().loadSkin(map.get(MinecraftProfileTexture.Type.SKIN), MinecraftProfileTexture.Type.SKIN); - } else { - return DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(profile)); + if (map.containsKey(Type.SKIN)) { + ResourceLocation loc = minecraft.getSkinManager().loadSkin(map.get(Type.SKIN), Type.SKIN); + if (Pony.getBufferedImage(loc) != null) { + return loc; + } } + return DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(profile)); + } return DefaultPlayerSkin.getDefaultSkinLegacy();