diff --git a/src/main/java/com/minelittlepony/ForgeProxy.java b/src/main/java/com/minelittlepony/ForgeProxy.java index a192c7b3..7c888acc 100644 --- a/src/main/java/com/minelittlepony/ForgeProxy.java +++ b/src/main/java/com/minelittlepony/ForgeProxy.java @@ -15,16 +15,40 @@ import javax.annotation.Nullable; import java.util.Optional; import java.util.function.Function; +/** + * Proxy class for accessing forge fields and methods. + */ public class ForgeProxy { - + + /** + * True if forge is present. + */ private static boolean forgeLoaded = ModUtilities.fmlIsPresent(); - public static String getArmorTexture(Entity entity, ItemStack armor, String def, EntityEquipmentSlot slot, @Nullable String type) { + /** + * Gets the mod armour texture for associated item and slot. + * + * @param entity The entity to get armour for. + * @param item The armour item + * @param def Default return value if no mods present + * @param slot The slot this armour piece is place in. + * @param type unknown + * @return + */ + public static String getArmorTexture(Entity entity, ItemStack item, String def, EntityEquipmentSlot slot, @Nullable String type) { if (forgeLoaded) - return ForgeHooksClient.getArmorTexture(entity, armor, def, slot, type); + return ForgeHooksClient.getArmorTexture(entity, item, def, slot, type); return def; } + /** + * Gets the mod armour texture for associated item and slot. + * + * @param entity The entity to get armour for. + * @param item The armour item + * @param slot The slot this armour piece is place in. + * @param def Default return value if no mods present + */ public static ModelBiped getArmorModel(EntityLivingBase entity, ItemStack item, EntityEquipmentSlot slot, ModelBiped def) { if (forgeLoaded) return ForgeHooksClient.getArmorModel(entity, item, slot, def); diff --git a/src/main/java/com/minelittlepony/LiteModMineLittlePony.java b/src/main/java/com/minelittlepony/LiteModMineLittlePony.java index bf40a70b..0a19818e 100644 --- a/src/main/java/com/minelittlepony/LiteModMineLittlePony.java +++ b/src/main/java/com/minelittlepony/LiteModMineLittlePony.java @@ -28,8 +28,6 @@ public class LiteModMineLittlePony implements Tickable, InitCompleteListener { @Override public void init(File configPath) { this.mlp = new MineLittlePony(); - this.mlp.init(); - } @Override @@ -41,5 +39,4 @@ public class LiteModMineLittlePony implements Tickable, InitCompleteListener { public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock) { this.mlp.onTick(minecraft, inGame); } - } diff --git a/src/main/java/com/minelittlepony/MineLittlePony.java b/src/main/java/com/minelittlepony/MineLittlePony.java index 3f82fe79..965d9139 100644 --- a/src/main/java/com/minelittlepony/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/MineLittlePony.java @@ -1,93 +1,69 @@ package com.minelittlepony; -import com.google.common.collect.Maps; import com.minelittlepony.hdskins.gui.GuiSkinsMineLP; -import com.minelittlepony.model.PMAPI; import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.PonyDataSerialzier; -import com.minelittlepony.render.player.RenderPonyPlayer; -import com.minelittlepony.render.ponies.RenderPonyEvoker; -import com.minelittlepony.render.ponies.RenderPonyIllusionIllager; -import com.minelittlepony.render.ponies.RenderPonyPigman; -import com.minelittlepony.render.ponies.RenderPonySkeleton; -import com.minelittlepony.render.ponies.RenderPonyVex; -import com.minelittlepony.render.ponies.RenderPonyVillager; -import com.minelittlepony.render.ponies.RenderPonyVindicator; -import com.minelittlepony.render.ponies.RenderPonyZombie; -import com.minelittlepony.render.ponies.RenderPonyZombieVillager; import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.liteloader.util.ModUtilities; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.gui.GuiSkins; import com.voxelmodpack.hdskins.skins.SkinServer; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.client.resources.data.MetadataSerializer; import net.minecraft.client.settings.KeyBinding; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.EntityEvoker; -import net.minecraft.entity.monster.EntityGiantZombie; -import net.minecraft.entity.monster.EntityHusk; -import net.minecraft.entity.monster.EntityIllusionIllager; -import net.minecraft.entity.monster.EntityPigZombie; -import net.minecraft.entity.monster.EntitySkeleton; -import net.minecraft.entity.monster.EntityStray; -import net.minecraft.entity.monster.EntityVex; -import net.minecraft.entity.monster.EntityVindicator; -import net.minecraft.entity.monster.EntityWitherSkeleton; -import net.minecraft.entity.monster.EntityZombie; -import net.minecraft.entity.monster.EntityZombieVillager; -import net.minecraft.entity.passive.EntityVillager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; -import java.util.Map; - +/** + * Static MineLittlePony singleton class. Everything's controlled from up here. + */ public class MineLittlePony { public static final Logger logger = LogManager.getLogger("MineLittlePony"); - public static final String MOD_NAME = "Mine Little Pony"; - public static final String MOD_VERSION = "@VERSION@"; + public static final String + MOD_NAME = "Mine Little Pony", + MOD_VERSION = "@VERSION@"; + + private static final String + SKIN_SERVER_URL = "minelpskins.voxelmodpack.com", + GATEWAY_URL = "minelpskinmanager.voxelmodpack.com"; - @SuppressWarnings("unused") - private static final String SKIN_SERVER_URL = "minelpskins.voxelmodpack.com"; - @SuppressWarnings("unused") - private static final String GATEWAY_URL = "minelpskinmanager.voxelmodpack.com"; private static final KeyBinding SETTINGS_GUI = new KeyBinding("Settings", Keyboard.KEY_F9, "Mine Little Pony"); private static MineLittlePony instance; - private PonyConfig config; - private PonyManager ponyManager; + private final PonyConfig config; + private final PonyManager ponyManager; - private Map, Render> renderMap = Maps.newHashMap(); + private final PonyRenderManager renderManager; MineLittlePony() { instance = this; - } - void init() { LiteLoader.getInput().registerKeyBinding(SETTINGS_GUI); - this.config = new PonyConfig(); - this.ponyManager = new PonyManager(config); - + config = new PonyConfig(); + ponyManager = new PonyManager(config); + renderManager = new PonyRenderManager(); + LiteLoader.getInstance().registerExposable(config, null); IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); - irrm.registerReloadListener(this.ponyManager); + irrm.registerReloadListener(ponyManager); MetadataSerializer ms = Minecraft.getMinecraft().getResourcePackRepository().rprMetadataSerializer; ms.registerMetadataSectionType(new PonyDataSerialzier(), IPonyData.class); // This also makes it the default gateway server. - SkinServer.defaultServers.add("legacy:http://minelpskins.voxelmodpack.com;http://minelpskinmanager.voxelmodpack.com"); + SkinServer.defaultServers.add("legacy:" + SKIN_SERVER_URL + ";" + GATEWAY_URL); } + /** + * Called when the game is ready. + */ void postInit(Minecraft minecraft) { HDSkinManager manager = HDSkinManager.INSTANCE; @@ -97,104 +73,13 @@ public class MineLittlePony { // logger.info("Set MineLP skin server URL."); RenderManager rm = minecraft.getRenderManager(); - this.saveCurrentRenderers(rm); - //ModUtilities.addRenderer(EntityPonyModel.class, new RenderPonyModel(rm)); - - this.initialisePlayerRenderers(rm); - this.initializeMobRenderers(rm); - - } - - private void saveCurrentRenderers(RenderManager rm) { - // villagers - saveRenderer(rm, EntityVillager.class); - saveRenderer(rm, EntityZombieVillager.class); - // zombies - saveRenderer(rm, EntityZombie.class); - saveRenderer(rm, EntityGiantZombie.class); - saveRenderer(rm, EntityHusk.class); - // pig zombie - saveRenderer(rm, EntityPigZombie.class); - // skeletons - saveRenderer(rm, EntitySkeleton.class); - saveRenderer(rm, EntityStray.class); - saveRenderer(rm, EntityWitherSkeleton.class); - // illagers - saveRenderer(rm, EntityVex.class); - saveRenderer(rm, EntityEvoker.class); - saveRenderer(rm, EntityVindicator.class); - saveRenderer(rm, EntityIllusionIllager.class); - } - - private void saveRenderer(RenderManager rm, Class cl) { - this.renderMap.put(cl, rm.getEntityClassRenderObject(cl)); - } - - @SuppressWarnings("unchecked") - private Render getRenderer(Class cl) { - Render render = (Render) this.renderMap.get(cl); - if (render == null) throw new MissingRendererException(cl); - return render; - } - - public void initialisePlayerRenderers(RenderManager rm) { - new RenderPonyPlayer(rm, false, "pony", PMAPI.pony); - new RenderPonyPlayer(rm, true, "slimpony", PMAPI.ponySmall); - } - - public void initializeMobRenderers(RenderManager rm) { - if (this.config.villagers) { - ModUtilities.addRenderer(EntityVillager.class, new RenderPonyVillager(rm)); - ModUtilities.addRenderer(EntityZombieVillager.class, new RenderPonyZombieVillager(rm)); - logger.info("Villagers are now ponies."); - } else { - ModUtilities.addRenderer(EntityVillager.class, getRenderer(EntityVillager.class)); - ModUtilities.addRenderer(EntityZombieVillager.class, getRenderer(EntityZombieVillager.class)); - } - - if (this.config.zombies) { - ModUtilities.addRenderer(EntityZombie.class, new RenderPonyZombie<>(rm)); - ModUtilities.addRenderer(EntityHusk.class, new RenderPonyZombie.Husk(rm)); - ModUtilities.addRenderer(EntityGiantZombie.class, new RenderPonyZombie.Giant(rm)); - logger.info("Zombies are now ponies."); - } else { - ModUtilities.addRenderer(EntityZombie.class, getRenderer(EntityZombie.class)); - ModUtilities.addRenderer(EntityHusk.class, getRenderer(EntityHusk.class)); - ModUtilities.addRenderer(EntityGiantZombie.class, getRenderer(EntityGiantZombie.class)); - } - - if (this.config.pigzombies) { - ModUtilities.addRenderer(EntityPigZombie.class, new RenderPonyPigman(rm)); - logger.info("Zombie pigmen are now ponies."); - } else { - ModUtilities.addRenderer(EntityPigZombie.class, getRenderer(EntityPigZombie.class)); - } - - if (this.config.skeletons) { - ModUtilities.addRenderer(EntitySkeleton.class, new RenderPonySkeleton<>(rm)); - ModUtilities.addRenderer(EntityStray.class, new RenderPonySkeleton.Stray(rm)); - ModUtilities.addRenderer(EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(rm)); - logger.info("Skeletons are now ponies."); - } else { - ModUtilities.addRenderer(EntitySkeleton.class, getRenderer(EntitySkeleton.class)); - ModUtilities.addRenderer(EntityStray.class, getRenderer(EntityStray.class)); - ModUtilities.addRenderer(EntityWitherSkeleton.class, getRenderer(EntityWitherSkeleton.class)); - } - - if (this.config.illagers) { - ModUtilities.addRenderer(EntityVex.class, new RenderPonyVex(rm)); - ModUtilities.addRenderer(EntityEvoker.class, new RenderPonyEvoker(rm)); - ModUtilities.addRenderer(EntityVindicator.class, new RenderPonyVindicator(rm)); - ModUtilities.addRenderer(EntityIllusionIllager.class, new RenderPonyIllusionIllager(rm)); - logger.info("Illagers are now ponies."); - } else { - ModUtilities.addRenderer(EntityVex.class, getRenderer(EntityVex.class)); - ModUtilities.addRenderer(EntityEvoker.class, getRenderer(EntityEvoker.class)); - ModUtilities.addRenderer(EntityVindicator.class, getRenderer(EntityVindicator.class)); - ModUtilities.addRenderer(EntityIllusionIllager.class, getRenderer(EntityIllusionIllager.class)); - } + renderManager.initialisePlayerRenderers(rm); + renderManager.initializeMobRenderers(rm, config); } + /** + * Called on every update tick + */ void onTick(Minecraft minecraft, boolean inGame) { if (inGame && minecraft.currentScreen == null && SETTINGS_GUI.isPressed()) { @@ -210,14 +95,30 @@ public class MineLittlePony { } + /** + * Gets the global MineLP instance. + */ public static MineLittlePony getInstance() { return instance; } + /** + * Gets the static pony manager instance. + */ public PonyManager getManager() { return ponyManager; } + + /** + * Gets the static pony render manager responsible for all entity renderers. + */ + public PonyRenderManager getRenderManager() { + return renderManager; + } + /** + * Gets the global MineLP client configuration. + */ public static PonyConfig getConfig() { return getInstance().config; } diff --git a/src/main/java/com/minelittlepony/PonyConfig.java b/src/main/java/com/minelittlepony/PonyConfig.java index ac76072a..9557ea61 100644 --- a/src/main/java/com/minelittlepony/PonyConfig.java +++ b/src/main/java/com/minelittlepony/PonyConfig.java @@ -6,6 +6,10 @@ import com.mumfrey.liteloader.modconfig.ConfigStrategy; import com.mumfrey.liteloader.modconfig.Exposable; import com.mumfrey.liteloader.modconfig.ExposableOptions; +/** + * Storage contained for MineLP client settings. + * + */ @ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned) public class PonyConfig implements Exposable { @@ -20,15 +24,26 @@ public class PonyConfig implements Exposable { @Expose public boolean skeletons = true; @Expose public boolean illagers = true; + /** + * Gets the current PonyLevel. That is the level of ponies you would like to see. + * @param ignorePony true to ignore whatever value the setting has. + */ public PonyLevel getPonyLevel(boolean ignorePony) { return ignorePony ? PonyLevel.BOTH : getPonyLevel(); } + /** + * Actually gets the pony level value. No option to ignore reality here. + */ public PonyLevel getPonyLevel() { if (ponylevel == null) ponylevel = PonyLevel.PONIES; return ponylevel; } + /** + * Sets the pony level. Want MOAR PONEHS? Well here you go. + * @param ponylevel + */ public void setPonyLevel(PonyLevel ponylevel) { this.ponylevel = ponylevel; } diff --git a/src/main/java/com/minelittlepony/PonyManager.java b/src/main/java/com/minelittlepony/PonyManager.java index bfddf206..3a32070e 100644 --- a/src/main/java/com/minelittlepony/PonyManager.java +++ b/src/main/java/com/minelittlepony/PonyManager.java @@ -24,15 +24,22 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; +/** + * The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin. + * + */ public class PonyManager implements IResourceManagerReloadListener { - public static final ResourceLocation STEVE = new ResourceLocation("minelittlepony", "textures/entity/steve_pony.png"); - public static final ResourceLocation ALEX = new ResourceLocation("minelittlepony", "textures/entity/alex_pony.png"); - - private static final ResourceLocation BGPONIES_JSON = new ResourceLocation("minelittlepony", "textures/entity/pony/bgponies.json"); + public static final ResourceLocation + STEVE = new ResourceLocation("minelittlepony", "textures/entity/steve_pony.png"), + ALEX = new ResourceLocation("minelittlepony", "textures/entity/alex_pony.png"), + BGPONIES_JSON = new ResourceLocation("minelittlepony", "textures/entity/pony/bgponies.json"); private static final Gson GSON = new Gson(); + /** + * All currently loaded background ponies. + */ private List backgroundPonyList = Lists.newArrayList(); private PonyConfig config; @@ -46,16 +53,27 @@ public class PonyManager implements IResourceManagerReloadListener { initmodels(); } - public void initmodels() { + private void initmodels() { MineLittlePony.logger.info("Initializing models..."); PMAPI.init(); MineLittlePony.logger.info("Done initializing models."); } - public Pony getPony(ResourceLocation skinResourceLocation, boolean slim) { - return poniesCache.computeIfAbsent(skinResourceLocation, res -> new Pony(res, slim)); + /** + * Gets or creates a pony for the given skin resource and vanilla model type. + * + * @param resource A texture resource + */ + public Pony getPony(ResourceLocation resource, boolean slim) { + return poniesCache.computeIfAbsent(resource, res -> new Pony(res, slim)); } + /** + * Gets or creates a pony for the given player. + * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. + * + * @param player the player + */ public Pony getPony(AbstractClientPlayer player) { Pony pony = getPony(player.getLocationSkin(), IPlayerInfo.getPlayerInfo(player).usesSlimArms()); @@ -66,6 +84,16 @@ public class PonyManager implements IResourceManagerReloadListener { return pony; } + /** + * Gets or creates a pony for the given skin resource and entity id. + * + * Whether is has slim arms is determined by the id. + * + * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. + * + * @param resource A texture resource + * @param uuid id of a player or entity + */ public Pony getPony(ResourceLocation resource, UUID uuid) { Pony pony = getPony(resource, isSlimSkin(uuid)); @@ -76,6 +104,11 @@ public class PonyManager implements IResourceManagerReloadListener { return pony; } + /** + * Gets the default pony. Either STEVE/ALEX, or a background pony based on client settings. + * + * @param uuid id of a player or entity + */ public Pony getDefaultPony(UUID uuid) { if (config.getPonyLevel() != PonyLevel.PONIES) { return getPony(DefaultPlayerSkin.getDefaultSkin(uuid), isSlimSkin(uuid)); @@ -93,6 +126,9 @@ public class PonyManager implements IResourceManagerReloadListener { return getPony(backgroundPonyList.get(bgi), false); } + /** + * De-registers a pony from the cache. + */ public Pony removePony(ResourceLocation location) { return poniesCache.remove(location); } @@ -124,6 +160,9 @@ public class PonyManager implements IResourceManagerReloadListener { return isSlimSkin(uuid) ? ALEX : STEVE; } + /** + * Returns true if the given uuid is of a player would would use the ALEX skin type. + */ public static boolean isSlimSkin(UUID uuid) { return (uuid.hashCode() & 1) == 1; } diff --git a/src/main/java/com/minelittlepony/PonyRenderManager.java b/src/main/java/com/minelittlepony/PonyRenderManager.java new file mode 100644 index 00000000..bb14bbbe --- /dev/null +++ b/src/main/java/com/minelittlepony/PonyRenderManager.java @@ -0,0 +1,142 @@ +package com.minelittlepony; + +import java.util.Map; + +import com.google.common.collect.Maps; +import com.minelittlepony.hdskins.gui.EntityPonyModel; +import com.minelittlepony.hdskins.gui.RenderPonyModel; +import com.minelittlepony.model.PMAPI; +import com.minelittlepony.render.player.RenderPonyPlayer; +import com.minelittlepony.render.ponies.RenderPonyEvoker; +import com.minelittlepony.render.ponies.RenderPonyIllusionIllager; +import com.minelittlepony.render.ponies.RenderPonyPigman; +import com.minelittlepony.render.ponies.RenderPonySkeleton; +import com.minelittlepony.render.ponies.RenderPonyVex; +import com.minelittlepony.render.ponies.RenderPonyVillager; +import com.minelittlepony.render.ponies.RenderPonyVindicator; +import com.minelittlepony.render.ponies.RenderPonyZombie; +import com.minelittlepony.render.ponies.RenderPonyZombieVillager; +import com.mumfrey.liteloader.util.ModUtilities; + +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.monster.EntityEvoker; +import net.minecraft.entity.monster.EntityGiantZombie; +import net.minecraft.entity.monster.EntityHusk; +import net.minecraft.entity.monster.EntityIllusionIllager; +import net.minecraft.entity.monster.EntityPigZombie; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntityStray; +import net.minecraft.entity.monster.EntityVex; +import net.minecraft.entity.monster.EntityVindicator; +import net.minecraft.entity.monster.EntityWitherSkeleton; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.monster.EntityZombieVillager; +import net.minecraft.entity.passive.EntityVillager; + +/** + * Render manager responsible for replacing and restoring entity renderers when the client settings change. + * Old values of persisted internally. + */ +public class PonyRenderManager { + + private final Map, Render> renderMap = Maps.newHashMap(); + + public PonyRenderManager() { + + } + + /** + * Registers all new player skin types. (currently only pony and slimpony). + */ + public void initialisePlayerRenderers(RenderManager rm) { + // Preview on the select skin gui + ModUtilities.addRenderer(EntityPonyModel.class, new RenderPonyModel(rm)); + + new RenderPonyPlayer(rm, false, "pony", PMAPI.pony); + new RenderPonyPlayer(rm, true, "slimpony", PMAPI.ponySmall); + //TODO: Add skin types for each species? May require model break up. + } + + /** + * Registers all entity model replacements. (except for players). + */ + public void initializeMobRenderers(RenderManager rm, PonyConfig config) { + + if (config.villagers) { + pushNewRenderer(rm, EntityVillager.class, new RenderPonyVillager(rm)); + pushNewRenderer(rm, EntityZombieVillager.class, new RenderPonyZombieVillager(rm)); + MineLittlePony.logger.info("Villagers are now ponies."); + } else { + restoreRenderer(EntityVillager.class); + restoreRenderer(EntityZombieVillager.class); + } + + if (config.zombies) { + pushNewRenderer(rm, EntityZombie.class, new RenderPonyZombie<>(rm)); + pushNewRenderer(rm, EntityHusk.class, new RenderPonyZombie.Husk(rm)); + pushNewRenderer(rm, EntityGiantZombie.class, new RenderPonyZombie.Giant(rm)); + MineLittlePony.logger.info("Zombies are now ponies."); + } else { + restoreRenderer(EntityZombie.class); + restoreRenderer(EntityHusk.class); + restoreRenderer(EntityGiantZombie.class); + } + + if (config.pigzombies) { + pushNewRenderer(rm, EntityPigZombie.class, new RenderPonyPigman(rm)); + MineLittlePony.logger.info("Zombie pigmen are now ponies."); + } else { + restoreRenderer(EntityPigZombie.class); + } + + if (config.skeletons) { + pushNewRenderer(rm, EntitySkeleton.class, new RenderPonySkeleton<>(rm)); + pushNewRenderer(rm, EntityStray.class, new RenderPonySkeleton.Stray(rm)); + pushNewRenderer(rm, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(rm)); + MineLittlePony.logger.info("Skeletons are now ponies."); + } else { + restoreRenderer(EntitySkeleton.class); + restoreRenderer(EntityStray.class); + restoreRenderer(EntityWitherSkeleton.class); + } + + if (config.illagers) { + pushNewRenderer(rm, EntityVex.class, new RenderPonyVex(rm)); + pushNewRenderer(rm, EntityEvoker.class, new RenderPonyEvoker(rm)); + pushNewRenderer(rm, EntityVindicator.class, new RenderPonyVindicator(rm)); + pushNewRenderer(rm, EntityIllusionIllager.class, new RenderPonyIllusionIllager(rm)); + MineLittlePony.logger.info("Illagers are now ponies."); + } else { + restoreRenderer(EntityVex.class); + restoreRenderer(EntityEvoker.class); + restoreRenderer(EntityVindicator.class); + restoreRenderer(EntityIllusionIllager.class); + } + } + + /** + * Pushes a new renderer replacement storing the original internally. This change can be undone with {@link #restoreRenderer(Class)} + * @param manager The render manager + * @param type The type to replace + * @param renderer The replacement value + * @param The entity type + */ + public void pushNewRenderer(RenderManager manager, Class type, Render renderer) { + if (!renderMap.containsKey(type)) { + renderMap.put(type, manager.getEntityClassRenderObject(type)); + } + ModUtilities.addRenderer(type, renderer); + } + + /** + * Restores a renderer to its previous value. + */ + @SuppressWarnings("unchecked") + public void restoreRenderer(Class type) { + if (renderMap.containsKey(type)) { + ModUtilities.addRenderer(type, (Render)renderMap.get(type)); + } + } +} diff --git a/src/main/java/com/minelittlepony/PonySettingPanel.java b/src/main/java/com/minelittlepony/PonySettingPanel.java index e045b1a5..935f429e 100644 --- a/src/main/java/com/minelittlepony/PonySettingPanel.java +++ b/src/main/java/com/minelittlepony/PonySettingPanel.java @@ -9,6 +9,9 @@ import net.minecraft.client.resources.I18n; import java.io.IOException; +/** + * In-Game options menu. + */ public class PonySettingPanel extends GuiScreen { private static final String _PREFIX = "minelp.options."; @@ -175,6 +178,6 @@ public class PonySettingPanel extends GuiScreen { @Override public void onGuiClosed() { LiteLoader.getInstance().writeConfig(config); - MineLittlePony.getInstance().initializeMobRenderers(mc.getRenderManager()); + MineLittlePony.getInstance().getRenderManager().initializeMobRenderers(mc.getRenderManager(), config); } } diff --git a/src/main/java/com/minelittlepony/ducks/IDownloadImageData.java b/src/main/java/com/minelittlepony/ducks/IDownloadImageData.java index 313fa923..15a0b914 100644 --- a/src/main/java/com/minelittlepony/ducks/IDownloadImageData.java +++ b/src/main/java/com/minelittlepony/ducks/IDownloadImageData.java @@ -3,5 +3,8 @@ package com.minelittlepony.ducks; import java.awt.image.BufferedImage; public interface IDownloadImageData { + /** + * Gets the downloaded image data as a buffered image. + */ BufferedImage getBufferedImage(); } diff --git a/src/main/java/com/minelittlepony/ducks/IPlayerInfo.java b/src/main/java/com/minelittlepony/ducks/IPlayerInfo.java index f2d62f55..ef74e6ea 100644 --- a/src/main/java/com/minelittlepony/ducks/IPlayerInfo.java +++ b/src/main/java/com/minelittlepony/ducks/IPlayerInfo.java @@ -6,10 +6,19 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; public interface IPlayerInfo { + /** + * Gets the pony associated with this player. + */ Pony getPony(); + /** + * Returns true if the vanilla skin (the one returned by NetworkPlayerInfo.getSkinLocation) uses the ALEX model type. + */ boolean usesSlimArms(); + /** + * Gets the player info for the given player. + */ public static IPlayerInfo getPlayerInfo(AbstractClientPlayer player) { return (IPlayerInfo)Minecraft.getMinecraft().getConnection().getPlayerInfo(player.getUniqueID()); } diff --git a/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java b/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java index 4c9f7520..2351fca3 100644 --- a/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java +++ b/src/main/java/com/minelittlepony/ducks/IPonyAnimationHolder.java @@ -1,5 +1,12 @@ package com.minelittlepony.ducks; +/** + * Holding class for entities that support special pony animations used for the renderers. + */ public interface IPonyAnimationHolder { + + /** + * Updates and gets the amount this entity is strafing to each side. + */ float getStrafeAmount(float ticks); } diff --git a/src/main/java/com/minelittlepony/ducks/IRenderItem.java b/src/main/java/com/minelittlepony/ducks/IRenderItem.java index 4d1a0eec..ebd69469 100644 --- a/src/main/java/com/minelittlepony/ducks/IRenderItem.java +++ b/src/main/java/com/minelittlepony/ducks/IRenderItem.java @@ -2,5 +2,8 @@ package com.minelittlepony.ducks; public interface IRenderItem { + /** + * Sets whether items should be rendered with transparency support. + */ void useTransparency(boolean use); } diff --git a/src/main/java/com/minelittlepony/ducks/IRenderManager.java b/src/main/java/com/minelittlepony/ducks/IRenderManager.java index f401e645..d48b127a 100644 --- a/src/main/java/com/minelittlepony/ducks/IRenderManager.java +++ b/src/main/java/com/minelittlepony/ducks/IRenderManager.java @@ -3,5 +3,10 @@ package com.minelittlepony.ducks; import net.minecraft.client.renderer.entity.RenderPlayer; public interface IRenderManager { + /** + * Registers a new player model to the underlying skinMap object. + * @param key The key to identify it by. + * @param render The renderer to add. + */ void addPlayerSkin(String key, RenderPlayer render); } diff --git a/src/main/java/com/minelittlepony/ducks/IRenderPony.java b/src/main/java/com/minelittlepony/ducks/IRenderPony.java index 17ba01bf..8af9d081 100644 --- a/src/main/java/com/minelittlepony/ducks/IRenderPony.java +++ b/src/main/java/com/minelittlepony/ducks/IRenderPony.java @@ -2,7 +2,13 @@ package com.minelittlepony.ducks; import com.minelittlepony.model.ModelWrapper; +/** + * I Render Pony now, oky? + */ public interface IRenderPony { + /** + * Gets the wrapped pony model for this renderer. + */ ModelWrapper getPlayerModel(); } diff --git a/src/main/java/com/minelittlepony/hdskins/gui/EntityPonyModel.java b/src/main/java/com/minelittlepony/hdskins/gui/EntityPonyModel.java index d16fc047..1c93e6f8 100644 --- a/src/main/java/com/minelittlepony/hdskins/gui/EntityPonyModel.java +++ b/src/main/java/com/minelittlepony/hdskins/gui/EntityPonyModel.java @@ -3,6 +3,9 @@ package com.minelittlepony.hdskins.gui; import com.mojang.authlib.GameProfile; import com.voxelmodpack.hdskins.gui.EntityPlayerModel; +/** + * Dummy model used for the skin uploading screen. + */ public class EntityPonyModel extends EntityPlayerModel { public EntityPonyModel(GameProfile profile) { diff --git a/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java b/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java index ad052db1..b45afce7 100644 --- a/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java +++ b/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java @@ -8,6 +8,9 @@ import com.voxelmodpack.hdskins.gui.EntityPlayerModel; import com.voxelmodpack.hdskins.gui.GuiSkins; import net.minecraft.util.ResourceLocation; +/** + * Skin uploading GUI. Usually displayed over the main menu. + */ public class GuiSkinsMineLP extends GuiSkins { private PonyManager ponyManager; diff --git a/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java b/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java index a8b6387e..696c7726 100644 --- a/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java +++ b/src/main/java/com/minelittlepony/hdskins/gui/RenderPonyModel.java @@ -18,6 +18,9 @@ import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +/** + * Renderer used for the dummy pony model when selecting a skin. + */ public class RenderPonyModel extends RenderPlayerModel { public RenderPonyModel(RenderManager renderer) { diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index 63d8c2ac..1126bbed 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -29,27 +29,40 @@ public abstract class AbstractPonyModel extends ModelPlayer { public IPonyData metadata = new PonyData(); public float motionPitch; + @Deprecated // TODO: Why so many arms? - public ModelRenderer steveLeftArm, steveRightArm, - steveLeftArmwear, steveRightArmwear; + public ModelRenderer steveLeftArm; + public ModelRenderer steveRightArm; public AbstractPonyModel(boolean arms) { super(0, arms); this.steveLeftArm = this.bipedLeftArm; this.steveRightArm = this.bipedRightArm; - this.steveLeftArmwear = this.bipedLeftArmwear; - this.steveRightArmwear = this.bipedLeftArmwear; } + /** + * Sets up this model's initial values, like a constructor... + * @param yOffset YPosition for this model. Always 0. + * @param stretch Scaling factor for this model. Ranges above or below 0 (no change). + */ public void init(float yOffset, float stretch) { - this.initTextures(); + initTextures(); this.initPositions(yOffset, stretch); } + /** + * Returns a new pony armour to go with this model. Called on startup by a model wrapper. + */ public abstract PonyArmor createArmour(); + /** + * Loads texture values. + */ protected abstract void initTextures(); + /** + * Loads texture positions and boxes. Pretty much just finishes the job of initTextures. + */ protected abstract void initPositions(float yOffset, float stretch); @Override @@ -58,17 +71,19 @@ public abstract class AbstractPonyModel extends ModelPlayer { super.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scaleFactor, entityIn); return; } - this.steveRightArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float) Math.PI) * 2.0F * limbSwingAmount * 0.5F; + + this.steveRightArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float) Math.PI) * 2 * limbSwingAmount * 0.5F; this.steveRightArm.rotateAngleY = 0; this.steveRightArm.rotateAngleZ = 0; - this.steveLeftArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 2.0F * limbSwingAmount * 0.5F; + + this.steveLeftArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 2 * limbSwingAmount * 0.5F; this.steveLeftArm.rotateAngleY = 0; this.steveLeftArm.rotateAngleZ = 0; - - copyModelAngles(steveRightArm, steveRightArmwear); - copyModelAngles(steveLeftArm, steveLeftArmwear); } + /** + * Returns true if the default minecraft handling should be used. + */ protected boolean doCancelRender() { return false; } @@ -79,15 +94,31 @@ public abstract class AbstractPonyModel extends ModelPlayer { aRenderer.rotationPointZ += shiftZ; } - protected static void rotateArmHolding(ModelRenderer arm, float direction, float var8, float var9, float tick) { + /** + * Rotates the provided arm to the correct orientation for holding an item. + * + * @param arm The arm to rotate + * @param direction Direction multiplier. 1 for right, -1 for left. + * @param swingProgress How far we are through the current swing + * @param tick Render partial ticks + */ + protected static void rotateArmHolding(ModelRenderer arm, float direction, float swingProgress, float tick) { + float swing = MathHelper.sin(swingProgress * (float)Math.PI); + float roll = MathHelper.sin((1 - (1 - swingProgress) * (1 - swingProgress)) * (float)Math.PI); + arm.rotateAngleZ = 0.0F; - arm.rotateAngleY = direction * (0.1F - var8 * 0.6F); + arm.rotateAngleY = direction * (0.1F - swing * 0.6F); arm.rotateAngleX = -1.5707964F; - arm.rotateAngleX -= var8 * 1.2F - var9 * 0.4F; + arm.rotateAngleX -= swing * 1.2F - roll * 0.4F; arm.rotateAngleZ += MathHelper.cos(tick * 0.09F) * 0.05F + 0.05F; arm.rotateAngleX += MathHelper.sin(tick * 0.067F) * 0.1F; } + /** + * Applies a transform particular to a certain body part. + * + * FIXME: Too long! Is there a better way to do this? + */ public void transform(BodyPart part) { if (this.isRiding) { translate(0.0F, -0.6F, -0.2F); @@ -221,15 +252,18 @@ public abstract class AbstractPonyModel extends ModelPlayer { } } + /** + * Copies this model's attributes from some other. + */ @Override public void setModelAttributes(ModelBase model) { super.setModelAttributes(model); if (model instanceof AbstractPonyModel) { AbstractPonyModel pony = (AbstractPonyModel) model; - this.isFlying = pony.isFlying; - this.isSleeping = pony.isSleeping; - this.metadata = pony.metadata; - this.motionPitch = pony.motionPitch; + isFlying = pony.isFlying; + isSleeping = pony.isSleeping; + metadata = pony.metadata; + motionPitch = pony.motionPitch; } } diff --git a/src/main/java/com/minelittlepony/model/ModelMobPony.java b/src/main/java/com/minelittlepony/model/ModelMobPony.java index 3652cb6d..5007762c 100644 --- a/src/main/java/com/minelittlepony/model/ModelMobPony.java +++ b/src/main/java/com/minelittlepony/model/ModelMobPony.java @@ -3,8 +3,11 @@ package com.minelittlepony.model; import com.minelittlepony.model.ponies.ModelPlayerPony; import net.minecraft.entity.Entity; -import net.minecraft.util.math.MathHelper; +/** + * Common class for all humanoid (ponioid?) non-player enemies. + * + */ public class ModelMobPony extends ModelPlayerPony { public ModelMobPony() { @@ -15,32 +18,42 @@ public class ModelMobPony extends ModelPlayerPony { protected void rotateLegs(float move, float swing, float tick, Entity entity) { super.rotateLegs(move, swing, tick, entity); - float var8 = MathHelper.sin(swingProgress * (float)Math.PI); - float var9 = MathHelper.sin((1 - (1 - swingProgress) * (1 - swingProgress)) * (float)Math.PI); - - rotateRightArm(var8, var9, move, tick); - rotateLeftArm(var8, var9, move, tick); + rotateRightArm(move, tick); + rotateLeftArm(move, tick); } - protected void rotateRightArm(float var8, float var9, float move, float tick) { + /** + * Called to update the left arm's final rotation. + * Subclasses may replace it with their own implementations. + * + * @param move Limb swing amount. + * @param tick Render partial ticks. + */ + protected void rotateRightArm(float move, float tick) { if (this.rightArmPose == ArmPose.EMPTY) return; if (!metadata.hasMagic()) { - rotateArmHolding(bipedRightArm, 1, var8, var9, tick); + rotateArmHolding(bipedRightArm, 1, swingProgress, tick); } else { unicornArmRight.setRotationPoint(-7, 12, -2); - rotateArmHolding(unicornArmRight, 1, var8, var9, tick); + rotateArmHolding(unicornArmRight, 1, swingProgress, tick); } } - protected void rotateLeftArm(float var8, float var9, float move, float tick) { + /** + * Same as rotateRightArm but for the left arm (duh). + * + * @param move Limb swing amount. + * @param tick Render partial ticks. + */ + protected void rotateLeftArm(float move, float tick) { if (leftArmPose == ArmPose.EMPTY) return; if (!metadata.hasMagic()) { - rotateArmHolding(bipedLeftArm, 1, var8, var9, tick); + rotateArmHolding(bipedLeftArm, 1, swingProgress, tick); } else { unicornArmRight.setRotationPoint(-7, 12, -2); - rotateArmHolding(unicornArmLeft, 1, var8, var9, tick); + rotateArmHolding(unicornArmLeft, 1, swingProgress, tick); } } } diff --git a/src/main/java/com/minelittlepony/model/ModelWrapper.java b/src/main/java/com/minelittlepony/model/ModelWrapper.java index a56d83e8..ede02d2f 100644 --- a/src/main/java/com/minelittlepony/model/ModelWrapper.java +++ b/src/main/java/com/minelittlepony/model/ModelWrapper.java @@ -3,11 +3,17 @@ package com.minelittlepony.model; import com.minelittlepony.model.armour.PonyArmor; import com.minelittlepony.pony.data.IPonyData; +/** + * Container class for the various models and their associated piece of armour. + */ public class ModelWrapper { private final AbstractPonyModel model; private final PonyArmor armor; + /** + * Created a new model wrapper to contain the given pony. + */ public ModelWrapper(AbstractPonyModel model) { this.model = model; this.armor = model.createArmour(); @@ -18,17 +24,27 @@ public class ModelWrapper { return model; } - public void init() { - model.init(0, 0); - armor.init(); - } - + /** + * Returns the contained armour model. + * @return + */ public PonyArmor getArmor() { return armor; } + /** + * Updates metadata values on this wrapper's armour and model. + */ public void apply(IPonyData meta) { model.metadata = meta; armor.apply(meta); } + + /** + * Called at startup to configure a model's needed components. + */ + public void init() { + model.init(0, 0); + armor.init(); + } } diff --git a/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java index 86118dd8..0d051057 100644 --- a/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java @@ -125,14 +125,20 @@ public class ModelPonyArmor extends ModelMobPony { @Override protected void initLegTextures() { this.bipedRightArm = new ModelRenderer(this, 0, 16); + this.steveRightArm = new ModelRenderer(this, 0, 16); + this.bipedLeftArm = new ModelRenderer(this, 0, 16); this.bipedLeftArm.mirror = true; - this.bipedRightLeg = new ModelRenderer(this, 0, 16); + this.bipedLeftLeg = new ModelRenderer(this, 0, 16); this.bipedLeftLeg.mirror = true; - this.steveRightArm = new ModelRenderer(this, 0, 16); + + this.bipedRightLeg = new ModelRenderer(this, 0, 16); + + this.unicornArmRight = new ModelRenderer(this, 0, 16); this.unicornArmLeft = new ModelRenderer(this, 0, 16); + this.extLegs[0] = new ModelRenderer(this, 48, 8); this.extLegs[1] = new ModelRenderer(this, 48, 8); this.extLegs[1].mirror = true; diff --git a/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java index ba0584be..5375ca2f 100644 --- a/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java @@ -1,15 +1,26 @@ package com.minelittlepony.model.armour; +/** + * Armour for skeleton ponies. + * + */ public class ModelSkeletonPonyArmor extends ModelPonyArmor { + /** + * The code here is copied from ModelMobPony, all with but one line of difference. + */ @Override - protected void rotateRightArm(float var8, float var9, float move, float tick) { + protected void rotateRightArm(float move, float tick) { if (this.rightArmPose == ArmPose.EMPTY) return; if (!this.metadata.hasMagic()) { - rotateArmHolding(bipedRightArm, 1, var8, var9, tick); + rotateArmHolding(bipedRightArm, 1, swingProgress, tick); } else { - rotateArmHolding(unicornArmRight, 1, var8, var9, tick); + // With everything that's happening in ModelPonyArmor, + // it's hard to tell if this is need or not. + // Testing will probably reveal all. + //unicornArmRight.setRotationPoint(-7, 12, -2); + rotateArmHolding(unicornArmRight, 1, swingProgress, tick); } } diff --git a/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java index b058dde2..65caef48 100644 --- a/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java @@ -9,18 +9,18 @@ public class ModelZombiePonyArmor extends ModelPonyArmor { } @Override - protected void rotateRightArm(float var8, float var9, float move, float tick) { + protected void rotateRightArm(float move, float tick) { if (rightArmPose != ArmPose.EMPTY) return; if (isRight(move)) { - rotateArmHolding(bipedRightArm, 1, var8, var9, tick); + rotateArmHolding(bipedRightArm, 1, swingProgress, tick); } else { - rotateArmHolding(bipedLeftArm, -1, var8, var9, tick); + rotateArmHolding(bipedLeftArm, -1, swingProgress, tick); } } @Override - protected void rotateLeftArm(float var8, float var9, float move, float tick) { + protected void rotateLeftArm(float move, float tick) { } diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelPlayerPony.java b/src/main/java/com/minelittlepony/model/ponies/ModelPlayerPony.java index 4f14ef1c..e3a64742 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelPlayerPony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelPlayerPony.java @@ -222,31 +222,33 @@ public class ModelPlayerPony extends AbstractPonyModel { leftLeg = MathHelper.cos(mve + PI - (pi * 0.4f)) * srt; rightLeg = MathHelper.cos(mve + pi * 0.2f) * srt; - this.steveRightArm.rotateAngleY = 0; - this.unicornArmRight.rotateAngleY = 0; - this.unicornArmLeft.rotateAngleY = 0; - - this.bipedRightArm.rotateAngleY = 0; + this.steveRightArm.rotateAngleY = this.bipedRightArm.rotateAngleY = 0; + this.bipedLeftArm.rotateAngleY = 0; this.bipedRightLeg.rotateAngleY = 0; this.bipedLeftLeg.rotateAngleY = 0; + + this.unicornArmRight.rotateAngleY = 0; + this.unicornArmLeft.rotateAngleY = 0; } - this.bipedRightArm.rotateAngleX = rightArm; - this.steveRightArm.rotateAngleX = rightArm; + + + + + this.steveLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX = leftArm; + this.steveRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX = rightArm; + + this.bipedLeftArm.rotateAngleZ = 0; + this.steveRightArm.rotateAngleZ = this.bipedRightArm.rotateAngleZ = 0; + + this.bipedLeftLeg.rotateAngleX = leftLeg; + this.bipedRightLeg.rotateAngleX = rightLeg; + this.unicornArmRight.rotateAngleX = 0; this.unicornArmLeft.rotateAngleX = 0; - - this.bipedLeftArm.rotateAngleX = leftArm; - this.bipedRightLeg.rotateAngleX = rightLeg; - this.bipedLeftLeg.rotateAngleX = leftLeg; - - this.bipedRightArm.rotateAngleZ = 0; - - this.steveRightArm.rotateAngleZ = 0; this.unicornArmRight.rotateAngleZ = 0; this.unicornArmLeft.rotateAngleZ = 0; - this.bipedLeftArm.rotateAngleZ = 0; } private float getLegOutset() { @@ -256,30 +258,34 @@ public class ModelPlayerPony extends AbstractPonyModel { } protected void adjustLegs() { - float sinBodyRotateAngleYFactor = MathHelper.sin(this.bipedBody.rotateAngleY) * 5; - float cosBodyRotateAngleYFactor = MathHelper.cos(this.bipedBody.rotateAngleY) * 5; - - - float legOutset = getLegOutset(); + float sin = MathHelper.sin(bipedBody.rotateAngleY) * 5; + float cos = MathHelper.cos(bipedBody.rotateAngleY) * 5; + float spread = rainboom ? 2 : 1; - this.bipedRightArm.rotationPointZ = spread + sinBodyRotateAngleYFactor; - this.steveRightArm.rotationPointZ = spread + sinBodyRotateAngleYFactor; - this.bipedLeftArm.rotationPointZ = spread - sinBodyRotateAngleYFactor; - this.steveRightArm.rotationPointX = -cosBodyRotateAngleYFactor; + steveRightArm.rotationPointZ = bipedRightArm.rotationPointZ = spread + sin; - float rpxl = legOutset - cosBodyRotateAngleYFactor - 1; - float rpxr = cosBodyRotateAngleYFactor + 2 - legOutset; - - bipedRightArm.rotationPointX = bipedRightLeg.rotationPointX = rpxl; - bipedLeftArm.rotationPointX = bipedLeftLeg.rotationPointX = rpxr; + bipedLeftArm.rotationPointZ = spread - sin; + steveRightArm.rotationPointZ = -cos; + + float legOutset = getLegOutset(); + float rpxl = cos + 1 - legOutset; + float rpxr = legOutset - cos - 1; + + bipedRightArm.rotationPointX = rpxr; + bipedRightLeg.rotationPointX = rpxr; + bipedLeftArm.rotationPointX = rpxl; + bipedLeftLeg.rotationPointX = rpxl; + + // Push the front legs back apart if we're a thin pony + if (smallArms) { + bipedLeftArm.rotationPointX--; + bipedLeftArm.rotationPointX += 2; + } bipedRightArm.rotateAngleY += bipedBody.rotateAngleY; bipedLeftArm.rotateAngleY += bipedBody.rotateAngleY; - //noinspection SuspiciousNameCombination - this.bipedLeftArm.rotateAngleX += this.bipedBody.rotateAngleY; - bipedRightArm.rotationPointY = bipedLeftArm.rotationPointY = 8; bipedRightLeg.rotationPointZ = bipedLeftLeg.rotationPointZ = 10; } @@ -298,17 +304,16 @@ public class ModelPlayerPony extends AbstractPonyModel { this.horn.setUsingMagic(this.leftArmPose != ArmPose.EMPTY || this.rightArmPose != ArmPose.EMPTY); } - - @SuppressWarnings("incomplete-switch") - private void alignArmForAction(ModelRenderer arm, ArmPose pose, boolean bothHoovesAreOccupied, float swing) { + + private void alignArmForAction(ModelRenderer arm, ArmPose pose, boolean both, float swing) { switch (pose) { case ITEM: float swag = 1; - if (!isFlying && bothHoovesAreOccupied) { + if (!isFlying && both) { swag = (float) (1 - Math.pow(swing, 2)); } - float rotationMultiplier = 0.5f + (1 - swag)/2; - arm.rotateAngleX = this.bipedLeftArm.rotateAngleX * rotationMultiplier - ((float) Math.PI / 10) * swag; + float mult = 0.5f + (1 - swag)/2; + arm.rotateAngleX = this.bipedLeftArm.rotateAngleX * mult - ((float) Math.PI / 10) * swag; case EMPTY: arm.rotateAngleY = 0; break; @@ -316,6 +321,7 @@ public class ModelPlayerPony extends AbstractPonyModel { arm.rotateAngleX = arm.rotateAngleX / 2 - 0.9424779F; arm.rotateAngleY = (float) (Math.PI / 6); break; + default: } } @@ -348,38 +354,38 @@ public class ModelPlayerPony extends AbstractPonyModel { } private void swingArm(ModelRenderer arm, float f22, float f33, float f28) { - arm.rotateAngleX = (float) (this.unicornArmRight.rotateAngleX - (f22 * 1.2D + f33)); + arm.rotateAngleX = (float) (arm.rotateAngleX - (f22 * 1.2D + f33)); arm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; arm.rotateAngleZ = f28 * -0.4F; } protected void swingArms(float tick) { - float cosTickFactor = MathHelper.cos(tick * 0.09F) * 0.05F + 0.05F; - float sinTickFactor = MathHelper.sin(tick * 0.067F) * 0.05F; + float cos = MathHelper.cos(tick * 0.09F) * 0.05F + 0.05F; + float sin = MathHelper.sin(tick * 0.067F) * 0.05F; if (this.rightArmPose != ArmPose.EMPTY && !this.isSleeping) { if (this.metadata.hasMagic()) { - this.unicornArmRight.rotateAngleZ += cosTickFactor; - this.unicornArmRight.rotateAngleX += sinTickFactor; + this.unicornArmRight.rotateAngleZ += cos; + this.unicornArmRight.rotateAngleX += sin; } else { - this.bipedRightArm.rotateAngleZ += cosTickFactor; - this.bipedRightArm.rotateAngleX += sinTickFactor; - - this.steveRightArm.rotateAngleZ += cosTickFactor; - this.steveRightArm.rotateAngleX += sinTickFactor; + this.bipedRightArm.rotateAngleZ += cos; + this.steveRightArm.rotateAngleZ += cos; + + this.bipedRightArm.rotateAngleX += sin; + this.steveRightArm.rotateAngleX += sin; } } if (this.leftArmPose != ArmPose.EMPTY && !this.isSleeping) { if (this.metadata.hasMagic()) { - this.unicornArmLeft.rotateAngleZ += cosTickFactor; - this.unicornArmLeft.rotateAngleX += sinTickFactor; + this.unicornArmLeft.rotateAngleZ += cos; + this.unicornArmLeft.rotateAngleX += sin; } else { - this.bipedLeftArm.rotateAngleZ += cosTickFactor; - this.bipedLeftArm.rotateAngleX += sinTickFactor; - - this.steveLeftArm.rotateAngleZ += cosTickFactor; - this.steveLeftArm.rotateAngleX += sinTickFactor; + this.bipedLeftArm.rotateAngleZ += cos; + this.steveLeftArm.rotateAngleZ += cos; + + this.bipedLeftArm.rotateAngleX += sin; + this.steveLeftArm.rotateAngleX += sin; } } } @@ -412,10 +418,9 @@ public class ModelPlayerPony extends AbstractPonyModel { this.unicornArmLeft.rotateAngleX += SNEAK_LEG_X_ROTATION_ADJUSTMENT; this.bipedRightArm.rotateAngleX -= SNEAK_LEG_X_ROTATION_ADJUSTMENT; - this.bipedRightLeg.rotationPointY = FRONT_LEG_RP_Y_SNEAK; - this.bipedLeftArm.rotateAngleX -= SNEAK_LEG_X_ROTATION_ADJUSTMENT; - this.bipedLeftLeg.rotationPointY = FRONT_LEG_RP_Y_SNEAK; + + this.bipedLeftLeg.rotationPointY = this.bipedRightLeg.rotationPointY = FRONT_LEG_RP_Y_SNEAK; } protected void ponySleep() { @@ -675,50 +680,55 @@ public class ModelPlayerPony extends AbstractPonyModel { } protected void initLegPositions(float yOffset, float stretch) { - int armWidth = this.smallArms ? 3 : 4; - float armY = this.smallArms ? 8.5f : 8f; - float armX = this.smallArms ? -2f : -3f; + int armWidth = smallArms ? 3 : 4; + float rarmY = smallArms ? 8.5f : 8; + float rarmX = smallArms ? 2 : 3; - this.bipedRightArm.addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, armWidth, 12, 4, stretch); - this.bipedLeftArm .addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, armWidth, 12, 4, stretch); + float armX = THIRDP_ARM_CENTRE_X - 2; + float armY = THIRDP_ARM_CENTRE_Y - 6; + float armZ = THIRDP_ARM_CENTRE_Z - 2; - this.bipedRightArm.setRotationPoint(armX, yOffset + armY, 0.0F); - this.bipedLeftArm .setRotationPoint(3.0F, yOffset + armY, 0.0F); + this.bipedLeftArm .addBox(armX, armY, armZ, armWidth, 12, 4, stretch); + this.bipedRightArm.addBox(armX, armY, armZ, armWidth, 12, 4, stretch); - this.bipedRightLeg.addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, 4, 12, 4, stretch); - this.bipedLeftLeg .addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, 4, 12, 4, stretch); + this.bipedLeftLeg .addBox(armX, armY, armZ, 4, 12, 4, stretch); + this.bipedRightLeg.addBox(armX, armY, armZ, 4, 12, 4, stretch); - this.bipedRightLeg.setRotationPoint(-3.0F, 0.0F + yOffset, 0.0F); + this.bipedLeftArm .setRotationPoint( rarmX, yOffset + rarmY, 0); + this.bipedRightArm.setRotationPoint(-rarmX, yOffset + rarmY, 0); + + this.bipedLeftLeg .setRotationPoint( rarmX, yOffset, 0); + this.bipedRightLeg.setRotationPoint(-rarmX, yOffset, 0); - this.unicornArmRight.addBox(-2.0F + FIRSTP_ARM_CENTRE_X, -6.0F + FIRSTP_ARM_CENTRE_Y, -2.0F + FIRSTP_ARM_CENTRE_Z, 4, 12, 4, stretch + .25f); - this.unicornArmLeft .addBox(-2.0F + FIRSTP_ARM_CENTRE_X, -6.0F + FIRSTP_ARM_CENTRE_Y, -2.0F + FIRSTP_ARM_CENTRE_Z, 4, 12, 4, stretch + .25f); - - this.unicornArmRight.setRotationPoint(-5.0F, 2.0F + yOffset, 0.0F); - this.unicornArmLeft .setRotationPoint(-5.0F, 2.0F + yOffset, 0.0F); - - if (bipedRightArmwear != null) { - this.bipedRightArmwear.addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, armWidth, 12, 4, stretch + 0.25f); - this.bipedRightArmwear.setRotationPoint(-3.0F, yOffset + armY, 0.0F); + if (bipedLeftArmwear != null) { + this.bipedLeftArmwear.addBox(armX, armY, armZ, 3, 12, 4, stretch + 0.25f); + this.bipedLeftArmwear.setRotationPoint(3, yOffset + rarmY, 0); } - if (bipedLeftArmwear != null) { - this.bipedLeftArmwear .addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, 3, 12, 4, stretch + 0.25f); - this.bipedLeftArmwear .setRotationPoint(3.0F, yOffset + armY, 0.0F); + if (bipedRightArmwear != null) { + this.bipedRightArmwear.addBox(armX, armY, armZ, armWidth, 12, 4, stretch + 0.25f); + this.bipedRightArmwear.setRotationPoint(-3, yOffset + rarmY, 0); + } + + if (this.bipedLeftLegwear != null) { + this.bipedLeftLegwear.addBox(armX, armY, armZ, 4, 12, 4, stretch + 0.25f); + this.bipedRightLegwear.setRotationPoint(3, yOffset, 0); } if (bipedRightLegwear != null) { - this.bipedRightLegwear.addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, 4, 12, 4, stretch + 0.25f); - this.bipedRightLegwear.setRotationPoint(-3.0F, 0.0F + yOffset, 0.0F); + this.bipedRightLegwear.addBox(armX, armY, armZ, 4, 12, 4, stretch + 0.25f); + this.bipedRightLegwear.setRotationPoint(-3, yOffset, 0); } - if (this.bipedLeftLegwear != null) { - this.bipedLeftLegwear.addBox(-2.0F + THIRDP_ARM_CENTRE_X, -6.0F + THIRDP_ARM_CENTRE_Y, -2.0F + THIRDP_ARM_CENTRE_Z, 4, 12, 4, stretch + 0.25f); - } + this.unicornArmLeft .addBox(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25f); + this.unicornArmRight.addBox(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25f); + + this.unicornArmLeft .setRotationPoint(5, yOffset + 2, 0); + this.unicornArmRight.setRotationPoint(-5, yOffset + 2, 0); } @Override public void renderCape(float scale) { this.bipedCape.render(scale); } - } diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java b/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java index a8fea8cc..c13f23f4 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java @@ -54,7 +54,6 @@ public class ModelSkeletonPony extends ModelMobPony { if (rightArmPose != ArmPose.EMPTY && !metadata.hasMagic()) { bipedRightArm.setRotationPoint(-1.5F, 9.5F, 4); } - } @Override diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java index 5656b0d7..9785eb4c 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java @@ -22,18 +22,18 @@ public class ModelZombiePony extends ModelMobPony { } @Override - protected void rotateRightArm(float var8, float var9, float move, float tick) { + protected void rotateRightArm(float move, float tick) { if (rightArmPose != ArmPose.EMPTY) return; if (isRight(move)) { - rotateArmHolding(bipedRightArm, 1, var8, var9, tick); + rotateArmHolding(bipedRightArm, 1, swingProgress, tick); } else { - rotateArmHolding(bipedLeftArm, -1, var8, var9, tick); + rotateArmHolding(bipedLeftArm, -1, swingProgress, tick); } } @Override - protected void rotateLeftArm(float var8, float var9, float move, float tick) { + protected void rotateLeftArm(float move, float tick) { } diff --git a/src/main/java/com/minelittlepony/pony/data/IPonyData.java b/src/main/java/com/minelittlepony/pony/data/IPonyData.java index f1f23d67..74756255 100644 --- a/src/main/java/com/minelittlepony/pony/data/IPonyData.java +++ b/src/main/java/com/minelittlepony/pony/data/IPonyData.java @@ -3,18 +3,36 @@ package com.minelittlepony.pony.data; import net.minecraft.client.resources.data.IMetadataSection; /** - * Dummy interface so gson won't go crazy + * Metadata for a pony. */ public interface IPonyData extends IMetadataSection { + /** + * Gets this pony's race. + */ PonyRace getRace(); + /** + * Gets the length of the pony's tail. + */ TailLengths getTail(); + /** + * Get the pony's gender (usually female). + */ PonyGender getGender(); + /** + * Gets the current pony size. + */ PonySize getSize(); + /** + * Gets the magical glow colour for magic-casting races. Returns 0 otherwise. + */ int getGlowColor(); + /** + * Returns true if and only if this metadata represents a pony that can cast magic. + */ boolean hasMagic(); } diff --git a/src/main/java/com/minelittlepony/pony/data/ITriggerPixelMapped.java b/src/main/java/com/minelittlepony/pony/data/ITriggerPixelMapped.java index 9ba53aa0..2e2e5925 100644 --- a/src/main/java/com/minelittlepony/pony/data/ITriggerPixelMapped.java +++ b/src/main/java/com/minelittlepony/pony/data/ITriggerPixelMapped.java @@ -1,9 +1,24 @@ package com.minelittlepony.pony.data; +/** + * Interface for enums that can be parsed from an image trigger pixel value. + * @author Chris Albers + * + * @param + */ public interface ITriggerPixelMapped & ITriggerPixelMapped> { - + /** + * Gets the pixel colour matching this enum value. + */ int getTriggerPixel(); + /** + * Gets the enum value corresponding to the given enum type and pixel value. + * If none are found, the first parameter is returned as the default. + * + * @param type Return type and default value. + * @param pixelValue The pixel colour to search for. + */ @SuppressWarnings("unchecked") public static & ITriggerPixelMapped> T getByTriggerPixel(T type, int pixelValue) { for (T i : (T[])type.getClass().getEnumConstants()) { diff --git a/src/main/java/com/minelittlepony/pony/data/PonyData.java b/src/main/java/com/minelittlepony/pony/data/PonyData.java index aa5e0ea0..7d6cf50b 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyData.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyData.java @@ -6,6 +6,11 @@ import com.minelittlepony.MineLittlePony; import java.awt.image.BufferedImage; import javax.annotation.concurrent.Immutable; + +/** + * Implementation for IPonyData. + * + */ @Immutable public class PonyData implements IPonyData { private final PonyRace race; @@ -71,6 +76,9 @@ public class PonyData implements IPonyData { .toString(); } + /** + * Parses an image buffer into a new IPonyData representing the values stored in it's individual trigger pixels. + */ static IPonyData parse(BufferedImage image) { return new PonyData(image); } diff --git a/src/main/java/com/minelittlepony/pony/data/PonyRace.java b/src/main/java/com/minelittlepony/pony/data/PonyRace.java index f7588831..de350c26 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyRace.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyRace.java @@ -29,22 +29,41 @@ public enum PonyRace implements ITriggerPixelMapped { this.model = model; } + /** + * Returns true if this pony has a horn (and by extension can cast magic). + * @return + */ public boolean hasHorn() { return horn; } + /** + * Returns true if this pony has wings. If it has wings, it can fly, of course. + */ public boolean hasWings() { return wings; } + /** + * Returns true if this is a human. + */ public boolean isHuman() { return this == HUMAN; } + /** + * Gets the model type associated with this species. + */ public PlayerModels getModel() { return model; } + /** + * Gets the actual race determined by the given pony level. + * PonyLevel.HUMANS would force all races to be humans. + * PonyLevel.BOTH is no change. + * PonyLevel.PONIES (should) return a pony if this is a human. Don't be fooled, though. It doesn't. + */ public PonyRace getEffectiveRace(PonyLevel level) { if (level == PonyLevel.HUMANS) return HUMAN; return this; diff --git a/src/main/java/com/minelittlepony/pony/data/TriggerPixels.java b/src/main/java/com/minelittlepony/pony/data/TriggerPixels.java index e1c42fca..57e79cb7 100644 --- a/src/main/java/com/minelittlepony/pony/data/TriggerPixels.java +++ b/src/main/java/com/minelittlepony/pony/data/TriggerPixels.java @@ -2,6 +2,10 @@ package com.minelittlepony.pony.data; import java.awt.image.BufferedImage; +/** + * Individual trigger pixels for a pony skin. + * + */ public enum TriggerPixels { RACE(PonyRace.HUMAN, 0, 0), TAIL(TailLengths.FULL, 1, 0), @@ -19,10 +23,20 @@ public enum TriggerPixels { this.y = y; } + /** + * Reads tis trigger pixel's value and returns the raw colour value. + * @param image Image to read + * @param mask Colour mask (0xffffff for rgb, -1 for rgba) + */ public int readColor(BufferedImage image, int mask) { return image.getRGB(x, y) & mask; } + /** + * Reads this trigger pixel's value and parses it to an Enum instance. + * + * @param image Image to read + */ @SuppressWarnings("unchecked") public & ITriggerPixelMapped> T readValue(BufferedImage image) { return ITriggerPixelMapped.getByTriggerPixel((T)def, readColor(image, 0xffffff)); diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyStrayOverlay.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyStrayOverlay.java index 88839f52..5c6df3b0 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyStrayOverlay.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyStrayOverlay.java @@ -16,7 +16,7 @@ public class LayerPonyStrayOverlay extends LayerOverlayBase { public LayerPonyStrayOverlay(RenderLivingBase render) { super(render); this.overlayModel = new ModelSkeletonPony(); - this.overlayModel.init(0F, 0.25F); + this.overlayModel.init(0, 0.25F); } @Override