diff --git a/src/main/java/com/minelittlepony/unicopia/MineLP.java b/src/main/java/com/minelittlepony/unicopia/MineLP.java new file mode 100644 index 00000000..3af15158 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/MineLP.java @@ -0,0 +1,23 @@ +package com.minelittlepony.unicopia; + +import com.minelittlepony.MineLittlePony; + +public final class MineLP { + private static boolean checkComplete; + private static boolean modIsActive; + + /** + * Returns true if mine little pony is present. That's all we need. + */ + public static boolean modIsActive() { + if (!checkComplete) { + try { + MineLittlePony.getConfig(); + modIsActive = true; + } catch (Exception e) { + modIsActive = false; + } + } + return modIsActive; + } +} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/Race.java b/src/main/java/com/minelittlepony/unicopia/Race.java index df8c30b3..947edae7 100644 --- a/src/main/java/com/minelittlepony/unicopia/Race.java +++ b/src/main/java/com/minelittlepony/unicopia/Race.java @@ -4,8 +4,11 @@ import java.util.HashMap; import java.util.Map; import com.google.common.base.Strings; +import com.minelittlepony.pony.data.PonyRace; import net.minecraft.client.resources.I18n; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public enum Race { HUMAN(false, false, false), @@ -80,6 +83,31 @@ public enum Race { return def; } + @SideOnly(Side.CLIENT) + public static Race fromPonyRace(PonyRace ponyRace) { + switch (ponyRace) { + case ALICORN: + return ALICORN; + case CHANGELING: + case REFORMED_CHANGELING: + return CHANGELING; + case ZEBRA: + case EARTH: + return EARTH; + case GRIFFIN: + case HIPPOGRIFF: + case PEGASUS: + case BATPONY: + return PEGASUS; + case SEAPONY: + case UNICORN: + return UNICORN; + default: + return HUMAN; + + } + } + public static Race fromId(int id) { return raceIdMap.getOrDefault(id, HUMAN); } diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index fb60d2b0..d5399520 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -42,6 +42,7 @@ import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.power.PowersRegistry; +import com.minelittlepony.pony.data.IPony; import come.minelittlepony.unicopia.forgebullshit.FBS; @@ -57,6 +58,16 @@ public class Unicopia { public static int MAGIC_PARTICLE; public static int RAIN_PARTICLE; + /** + * The race preferred by the client - as determined by mine little pony. + * Human if minelp was not installed. + * + * This is not neccessarily the _actual_ race used for the player, + * as the server may not allow certain race types, or the player may override + * this option in-game themselves. + */ + private static Race clientPlayerRace = getclientPlayerRace(); + @EventHandler public void preInit(FMLPreInitializationEvent event) { if (UClient.isClientSide()) { @@ -64,10 +75,19 @@ public class Unicopia { } } + @SideOnly(Side.CLIENT) + private static Race getclientPlayerRace() { + if (Minecraft.getMinecraft().player != null && MineLP.modIsActive()) { + return Race.fromPonyRace(IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false)); + } + + return Race.HUMAN; + } + @EventHandler public void init(FMLInitializationEvent event) { channel = JumpingCastle.subscribeTo(MODID, () -> { - channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER); + channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER); }) .listenFor(MsgRequestCapabilities.class) .listenFor(MsgPlayerCapabilities.class) @@ -111,6 +131,14 @@ public class Unicopia { @SideOnly(Side.CLIENT) @SubscribeEvent public static void onGameTick(TickEvent.ClientTickEvent event) { + Race newRace = getclientPlayerRace(); + + if (newRace != clientPlayerRace) { + clientPlayerRace = newRace; + + channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER); + } + if (event.phase == Phase.END) { Keyboard.getKeyHandler().onKeyInput(); } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java index 3ce8e574..56732e28 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java @@ -6,6 +6,7 @@ import com.google.gson.annotations.Expose; import com.minelittlepony.jumpingcastle.api.IChannel; import com.minelittlepony.jumpingcastle.api.IMessage; import com.minelittlepony.jumpingcastle.api.IMessageHandler; +import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.PlayerSpeciesList; @@ -16,8 +17,12 @@ public class MsgRequestCapabilities implements IMessage, IMessageHandler