diff --git a/src/main/java/com/minelittlepony/MineLittlePony.java b/src/main/java/com/minelittlepony/MineLittlePony.java index 75dd042b..9e7e8f19 100644 --- a/src/main/java/com/minelittlepony/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/MineLittlePony.java @@ -1,5 +1,6 @@ package com.minelittlepony; +import com.google.common.collect.Maps; import com.minelittlepony.gui.PonySettingPanel; import com.minelittlepony.hdskins.gui.EntityPonyModel; import com.minelittlepony.hdskins.gui.GuiSkinsMineLP; @@ -17,10 +18,12 @@ import com.mumfrey.liteloader.util.ModUtilities; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.gui.GuiSkins; 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.EntityHusk; import net.minecraft.entity.monster.EntityPigZombie; @@ -36,6 +39,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; +import java.util.Map; + public class MineLittlePony { public static final Logger logger = LogManager.getLogger("MineLittlePony"); @@ -54,6 +59,8 @@ public class MineLittlePony { private PonyManager ponyManager; private ProxyContainer proxy; + private Map, Render> renderMap = Maps.newHashMap(); + MineLittlePony() { instance = this; } @@ -84,22 +91,63 @@ 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.initializeMobRenderers(rm); + + } + + private void saveCurrentRenderers(RenderManager rm) { + // villagers + this.renderMap.put(EntityVillager.class, rm.getEntityClassRenderObject(EntityVillager.class)); + this.renderMap.put(EntityZombieVillager.class, rm.getEntityClassRenderObject(EntityZombieVillager.class)); + // zombies + this.renderMap.put(EntityZombie.class, rm.getEntityClassRenderObject(EntityZombie.class)); + this.renderMap.put(EntityHusk.class, rm.getEntityClassRenderObject(EntityHusk.class)); + // pig zombie + this.renderMap.put(EntityPigZombie.class, rm.getEntityClassRenderObject(EntityPigZombie.class)); + // skeletons + this.renderMap.put(EntitySkeleton.class, rm.getEntityClassRenderObject(EntitySkeleton.class)); + this.renderMap.put(EntityStray.class, rm.getEntityClassRenderObject(EntityStray.class)); + this.renderMap.put(EntityWitherSkeleton.class, rm.getEntityClassRenderObject(EntityWitherSkeleton.class)); + // illagers + this.renderMap.put(EntityVex.class, rm.getEntityClassRenderObject(EntityVex.class)); + this.renderMap.put(EntityEvoker.class, rm.getEntityClassRenderObject(EntityEvoker.class)); + this.renderMap.put(EntityVindicator.class, rm.getEntityClassRenderObject(EntityVindicator.class)); + } + + @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 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)); logger.info("Zombies are now ponies."); + } else { + ModUtilities.addRenderer(EntityZombie.class, getRenderer(EntityZombie.class)); + ModUtilities.addRenderer(EntityHusk.class, getRenderer(EntityHusk.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) { @@ -107,6 +155,10 @@ public class MineLittlePony { 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) { @@ -114,8 +166,11 @@ public class MineLittlePony { ModUtilities.addRenderer(EntityEvoker.class, new RenderPonyEvoker(rm)); ModUtilities.addRenderer(EntityVindicator.class, new RenderPonyVindicator(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)); } - } void onTick(Minecraft minecraft, boolean inGame) { diff --git a/src/main/java/com/minelittlepony/MissingRendererException.java b/src/main/java/com/minelittlepony/MissingRendererException.java new file mode 100644 index 00000000..34117e18 --- /dev/null +++ b/src/main/java/com/minelittlepony/MissingRendererException.java @@ -0,0 +1,8 @@ +package com.minelittlepony; + +public class MissingRendererException extends RuntimeException { + + public MissingRendererException(Class cl) { + super("Could not find a renderer for " + cl.getName() + ". This is a bug."); + } +} diff --git a/src/main/java/com/minelittlepony/gui/PonySettingPanel.java b/src/main/java/com/minelittlepony/gui/PonySettingPanel.java index f6414038..8c7fecc0 100644 --- a/src/main/java/com/minelittlepony/gui/PonySettingPanel.java +++ b/src/main/java/com/minelittlepony/gui/PonySettingPanel.java @@ -177,5 +177,6 @@ public class PonySettingPanel extends GuiScreen { @Override public void onGuiClosed() { LiteLoader.getInstance().writeConfig(config); + MineLittlePony.getInstance().initializeMobRenderers(mc.getRenderManager()); } } diff --git a/src/main/resources/assets/minelittlepony/lang/en_us.lang b/src/main/resources/assets/minelittlepony/lang/en_us.lang index b5c540e4..0e6ae0ee 100644 --- a/src/main/resources/assets/minelittlepony/lang/en_us.lang +++ b/src/main/resources/assets/minelittlepony/lang/en_us.lang @@ -1,5 +1,3 @@ -minelp.restart=If you make any changes here, you must restart Minecraft before they will take effect! - minelp.options.title=Mine Little Pony Settings minelp.options.ponylevel=Pony Level minelp.options.ponylevel.ponies=Ponies Only diff --git a/src/main/resources/assets/minelittlepony/lang/fr_fr.lang b/src/main/resources/assets/minelittlepony/lang/fr_fr.lang index 280e903a..ec61b39f 100644 --- a/src/main/resources/assets/minelittlepony/lang/fr_fr.lang +++ b/src/main/resources/assets/minelittlepony/lang/fr_fr.lang @@ -1,7 +1,5 @@ # Mine Little Pony fr_FR.lang file # Provided by Dalfio (PinkishPie) -minelp.restart=Si vous apportez des modifications ici, vous devez redιmarrer Minecraft avant qu'ils prennent effet! - minelp.options.title=Options Mine Little Pony minelp.options.ponylevel=Niveau Poney minelp.options.ponylevel.ponies=Seuls Poneys diff --git a/src/main/resources/assets/minelittlepony/lang/ru_ru.lang b/src/main/resources/assets/minelittlepony/lang/ru_ru.lang index 9d920a03..21b603a6 100644 --- a/src/main/resources/assets/minelittlepony/lang/ru_ru.lang +++ b/src/main/resources/assets/minelittlepony/lang/ru_ru.lang @@ -1,4 +1,3 @@ -minelp.restart=Если Π²Ρ‹ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚Π΅ эти ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹, Ρ‚ΠΎ для ΠΈΡ… Π°ΠΊΡ‚ΠΈΠ²Π°Ρ†ΠΈΠΈ Π²Ρ‹ Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΏΠ΅Ρ€Π΅Π·Π°ΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ ΠΈΠ³Ρ€Ρƒ! minelp.options.title=Настроайки ΠΌΠΎΠ΄Π° Mine Little Pony minelp.options.ponylevel=Π£Ρ€ΠΎΠ²Π΅Π½ΡŒ ΠΏΠΎΠ½ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ minelp.options.ponylevel.ponies=Волько ΠΏΠΎΠ½ΠΈ