From 6d203d07b1e6943aaf15044f9c7d1b5b9f6299a1 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 28 May 2019 14:47:21 +0200 Subject: [PATCH] Update for HDSkins (should fix crash when opening the skins gui) --- .../client/gui/hdskins/GuiSkinsMineLP.java | 16 +++--- .../client/gui/hdskins/PonyPreview.java | 50 +++++++++++++++++++ .../client/gui/hdskins/RenderPonyModel.java | 40 ++------------- 3 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 src/main/java/com/minelittlepony/client/gui/hdskins/PonyPreview.java diff --git a/src/main/java/com/minelittlepony/client/gui/hdskins/GuiSkinsMineLP.java b/src/main/java/com/minelittlepony/client/gui/hdskins/GuiSkinsMineLP.java index 84a34e10..00f7e3a7 100644 --- a/src/main/java/com/minelittlepony/client/gui/hdskins/GuiSkinsMineLP.java +++ b/src/main/java/com/minelittlepony/client/gui/hdskins/GuiSkinsMineLP.java @@ -3,11 +3,10 @@ package com.minelittlepony.client.gui.hdskins; import com.minelittlepony.MineLittlePony; import com.minelittlepony.common.client.gui.element.IconicToggle; import com.minelittlepony.common.client.gui.style.Style; -import com.minelittlepony.hdskins.gui.EntityPlayerModel; import com.minelittlepony.hdskins.gui.GuiSkins; +import com.minelittlepony.hdskins.gui.PlayerPreview; import com.minelittlepony.hdskins.net.SkinServer; import com.minelittlepony.pony.IPonyManager; -import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; @@ -38,8 +37,8 @@ public class GuiSkinsMineLP extends GuiSkins { } @Override - protected EntityPlayerModel getModel(GameProfile profile) { - return new EntityPonyModel(profile); + public PlayerPreview createPreviewer() { + return new PonyPreview(); } @Override @@ -66,11 +65,12 @@ public class GuiSkinsMineLP extends GuiSkins { playSound(SoundEvents.BLOCK_BREWING_STAND_BREW); isWet = wet == 1; - localPlayer.releaseTextures(); - ((EntityPonyModel)localPlayer).setWet(isWet); - ((EntityPonyModel)remotePlayer).setWet(isWet); + previewer.getLocal().releaseTextures(); + if (previewer instanceof PonyPreview) { + ((PonyPreview)previewer).setWet(isWet); + } return wet; } @@ -80,7 +80,7 @@ public class GuiSkinsMineLP extends GuiSkins { MineLittlePony.logger.debug("Invalidating old local skin, checking updated local skin"); if (type == Type.SKIN) { - ponyManager.removePony(localPlayer.getLocal(Type.SKIN).getTexture()); + ponyManager.removePony(previewer.getLocal().getTexture(Type.SKIN).getTexture()); } } diff --git a/src/main/java/com/minelittlepony/client/gui/hdskins/PonyPreview.java b/src/main/java/com/minelittlepony/client/gui/hdskins/PonyPreview.java new file mode 100644 index 00000000..5313ea2c --- /dev/null +++ b/src/main/java/com/minelittlepony/client/gui/hdskins/PonyPreview.java @@ -0,0 +1,50 @@ +package com.minelittlepony.client.gui.hdskins; + +import net.minecraft.util.Identifier; + +import com.minelittlepony.MineLittlePony; +import com.minelittlepony.client.pony.Pony; +import com.minelittlepony.hdskins.gui.EntityPlayerModel; +import com.minelittlepony.hdskins.gui.PlayerPreview; +import com.minelittlepony.pony.IPony; +import com.minelittlepony.pony.meta.Race; +import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; + +public class PonyPreview extends PlayerPreview { + + private final EntityPonyModel localPlayer = new EntityPonyModel(minecraft.getSession().getProfile()); + private final EntityPonyModel remotePlayer = new EntityPonyModel(minecraft.getSession().getProfile()); + + public void setWet(boolean isWet) { + ((EntityPonyModel)localPlayer).setWet(isWet); + ((EntityPonyModel)remotePlayer).setWet(isWet); + } + + protected EntityPlayerModel ponify(EntityPlayerModel entity, EntityPlayerModel pony) { + Identifier loc = entity.getTexture(Type.SKIN).getTexture(); + if (loc == null || Pony.getBufferedImage(loc) == null) { + return entity; + } + + IPony thePony = MineLittlePony.getInstance().getManager().getPony(loc); + + Race race = thePony.getRace(false); + + if (race.isHuman()) { + return entity; + } + + return pony; + } + + @Override + public EntityPlayerModel getRemote() { + return ponify(super.getRemote(), remotePlayer); + } + + + @Override + public EntityPlayerModel getLocal() { + return ponify(super.getLocal(), localPlayer); + } +} diff --git a/src/main/java/com/minelittlepony/client/gui/hdskins/RenderPonyModel.java b/src/main/java/com/minelittlepony/client/gui/hdskins/RenderPonyModel.java index 8d4277e6..f5ac0dbb 100644 --- a/src/main/java/com/minelittlepony/client/gui/hdskins/RenderPonyModel.java +++ b/src/main/java/com/minelittlepony/client/gui/hdskins/RenderPonyModel.java @@ -4,7 +4,6 @@ import com.minelittlepony.MineLittlePony; import com.minelittlepony.client.model.ClientPonyModel; import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.races.PlayerModels; -import com.minelittlepony.client.pony.Pony; import com.minelittlepony.client.render.IPonyRender; import com.minelittlepony.client.render.RenderPony; import com.minelittlepony.client.render.layer.LayerGear; @@ -17,8 +16,6 @@ import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.feature.FeatureRenderer; -import net.minecraft.client.render.entity.model.ElytraEntityModel; -import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.util.Identifier; /** @@ -26,8 +23,6 @@ import net.minecraft.util.Identifier; */ public class RenderPonyModel extends RenderPlayerModel> implements IPonyRender> { - boolean renderingAsHuman = false; - protected final RenderPony> renderPony = new RenderPony<>(this); public RenderPonyModel(EntityRenderDispatcher manager) { @@ -49,24 +44,15 @@ public class RenderPonyModel extends RenderPlayerModel getEntityModel(EntityPonyModel playermodel) { - renderingAsHuman = true; - Identifier loc = getTexture(playermodel); - if (loc == null || Pony.getBufferedImage(loc) == null) { - return super.getEntityModel(playermodel); - } boolean slim = playermodel.usesThinSkin(); @@ -74,10 +60,6 @@ public class RenderPonyModel extends RenderPlayerModel> getElytraLayer() { return new LayerPonyElytra>(this) { - private final ElytraEntityModel modelElytra = new ElytraEntityModel<>(); - - @Override - protected void preRenderCallback() { - if (!renderingAsHuman) { - super.preRenderCallback(); - } - } - - @Override - protected EntityModel getElytraModel() { - return renderingAsHuman ? modelElytra : super.getElytraModel(); - } - @Override protected Identifier getElytraTexture(EntityPonyModel entity) { - return entity.getLocal(Type.ELYTRA).getTexture(); + return entity.getTexture(Type.ELYTRA).getTexture(); } }; }