MineLittlePony/src/main/java/com/minelittlepony/MineLittlePony.java

226 lines
9.5 KiB
Java
Raw Normal View History

2016-11-17 05:45:04 +01:00
package com.minelittlepony;
2015-08-02 00:36:33 +02:00
import com.google.common.collect.Maps;
2016-11-17 05:45:04 +01:00
import com.minelittlepony.hdskins.gui.GuiSkinsMineLP;
2018-04-24 17:12:23 +02:00
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;
2016-01-26 09:20:39 +01:00
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;
2015-08-02 00:36:33 +02:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
2016-01-26 09:20:39 +01:00
import net.minecraft.client.renderer.entity.RenderManager;
2016-08-22 23:32:03 +02:00
import net.minecraft.client.resources.IReloadableResourceManager;
2016-11-24 08:01:23 +01:00
import net.minecraft.client.resources.data.MetadataSerializer;
2016-01-26 09:20:39 +01:00
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
2016-11-24 08:01:23 +01:00
import net.minecraft.entity.monster.EntityEvoker;
2018-04-12 16:21:19 +02:00
import net.minecraft.entity.monster.EntityGiantZombie;
2016-11-17 05:45:04 +01:00
import net.minecraft.entity.monster.EntityHusk;
import net.minecraft.entity.monster.EntityIllusionIllager;
2016-01-26 09:20:39 +01:00
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
2016-11-17 05:45:04 +01:00
import net.minecraft.entity.monster.EntityStray;
2016-11-17 05:45:04 +01:00
import net.minecraft.entity.monster.EntityVex;
2016-11-24 08:01:23 +01:00
import net.minecraft.entity.monster.EntityVindicator;
2016-11-17 05:45:04 +01:00
import net.minecraft.entity.monster.EntityWitherSkeleton;
2016-01-26 09:20:39 +01:00
import net.minecraft.entity.monster.EntityZombie;
2016-11-17 05:45:04 +01:00
import net.minecraft.entity.monster.EntityZombieVillager;
2016-01-26 09:20:39 +01:00
import net.minecraft.entity.passive.EntityVillager;
2016-11-25 05:40:19 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import java.util.Map;
2016-01-26 09:16:11 +01:00
public class MineLittlePony {
2016-11-25 05:40:19 +01:00
public static final Logger logger = LogManager.getLogger("MineLittlePony");
2016-01-26 09:20:39 +01:00
public static final String MOD_NAME = "Mine Little Pony";
public static final String MOD_VERSION = "@VERSION@";
2018-04-10 13:56:48 +02:00
@SuppressWarnings("unused")
private static final String SKIN_SERVER_URL = "minelpskins.voxelmodpack.com";
@SuppressWarnings("unused")
private static final String GATEWAY_URL = "minelpskinmanager.voxelmodpack.com";
2016-01-26 09:20:39 +01:00
private static final KeyBinding SETTINGS_GUI = new KeyBinding("Settings", Keyboard.KEY_F9, "Mine Little Pony");
private static MineLittlePony instance;
2015-08-02 00:36:33 +02:00
private PonyConfig config;
private PonyManager ponyManager;
private Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap();
2016-01-26 09:20:39 +01:00
MineLittlePony() {
instance = this;
}
void init() {
LiteLoader.getInput().registerKeyBinding(SETTINGS_GUI);
2015-08-02 00:36:33 +02:00
this.config = new PonyConfig();
this.ponyManager = new PonyManager(config);
2016-01-26 09:20:39 +01:00
LiteLoader.getInstance().registerExposable(config, null);
2016-08-22 23:32:03 +02:00
IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
irrm.registerReloadListener(this.ponyManager);
2016-11-24 08:01:23 +01:00
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");
2016-01-26 09:20:39 +01:00
}
void postInit(Minecraft minecraft) {
HDSkinManager manager = HDSkinManager.INSTANCE;
// manager.setSkinUrl(SKIN_SERVER_URL);
// manager.setGatewayURL(GATEWAY_URL);
2016-01-26 09:20:39 +01:00
manager.addSkinModifier(new PonySkinModifier());
// logger.info("Set MineLP skin server URL.");
2016-01-26 09:20:39 +01:00
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);
2018-04-12 16:21:19 +02:00
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<? extends Entity> cl) {
this.renderMap.put(cl, rm.getEntityClassRenderObject(cl));
}
@SuppressWarnings("unchecked")
private <T extends Entity> Render<T> getRenderer(Class<T> cl) {
Render<T> render = (Render<T>) this.renderMap.get(cl);
if (render == null) throw new MissingRendererException(cl);
return render;
}
public void initialisePlayerRenderers(RenderManager rm) {
2018-04-24 17:12:23 +02:00
new RenderPonyPlayer(rm, false, "pony", PMAPI.pony);
new RenderPonyPlayer(rm, true, "slimpony", PMAPI.ponySmall);
}
public void initializeMobRenderers(RenderManager rm) {
2016-01-26 09:20:39 +01:00
if (this.config.villagers) {
ModUtilities.addRenderer(EntityVillager.class, new RenderPonyVillager(rm));
2016-11-17 05:45:04 +01:00
ModUtilities.addRenderer(EntityZombieVillager.class, new RenderPonyZombieVillager(rm));
2016-11-25 05:40:19 +01:00
logger.info("Villagers are now ponies.");
} else {
ModUtilities.addRenderer(EntityVillager.class, getRenderer(EntityVillager.class));
ModUtilities.addRenderer(EntityZombieVillager.class, getRenderer(EntityZombieVillager.class));
2016-01-26 09:20:39 +01:00
}
if (this.config.zombies) {
2016-11-25 05:40:19 +01:00
ModUtilities.addRenderer(EntityZombie.class, new RenderPonyZombie<>(rm));
2016-11-17 05:45:04 +01:00
ModUtilities.addRenderer(EntityHusk.class, new RenderPonyZombie.Husk(rm));
2018-04-12 16:21:19 +02:00
ModUtilities.addRenderer(EntityGiantZombie.class, new RenderPonyZombie.Giant(rm));
2016-11-25 05:40:19 +01:00
logger.info("Zombies are now ponies.");
} else {
ModUtilities.addRenderer(EntityZombie.class, getRenderer(EntityZombie.class));
ModUtilities.addRenderer(EntityHusk.class, getRenderer(EntityHusk.class));
2018-04-12 16:21:19 +02:00
ModUtilities.addRenderer(EntityGiantZombie.class, getRenderer(EntityGiantZombie.class));
2016-01-26 09:20:39 +01:00
}
if (this.config.pigzombies) {
2016-08-22 23:32:03 +02:00
ModUtilities.addRenderer(EntityPigZombie.class, new RenderPonyPigman(rm));
2016-11-25 05:40:19 +01:00
logger.info("Zombie pigmen are now ponies.");
} else {
ModUtilities.addRenderer(EntityPigZombie.class, getRenderer(EntityPigZombie.class));
2016-01-26 09:20:39 +01:00
}
if (this.config.skeletons) {
2016-11-25 05:40:19 +01:00
ModUtilities.addRenderer(EntitySkeleton.class, new RenderPonySkeleton<>(rm));
2016-11-17 05:45:04 +01:00
ModUtilities.addRenderer(EntityStray.class, new RenderPonySkeleton.Stray(rm));
ModUtilities.addRenderer(EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(rm));
2016-11-25 05:40:19 +01:00
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));
2016-01-26 09:20:39 +01:00
}
2016-11-24 08:01:23 +01:00
2016-11-17 05:45:04 +01:00
if (this.config.illagers) {
ModUtilities.addRenderer(EntityVex.class, new RenderPonyVex(rm));
2016-11-24 08:01:23 +01:00
ModUtilities.addRenderer(EntityEvoker.class, new RenderPonyEvoker(rm));
ModUtilities.addRenderer(EntityVindicator.class, new RenderPonyVindicator(rm));
ModUtilities.addRenderer(EntityIllusionIllager.class, new RenderPonyIllusionIllager(rm));
2016-11-25 05:40:19 +01:00
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));
2016-11-17 05:45:04 +01:00
}
2016-01-26 09:20:39 +01:00
}
void onTick(Minecraft minecraft, boolean inGame) {
2016-01-26 09:20:39 +01:00
if (inGame && minecraft.currentScreen == null && SETTINGS_GUI.isPressed()) {
minecraft.displayGuiScreen(new PonySettingPanel());
}
boolean skins = minecraft.currentScreen instanceof GuiSkins
&& !(minecraft.currentScreen instanceof GuiSkinsMineLP);
if (skins) {
2016-01-26 09:20:39 +01:00
minecraft.displayGuiScreen(new GuiSkinsMineLP(ponyManager));
}
HDSkinManager.INSTANCE.setEnabled(config.hd);
2015-08-02 00:36:33 +02:00
}
2016-01-26 09:16:11 +01:00
public static MineLittlePony getInstance() {
return instance;
2015-08-02 00:36:33 +02:00
}
public PonyManager getManager() {
return ponyManager;
}
public static PonyConfig getConfig() {
2015-08-02 00:36:33 +02:00
return getInstance().config;
}
}