diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/IMetaHandler.java b/src/hdskins/java/com/voxelmodpack/hdskins/IMetaHandler.java new file mode 100644 index 00000000..a2be38c6 --- /dev/null +++ b/src/hdskins/java/com/voxelmodpack/hdskins/IMetaHandler.java @@ -0,0 +1,8 @@ +package com.voxelmodpack.hdskins; + +import com.google.common.base.Optional; + +public interface IMetaHandler { + + Optional get(String key); +} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/EntityPlayerModel.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/EntityPlayerModel.java index 35a9408c..1414fd8e 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/EntityPlayerModel.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/EntityPlayerModel.java @@ -9,6 +9,7 @@ import javax.imageio.ImageIO; import com.google.common.collect.Iterables; import com.mojang.authlib.GameProfile; import com.voxelmodpack.hdskins.HDSkinManager; +import com.voxelmodpack.hdskins.IMetaHandler; import com.voxelmodpack.hdskins.ImageBufferDownloadHD; import com.voxelmodpack.hdskins.PreviewTexture; @@ -34,6 +35,7 @@ public class EntityPlayerModel extends EntityLivingBase { public boolean isSwinging = false; protected boolean remoteSkin = false; protected boolean hasLocalTexture = false; + public IMetaHandler metaHandler; public EntityPlayerModel(GameProfile profile) { super((World) null); @@ -132,6 +134,11 @@ public class EntityPlayerModel extends EntityLivingBase { this.swingProgress = this.swingProgressInt / 8.0F; } + public void updateMeta(IMetaHandler guiMetaHandler) { + this.metaHandler = guiMetaHandler; + + } + @Override public EnumHandSide getPrimaryHand() { return Minecraft.getMinecraft().gameSettings.mainHand; diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/MetaHandler.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiMetaHandler.java similarity index 79% rename from src/hdskins/java/com/voxelmodpack/hdskins/gui/MetaHandler.java rename to src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiMetaHandler.java index bc7c1a48..c240c30a 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/MetaHandler.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiMetaHandler.java @@ -1,5 +1,7 @@ package com.voxelmodpack.hdskins.gui; +import static net.minecraft.client.renderer.GlStateManager.*; + import java.awt.Color; import java.io.IOException; import java.util.List; @@ -22,24 +24,32 @@ import com.mumfrey.liteloader.client.gui.GuiCheckbox; import com.mumfrey.webprefs.WebPreferencesManager; import com.mumfrey.webprefs.interfaces.IWebPreferences; import com.voxelmodpack.hdskins.HDSkinManager; +import com.voxelmodpack.hdskins.IMetaHandler; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiPageButtonList.GuiResponder; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiSlider; import net.minecraft.client.gui.GuiSlider.FormatHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.Entity; -public class MetaHandler extends GuiScreen { +public class GuiMetaHandler extends GuiScreen implements IMetaHandler { private GuiScreen parent; private List> options = Lists.newArrayList(); protected int optionHeight = 5; protected int optionPosX; - public MetaHandler(GuiScreen parent) { + private EntityPlayerModel model; + + public GuiMetaHandler(GuiScreen parent, EntityPlayerModel localPlayer) { this.parent = parent; + model = localPlayer; } public > void selection(String name, Class options) { @@ -58,19 +68,36 @@ public class MetaHandler extends GuiScreen { this.options.add(new Col(name)); } + @Override + public Optional get(String key) { + for (Opt opt : options) { + if (opt.name.equals(key)) { + if (opt.isEnabled()) { + return Optional.fromNullable(opt.toString()); + } + } + } + return Optional.absent(); + } + @Override public void initGui() { super.initGui(); optionHeight = 30; optionPosX = this.width / 8; - this.buttonList.add(new GuiButton(0, width / 2 - 100, height - 40, 80, 20, "Cancel")); - this.buttonList.add(new GuiButton(1, width / 2 + 20, height - 40, 80, 20, "Apply")); + this.buttonList.add(new GuiButton(0, width / 2 - 100, height - 30, 80, 20, "Cancel")); + this.buttonList.add(new GuiButton(1, width / 2 + 20, height - 30, 80, 20, "Apply")); for (Opt opt : options) { opt.init(); } fetch(); } + @Override + public void onGuiClosed() { + this.model.updateMeta(null); + } + @Override protected void actionPerformed(GuiButton button) throws IOException { switch (button.id) { @@ -90,18 +117,66 @@ public class MetaHandler extends GuiScreen { } } + private float updateCounter; + @Override - public void drawScreen(int mouseX, int mouseY, float ticks) { + public void drawScreen(int mouseX, int mouseY, float partialTick) { + // this.lastPartialTick = this.updateCounter + partialTick; this.drawDefaultBackground(); - super.drawScreen(mouseX, mouseY, ticks); + + int top = 30; + int bottom = height - 40; + int mid = width / 2; + + Gui.drawRect(mid + 10, top, width - 10, bottom, Integer.MIN_VALUE); + + ((GuiSkins) parent).enableClipping(30, height - 40); + enableBlend(); + enableDepth(); + mc.getTextureManager().bindTexture(EntityPlayerModel.NOSKIN); + renderPlayerModel(this.model, width * 0.75F, height * .75F, height * 0.25F, mouseX, mouseY, partialTick); + disableDepth(); + disableBlend(); + ((GuiSkins) parent).disableClipping(); + + super.drawScreen(mouseX, mouseY, partialTick); for (Opt opt : options) { opt.drawOption(mouseX, mouseY); } + this.drawCenteredString(this.fontRendererObj, "Skin Overrides", width / 2, 10, -1); + } + + public void renderPlayerModel(Entity thePlayer, float xPosition, float yPosition, float scale, float mouseX, float mouseY, float partialTick) { + enableColorMaterial(); + pushMatrix(); + translate(xPosition, yPosition, 300.0F); + + scale(-scale, scale, scale); + rotate(180.0F, 0.0F, 0.0F, 1.0F); + rotate(135.0F, 0.0F, 1.0F, 0.0F); + + RenderHelper.enableStandardItemLighting(); + + rotate(-135.0F, 0.0F, 1.0F, 0.0F); + rotate(15.0F, 1.0F, 0.0F, 0.0F); + rotate((updateCounter + partialTick) * 2.5F, 0.0F, 1.0F, 0.0F); + thePlayer.rotationPitch = -((float) Math.atan(mouseY / 40.0F)) * 20.0F; + translate(0.0D, thePlayer.getYOffset(), 0.0D); + + RenderManager rm = Minecraft.getMinecraft().getRenderManager(); + rm.playerViewY = 180.0F; + rm.renderEntityStatic(thePlayer, 0, false); + + popMatrix(); + RenderHelper.disableStandardItemLighting(); + disableColorMaterial(); } @Override public void mouseClicked(int mouseX, int mouseY, int button) throws IOException { super.mouseClicked(mouseX, mouseY, button); + if (mouseX > width / 2) + this.model.swingArm(); for (Opt opt : options) { if (opt.mouseClicked(mouseX, mouseY)) break; @@ -109,6 +184,14 @@ public class MetaHandler extends GuiScreen { } } + @Override + public void updateScreen() { + this.model.updateMeta(this); + this.model.updateModel(); + + this.updateCounter++; + } + @Override public void mouseReleased(int mouseX, int mouseY, int state) { super.mouseReleased(mouseX, mouseY, state); @@ -146,8 +229,8 @@ public class MetaHandler extends GuiScreen { for (Entry e : data.entrySet()) { for (Opt opt : options) { if (opt.name.equals(e.getKey())) { - opt.setEnabled(true); opt.fromString(e.getValue()); + opt.setEnabled(opt.value.isPresent()); break; } } @@ -169,7 +252,7 @@ public class MetaHandler extends GuiScreen { private String getName() { return name; } - + public void setEnabled(boolean enabled) { this.enabled.checked = enabled; } @@ -258,6 +341,7 @@ public class MetaHandler extends GuiScreen { super(name); this.min = min; this.max = max; + this.value = Optional.of(min); } @Override @@ -325,6 +409,7 @@ public class MetaHandler extends GuiScreen { super(name); this.type = enumType; this.options = ImmutableList.copyOf(enumType.getEnumConstants()); + this.value = Optional.of(this.get()); } @Override @@ -391,6 +476,7 @@ public class MetaHandler extends GuiScreen { public Col(String name) { super(name); + value = Optional.of(Color.WHITE); } @Override diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java index b14229c6..0a1bcf25 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java @@ -100,7 +100,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe private float lastPartialTick; private JFrame fileDrop; - private MetaHandler metadata; + private GuiMetaHandler metadata; // translations private final String manager = I18n.format("hdskins.manager"); @@ -132,9 +132,8 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe this.reloadRemoteSkin(); this.fetchingSkin = true; this.panoramaRenderer = LiteModHDSkinsMod.getPanoramaRenderer(this); - this.metadata = new MetaHandler(this); + this.metadata = new GuiMetaHandler(this, this.remotePlayer); this.setupMetaOverrides(this.metadata); - this.metadata.fetch(); } protected EntityPlayerModel getModel(GameProfile profile) { @@ -230,7 +229,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe this.btnBrowse.enabled = !this.mc.isFullScreen(); } - protected void setupMetaOverrides(MetaHandler meta) { + protected void setupMetaOverrides(GuiMetaHandler meta) { meta.bool("slim"); } @@ -574,6 +573,8 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe float xPos2 = this.width * 0.75F; float scale = this.height * 0.25F; + mc.getTextureManager().bindTexture(EntityPlayerModel.NOSKIN); + this.renderPlayerModel(this.localPlayer, xPos1, yPos, scale, xPos1 - mouseX, yPos - scale * 1.8F - mouseY, partialTick); this.renderPlayerModel(this.remotePlayer, xPos2, yPos, scale, xPos2 - mouseX, yPos - scale * 1.8F - mouseY, partialTick); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/RenderPlayerModel.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/RenderPlayerModel.java index 72a299d8..c1d205d3 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/RenderPlayerModel.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/RenderPlayerModel.java @@ -5,6 +5,7 @@ import static net.minecraft.client.renderer.GlStateManager.*; import org.lwjgl.opengl.GL11; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelPlayer; import net.minecraft.client.renderer.entity.RenderLivingBase; import net.minecraft.client.renderer.entity.RenderManager; @@ -12,8 +13,11 @@ import net.minecraft.util.ResourceLocation; public class RenderPlayerModel extends RenderLivingBase { + private static final ModelPlayer FAT = new ModelPlayer(0, false); + private static final ModelPlayer THIN = new ModelPlayer(0, true); + public RenderPlayerModel(RenderManager renderer) { - super(renderer, new ModelPlayer(0, false), 0.0F); + super(renderer, FAT, 0.0F); } @Override @@ -39,6 +43,13 @@ public class RenderPlayerModel extends RenderLiving @Override public void doRender(M par1Entity, double par2, double par4, double par6, float par8, float par9) { + if (par1Entity.metaHandler != null && par1Entity.metaHandler.get("slim").isPresent()) { + boolean skinny = "true".equals(par1Entity.metaHandler.get("slim").get()); + this.mainModel = skinny ? THIN : FAT; + } else { + this.mainModel = FAT; + } + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); super.doRender(par1Entity, par2, par4, par6, par8, par9); popAttrib(); diff --git a/src/main/java/com/brohoof/minelittlepony/Pony.java b/src/main/java/com/brohoof/minelittlepony/Pony.java index 6bad88ca..1626617d 100644 --- a/src/main/java/com/brohoof/minelittlepony/Pony.java +++ b/src/main/java/com/brohoof/minelittlepony/Pony.java @@ -2,6 +2,7 @@ package com.brohoof.minelittlepony; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.Map; import javax.imageio.ImageIO; @@ -9,6 +10,12 @@ import com.brohoof.minelittlepony.model.PMAPI; import com.brohoof.minelittlepony.model.PlayerModel; import com.brohoof.minelittlepony.util.MineLPLogger; import com.brohoof.minelittlepony.util.PonyFields; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.mojang.authlib.GameProfile; +import com.mumfrey.webprefs.WebPreferencesManager; +import com.mumfrey.webprefs.interfaces.IWebPreferences; +import com.voxelmodpack.hdskins.HDSkinManager; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; @@ -24,6 +31,7 @@ public class Pony { private static int ponyCount = 0; private final int ponyId = ponyCount++; + public GameProfile profile; public ResourceLocation textureResourceLocation; public PonyData metadata = new PonyData(); @@ -31,16 +39,17 @@ public class Pony { private boolean skinChecked; public Pony(AbstractClientPlayer player) { + this.profile = player.getGameProfile(); this.textureResourceLocation = player.getLocationSkin(); MineLPLogger.debug("+ Initialising new pony #%d for player %s (%s) with resource location %s.", this.ponyId, player.getName(), player.getUniqueID(), this.textureResourceLocation); this.checkSkin(this.textureResourceLocation); + this.checkMeta(profile); } public Pony(ResourceLocation aTextureResourceLocation) { this.textureResourceLocation = aTextureResourceLocation; - MineLPLogger.debug("+ Initialising new pony #%d with resource location %s.", this.ponyId, - this.textureResourceLocation); + MineLPLogger.debug("+ Initialising new pony #%d with resource location %s.", this.ponyId, this.textureResourceLocation); this.checkSkin(this.textureResourceLocation); } @@ -51,6 +60,7 @@ public class Pony { public void checkSkin() { if (!this.skinChecked) { this.checkSkin(this.textureResourceLocation); + this.checkMeta(this.profile); } } @@ -61,11 +71,29 @@ public class Pony { } } + private void checkMeta(GameProfile profile) { + if (profile == null) + return; + IWebPreferences prefs = WebPreferencesManager.getDefault().getPreferences(profile); + String json = prefs.get(HDSkinManager.METADATA_KEY, "{}"); + Map data = new Gson().fromJson(json, new TypeToken>() {}.getType()); + + if (data.containsKey("race")) + metadata.setRace(PonyRace.valueOf(data.get("race"))); + if (data.containsKey("tail")) + metadata.setTail(TailLengths.valueOf(data.get("tail"))); + if (data.containsKey("gender")) + metadata.setGender(PonyGender.valueOf(data.get("gender"))); + if (data.containsKey("size")) + metadata.setSize(PonySize.valueOf(data.get("size"))); + if (data.containsKey("magic")) + metadata.setGlowColor(Integer.parseInt(data.get("magic"))); + } + public BufferedImage getBufferedImage(ResourceLocation textureResourceLocation) { BufferedImage skinImage = null; try { - skinImage = ImageIO.read(Minecraft.getMinecraft().getResourceManager() - .getResource(textureResourceLocation).getInputStream()); + skinImage = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(textureResourceLocation).getInputStream()); MineLPLogger.debug("Obtained skin from resource location %s", textureResourceLocation); // this.checkSkin(skinImage); } catch (IOException var6) { @@ -128,4 +156,7 @@ public class Pony { return this.textureResourceLocation; } + public GameProfile getProfile() { + return profile; + } } diff --git a/src/main/java/com/brohoof/minelittlepony/hdskins/gui/EntityPonyModel.java b/src/main/java/com/brohoof/minelittlepony/hdskins/gui/EntityPonyModel.java index 4b2ed961..488b93b1 100644 --- a/src/main/java/com/brohoof/minelittlepony/hdskins/gui/EntityPonyModel.java +++ b/src/main/java/com/brohoof/minelittlepony/hdskins/gui/EntityPonyModel.java @@ -1,9 +1,11 @@ package com.brohoof.minelittlepony.hdskins.gui; import com.mojang.authlib.GameProfile; +import com.voxelmodpack.hdskins.IMetaHandler; import com.voxelmodpack.hdskins.gui.EntityPlayerModel; public class EntityPonyModel extends EntityPlayerModel { + public EntityPonyModel(GameProfile profile) { super(profile); } diff --git a/src/main/java/com/brohoof/minelittlepony/hdskins/gui/GuiSkinsMineLP.java b/src/main/java/com/brohoof/minelittlepony/hdskins/gui/GuiSkinsMineLP.java index 24461b2a..33cdb095 100644 --- a/src/main/java/com/brohoof/minelittlepony/hdskins/gui/GuiSkinsMineLP.java +++ b/src/main/java/com/brohoof/minelittlepony/hdskins/gui/GuiSkinsMineLP.java @@ -11,7 +11,7 @@ import com.brohoof.minelittlepony.util.MineLPLogger; import com.mojang.authlib.GameProfile; import com.voxelmodpack.hdskins.gui.EntityPlayerModel; import com.voxelmodpack.hdskins.gui.GuiSkins; -import com.voxelmodpack.hdskins.gui.MetaHandler; +import com.voxelmodpack.hdskins.gui.GuiMetaHandler; public class GuiSkinsMineLP extends GuiSkins { @@ -22,7 +22,7 @@ public class GuiSkinsMineLP extends GuiSkins { } @Override - protected void setupMetaOverrides(MetaHandler meta) { + protected void setupMetaOverrides(GuiMetaHandler meta) { super.setupMetaOverrides(meta); meta.selection("race", PonyRace.class); meta.selection("tail", TailLengths.class); diff --git a/src/main/java/com/brohoof/minelittlepony/hdskins/gui/RenderPonyModel.java b/src/main/java/com/brohoof/minelittlepony/hdskins/gui/RenderPonyModel.java index 017b2962..4c35a5d1 100644 --- a/src/main/java/com/brohoof/minelittlepony/hdskins/gui/RenderPonyModel.java +++ b/src/main/java/com/brohoof/minelittlepony/hdskins/gui/RenderPonyModel.java @@ -2,7 +2,12 @@ package com.brohoof.minelittlepony.hdskins.gui; import com.brohoof.minelittlepony.MineLittlePony; import com.brohoof.minelittlepony.Pony; +import com.brohoof.minelittlepony.PonyGender; +import com.brohoof.minelittlepony.PonyRace; +import com.brohoof.minelittlepony.PonySize; +import com.brohoof.minelittlepony.TailLengths; import com.brohoof.minelittlepony.model.PlayerModel; +import com.google.common.base.Optional; import com.voxelmodpack.hdskins.gui.RenderPlayerModel; import net.minecraft.client.renderer.entity.RenderManager; @@ -17,7 +22,28 @@ public class RenderPonyModel extends RenderPlayerModel { protected void renderModel(EntityPonyModel playermodel, float par2, float par3, float par4, float par5, float par6, float par7) { this.bindEntityTexture(playermodel); Pony thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(this.getEntityTexture(playermodel)); + thePony.invalidateSkinCheck(); thePony.checkSkin(); + + if (playermodel.metaHandler != null) { + Optional race = playermodel.metaHandler.get("race"); + Optional tail = playermodel.metaHandler.get("tail"); + Optional gender = playermodel.metaHandler.get("gender"); + Optional size = playermodel.metaHandler.get("size"); + Optional magicColor = playermodel.metaHandler.get("magic"); + + if (race.isPresent()) + thePony.metadata.setRace(PonyRace.valueOf(race.get())); + if (tail.isPresent()) + thePony.metadata.setTail(TailLengths.valueOf(tail.get())); + if (gender.isPresent()) + thePony.metadata.setGender(PonyGender.valueOf(gender.get())); + if (size.isPresent()) + thePony.metadata.setSize(PonySize.valueOf(size.get())); + if (magicColor.isPresent()) + thePony.metadata.setGlowColor(Integer.parseInt(magicColor.get())); + } + // TODO small arms PlayerModel pm = thePony.getModel(true, false); this.mainModel = pm.getModel(); diff --git a/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java b/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java index 878403d3..b37e577f 100644 --- a/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java +++ b/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java @@ -180,6 +180,7 @@ public abstract class MixinRenderPlayer extends RenderLivingBase { boolean isUnicorn = metadata.getRace().hasHorn(); if (isUnicorn) { ModelPlayerPony playerModel = (ModelPlayerPony) thePony; - playerModel.unicornarm.postRender(0.0625F); + ModelRenderer unicornarm = hand == EnumHandSide.LEFT ? playerModel.unicornArmLeft : playerModel.unicornArmRight; + unicornarm.postRender(0.0625F); } else { ((ModelBiped) this.livingPonyEntity.getMainModel()).postRenderArm(0.0625F, hand); } @@ -87,7 +89,7 @@ public class LayerHeldPonyItem implements LayerRenderer { GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); boolean isLeft = hand == EnumHandSide.LEFT; if (isUnicorn) { - GlStateManager.translate(isLeft ? -0.1F : 0.1F, 1, -.5); + GlStateManager.translate(isLeft ? -0.6F : 0.1F, 1, -.5); } else { GlStateManager.translate(0.0425F, 0.125F, -1.00F); }