Reimplement Daring Doo (STEVE) / Night Guard (ALEX)

This commit is contained in:
Sollace 2018-04-26 15:56:36 +02:00
parent 3dbedc3a5b
commit d6c5e2bd0b
3 changed files with 28 additions and 29 deletions

View file

@ -9,7 +9,9 @@ import com.minelittlepony.model.PMAPI;
import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyLevel; import com.minelittlepony.pony.data.PonyLevel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManager;
@ -75,13 +77,16 @@ public class PonyManager implements IResourceManagerReloadListener {
* @param player the player * @param player the player
*/ */
public Pony getPony(AbstractClientPlayer player) { public Pony getPony(AbstractClientPlayer player) {
Pony pony = getPony(player.getLocationSkin(), IPlayerInfo.getPlayerInfo(player).usesSlimArms()); return getPony(IPlayerInfo.getPlayerInfo(player).unwrap());
if (config.getPonyLevel() == PonyLevel.PONIES && pony.getMetadata().getRace().isHuman()) {
return getBackgroundPony(player.getUniqueID());
} }
return pony; public Pony getPony(NetworkPlayerInfo playerInfo) {
ResourceLocation skin = playerInfo.getLocationSkin();
UUID uuid = playerInfo.getGameProfile().getId();
if (skin == null) return getDefaultPony(uuid);
return getPony(skin, uuid);
} }
/** /**
@ -118,14 +123,20 @@ public class PonyManager implements IResourceManagerReloadListener {
} }
private Pony getBackgroundPony(UUID uuid) { private Pony getBackgroundPony(UUID uuid) {
if (getNumberOfPonies() == 0) return getPony(getDefaultSkin(uuid), isSlimSkin(uuid)); if (getNumberOfPonies() == 0 || isUser(uuid)) {
return getPony(getDefaultSkin(uuid), isSlimSkin(uuid));
}
int bgi = uuid.hashCode() % this.getNumberOfPonies(); int bgi = uuid.hashCode() % getNumberOfPonies();
while (bgi < 0) bgi += this.getNumberOfPonies(); while (bgi < 0) bgi += getNumberOfPonies();
return getPony(backgroundPonyList.get(bgi), false); return getPony(backgroundPonyList.get(bgi), false);
} }
private boolean isUser(UUID uuid) {
return Minecraft.getMinecraft().player != null && Minecraft.getMinecraft().player.getUniqueID().equals(uuid);
}
/** /**
* De-registers a pony from the cache. * De-registers a pony from the cache.
*/ */
@ -164,7 +175,7 @@ public class PonyManager implements IResourceManagerReloadListener {
* Returns true if the given uuid is of a player would would use the ALEX skin type. * Returns true if the given uuid is of a player would would use the ALEX skin type.
*/ */
public static boolean isSlimSkin(UUID uuid) { public static boolean isSlimSkin(UUID uuid) {
return (uuid.hashCode() & 1) == 1; return false;//(uuid.hashCode() & 1) == 1;
} }
private int getNumberOfPonies() { private int getNumberOfPonies() {

View file

@ -1,16 +1,10 @@
package com.minelittlepony.ducks; package com.minelittlepony.ducks;
import com.minelittlepony.pony.data.Pony;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
public interface IPlayerInfo { 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. * Returns true if the vanilla skin (the one returned by NetworkPlayerInfo.getSkinLocation) uses the ALEX model type.
*/ */
@ -22,4 +16,8 @@ public interface IPlayerInfo {
public static IPlayerInfo getPlayerInfo(AbstractClientPlayer player) { public static IPlayerInfo getPlayerInfo(AbstractClientPlayer player) {
return (IPlayerInfo)Minecraft.getMinecraft().getConnection().getPlayerInfo(player.getUniqueID()); return (IPlayerInfo)Minecraft.getMinecraft().getConnection().getPlayerInfo(player.getUniqueID());
} }
default NetworkPlayerInfo unwrap() {
return (NetworkPlayerInfo)this;
}
} }

View file

@ -9,7 +9,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyManager; import com.minelittlepony.PonyManager;
import com.minelittlepony.ducks.IPlayerInfo; import com.minelittlepony.ducks.IPlayerInfo;
import com.minelittlepony.pony.data.Pony;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.network.NetworkPlayerInfo;
@ -29,16 +28,7 @@ public abstract class MixinNetworkPlayerInfo implements IPlayerInfo {
@Inject(method = "getSkinType()Ljava/lang/String;", at = @At("RETURN"), cancellable = true) @Inject(method = "getSkinType()Ljava/lang/String;", at = @At("RETURN"), cancellable = true)
private void getSkinType(CallbackInfoReturnable<String> info) { private void getSkinType(CallbackInfoReturnable<String> info) {
info.setReturnValue(getPony().getRace(false).getModel().getId(usesSlimArms())); info.setReturnValue(MineLittlePony.getInstance().getManager().getPony(unwrap()).getRace(false).getModel().getId(usesSlimArms()));
}
@Override
public Pony getPony() {
ResourceLocation skin = getLocationSkin();
if (skin == null) {
return MineLittlePony.getInstance().getManager().getDefaultPony(getGameProfile().getId());
}
return MineLittlePony.getInstance().getManager().getPony(skin, getGameProfile().getId());
} }
@Override @Override