Link the player's race to the race reported by their minelp skin

This commit is contained in:
Sollace 2018-09-24 21:37:50 +02:00
parent 38e7b8bc36
commit 9518c93e3f
4 changed files with 88 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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<MsgRequ
@Expose
public UUID senderId;
public MsgRequestCapabilities(EntityPlayer player) {
@Expose
public Race race;
public MsgRequestCapabilities(EntityPlayer player, Race preferredRace) {
senderId = player.getGameProfile().getId();
race = preferredRace;
}
@Override
@ -25,6 +30,8 @@ public class MsgRequestCapabilities implements IMessage, IMessageHandler<MsgRequ
System.out.println("[SERVER] Sending capabilities to player id " + senderId);
IPlayer player = PlayerSpeciesList.instance().getPlayer(senderId);
player.setPlayerSpecies(message.race);
channel.respond(new MsgPlayerCapabilities(player), senderId);
}
}