diff --git a/gradle.properties b/gradle.properties index 23445d66..9e5c3b33 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,5 +22,5 @@ org.gradle.daemon=false # Dependencies modmenu_version=5.0.0-alpha.3 kirin_version=1.13.0-beta.3 - hd_skins_version=6.7.0-beta.2 + hd_skins_version=6.7.0-beta.3 mson_version=1.7.0-beta.1 diff --git a/skins b/skins index 203739b1..33af7293 160000 --- a/skins +++ b/skins @@ -1 +1 @@ -Subproject commit 203739b11aa6ab379e59b65bf4b320ab3d04755a +Subproject commit 33af729369727ca03bf3883eda578dd5b2ced219 diff --git a/src/main/java/com/minelittlepony/api/model/IPegasus.java b/src/main/java/com/minelittlepony/api/model/IPegasus.java index 85998628..453044c2 100644 --- a/src/main/java/com/minelittlepony/api/model/IPegasus.java +++ b/src/main/java/com/minelittlepony/api/model/IPegasus.java @@ -1,5 +1,6 @@ package com.minelittlepony.api.model; +import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.client.MineLittlePony; public interface IPegasus extends IModel { @@ -12,6 +13,11 @@ public interface IPegasus extends IModel { && (MineLittlePony.getInstance().getConfig().flappyElytras.get() || !getAttributes().isGliding); } + + default boolean isBurdened() { + return isWearing(Wearable.SADDLE_BAGS_BOTH) || isWearing(Wearable.SADDLE_BAGS_LEFT) || isWearing(Wearable.SADDLE_BAGS_RIGHT); + } + /** * Gets the wings of this pegasus/flying creature */ diff --git a/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java b/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java new file mode 100644 index 00000000..bdd4b331 --- /dev/null +++ b/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java @@ -0,0 +1,20 @@ +package com.minelittlepony.api.pony; + +import net.minecraft.util.Identifier; + +import java.util.HashMap; +import java.util.Map; + +public final class DefaultPonySkinHelper { + public static final Identifier STEVE = new Identifier("minelittlepony", "textures/entity/player/wide/steve_pony.png"); + + private static final Map SKINS = new HashMap<>(); + + public static Identifier getPonySkin(Identifier original) { + return SKINS.computeIfAbsent(original, DefaultPonySkinHelper::computePonySkin); + } + + private static Identifier computePonySkin(Identifier original) { + return new Identifier("minelittlepony", original.getPath().replace(".png", "_pony.png")); + } +} diff --git a/src/main/java/com/minelittlepony/api/pony/IPonyManager.java b/src/main/java/com/minelittlepony/api/pony/IPonyManager.java index b3e18854..1d0e8b7e 100644 --- a/src/main/java/com/minelittlepony/api/pony/IPonyManager.java +++ b/src/main/java/com/minelittlepony/api/pony/IPonyManager.java @@ -14,10 +14,6 @@ import java.util.UUID; * */ public interface IPonyManager { - - Identifier STEVE = new Identifier("minelittlepony", "textures/entity/steve_pony.png"); - Identifier ALEX = new Identifier("minelittlepony", "textures/entity/alex_pony.png"); - /** * Gets a pony representation of the passed in entity. * @@ -48,17 +44,10 @@ public interface IPonyManager { * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. * * @param resource A texture resource - * @param uuid id of a player or entity + * @param uuid id of a player */ IPony getPony(Identifier resource, UUID uuid); - /** - * Gets the default pony. Either STEVE/ALEX, or a background pony based on client settings. - * - * @param uuid id of a player or entity - */ - IPony getDefaultPony(UUID uuid); - /** * Gets a random background pony determined by the given uuid. * @@ -73,16 +62,5 @@ public interface IPonyManager { */ void removePony(Identifier resource); - static Identifier getDefaultSkin(UUID uuid) { - return isSlimSkin(uuid) ? ALEX : STEVE; - } - - /** - * Returns true if the given uuid is of a player would would use the ALEX skin type. - */ - static boolean isSlimSkin(UUID uuid) { - return (uuid.hashCode() & 1) == 1; - } - interface ForcedPony {} } diff --git a/src/main/java/com/minelittlepony/api/pony/meta/TriggerPixel.java b/src/main/java/com/minelittlepony/api/pony/meta/TriggerPixel.java index a263e23b..42c27c70 100644 --- a/src/main/java/com/minelittlepony/api/pony/meta/TriggerPixel.java +++ b/src/main/java/com/minelittlepony/api/pony/meta/TriggerPixel.java @@ -7,6 +7,8 @@ import com.minelittlepony.api.pony.TriggerPixelType; import com.minelittlepony.api.pony.TriggerPixelValue; import com.minelittlepony.common.util.Color; +import java.util.Arrays; + /** * Individual trigger pixels for a pony skin. * @@ -27,6 +29,10 @@ public enum TriggerPixel { TriggerPixelType def; + private static final TriggerPixel[] VALUES = values(); + private static final int MAX_READ_X = Arrays.stream(VALUES).mapToInt(i -> i.x).max().getAsInt(); + private static final int MAX_READ_Y = Arrays.stream(VALUES).mapToInt(i -> i.y).max().getAsInt(); + TriggerPixel(TriggerPixelType def, Channel channel, int x, int y) { this.def = def; this.channel = channel; @@ -81,6 +87,10 @@ public enum TriggerPixel { out[value.ordinal()] |= value != def; } + public static boolean isTriggerPixelCoord(int x, int y) { + return x <= MAX_READ_X && y <= MAX_READ_Y; + } + enum Channel { RAW (0xFFFFFFFF, 0), ALL (0x00FFFFFF, 0), diff --git a/src/main/java/com/minelittlepony/api/pony/meta/Wearable.java b/src/main/java/com/minelittlepony/api/pony/meta/Wearable.java index 71286cf0..46d89aff 100644 --- a/src/main/java/com/minelittlepony/api/pony/meta/Wearable.java +++ b/src/main/java/com/minelittlepony/api/pony/meta/Wearable.java @@ -7,13 +7,15 @@ import java.util.ArrayList; import java.util.List; public enum Wearable implements TriggerPixelType { - NONE (0x00), - CROWN (0x16), - MUFFIN (0x32), - HAT (0x64), - ANTLERS (0x96), - SADDLE_BAGS (0xC8), - STETSON (0xFA); + NONE (0x00), + CROWN (0x16), + MUFFIN (0x32), + HAT (0x64), + ANTLERS (0x96), + SADDLE_BAGS_LEFT (0xC6), + SADDLE_BAGS_RIGHT (0xC7), + SADDLE_BAGS_BOTH (0xC8), + STETSON (0xFA); private int triggerValue; @@ -26,6 +28,10 @@ public enum Wearable implements TriggerPixelType { return triggerValue; } + public boolean isSaddlebags() { + return this == SADDLE_BAGS_BOTH || this == SADDLE_BAGS_LEFT || this == SADDLE_BAGS_RIGHT; + } + @Override public int getChannelAdjustedColorCode() { return triggerValue == 0 ? 0 : Color.argbToHex(255, triggerValue, triggerValue, triggerValue); diff --git a/src/main/java/com/minelittlepony/client/SkinsProxy.java b/src/main/java/com/minelittlepony/client/SkinsProxy.java index dcdfee4c..4b7df9d9 100644 --- a/src/main/java/com/minelittlepony/client/SkinsProxy.java +++ b/src/main/java/com/minelittlepony/client/SkinsProxy.java @@ -42,7 +42,7 @@ public class SkinsProxy { } public Identifier getSeaponySkin(EquineRenderManager> manager, AbstractClientPlayerEntity player) { - return manager.getPony(player).texture(); + return manager.getTexture(player); } } diff --git a/src/main/java/com/minelittlepony/client/hdskins/PonyPreview.java b/src/main/java/com/minelittlepony/client/hdskins/PonyPreview.java index 89951e04..7df40774 100644 --- a/src/main/java/com/minelittlepony/client/hdskins/PonyPreview.java +++ b/src/main/java/com/minelittlepony/client/hdskins/PonyPreview.java @@ -13,6 +13,7 @@ import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.common.client.gui.dimension.Bounds; import com.minelittlepony.hdskins.client.dummy.*; import com.minelittlepony.hdskins.profile.SkinType; +import com.minelittlepony.settings.PonyLevel; import java.util.List; import java.util.Optional; @@ -30,15 +31,17 @@ class PonyPreview extends PlayerPreview { } @Override - public Identifier getBlankSkin(SkinType type, boolean slim) { - if (type == SkinType.SKIN) { - return slim ? NO_SKIN_ALEX_PONY : NO_SKIN_STEVE_PONY; + public Identifier getDefaultSkin(SkinType type, boolean slim) { + if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { + if (type == SkinType.SKIN) { + return slim ? NO_SKIN_ALEX_PONY : NO_SKIN_STEVE_PONY; + } } if (type == MineLPHDSkins.seaponySkinType) { return NO_SKIN_SEAPONY; } - return super.getBlankSkin(type, slim); + return super.getDefaultSkin(type, slim); } @Override diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java b/src/main/java/com/minelittlepony/client/mixin/MixinDefaultSkinHelper.java similarity index 63% rename from src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java rename to src/main/java/com/minelittlepony/client/mixin/MixinDefaultSkinHelper.java index d8f2db22..f440cb67 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinDefaultSkinHelper.java @@ -1,6 +1,6 @@ package com.minelittlepony.client.mixin; -import com.minelittlepony.api.pony.IPonyManager; +import com.minelittlepony.api.pony.DefaultPonySkinHelper; import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.settings.PonyLevel; @@ -14,35 +14,34 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.UUID; @Mixin(DefaultSkinHelper.class) -abstract class MixinDefaultPlayerSkin { +abstract class MixinDefaultSkinHelper { @Inject(method = "getTexture()Lnet/minecraft/util/Identifier;", at = @At("HEAD"), cancellable = true) - private static void legacySkin(CallbackInfoReturnable cir) { + private static void onGetTexture(CallbackInfoReturnable cir) { if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { - cir.setReturnValue(IPonyManager.STEVE); + cir.setReturnValue(DefaultPonySkinHelper.getPonySkin(cir.getReturnValue())); } } @Inject(method = "getTexture(Ljava/util/UUID;)Lnet/minecraft/util/Identifier;", - at = @At("HEAD"), + at = @At("RETURN"), cancellable = true) - private static void defaultSkin(UUID uuid, CallbackInfoReturnable cir) { + private static void onGetTexture(UUID uuid, CallbackInfoReturnable cir) { if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { - cir.setReturnValue(IPonyManager.getDefaultSkin(uuid)); + cir.setReturnValue(DefaultPonySkinHelper.getPonySkin(cir.getReturnValue())); } } @Inject(method = "getModel(Ljava/util/UUID;)Ljava/lang/String;", - at = @At("HEAD"), + at = @At("RETURN"), cancellable = true) - private static void skinType(UUID uuid, CallbackInfoReturnable cir) { + private static void onGetModel(UUID uuid, CallbackInfoReturnable cir) { if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { - cir.setReturnValue(MineLittlePony.getInstance().getManager() - .getPony(IPonyManager.getDefaultSkin(uuid), uuid) + .getPony(DefaultSkinHelper.getTexture(uuid), uuid) .race() - .getModelId(IPonyManager.isSlimSkin(uuid))); + .getModelId("slim".equalsIgnoreCase(cir.getReturnValue()))); } } } diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinFirstPersonRenderer.java b/src/main/java/com/minelittlepony/client/mixin/MixinHeldItemRenderer.java similarity index 98% rename from src/main/java/com/minelittlepony/client/mixin/MixinFirstPersonRenderer.java rename to src/main/java/com/minelittlepony/client/mixin/MixinHeldItemRenderer.java index ba05ccf8..df509dd5 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinFirstPersonRenderer.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinHeldItemRenderer.java @@ -18,7 +18,7 @@ import net.minecraft.world.World; import net.minecraft.client.render.item.ItemRenderer; @Mixin(HeldItemRenderer.class) -abstract class MixinFirstPersonRenderer { +abstract class MixinHeldItemRenderer { private static final String LivingEntity = "Lnet/minecraft/entity/LivingEntity;"; private static final String MatrixStack = "Lnet/minecraft/client/util/math/MatrixStack;"; private static final String ItemStack = "Lnet/minecraft/item/ItemStack;"; diff --git a/src/main/java/com/minelittlepony/client/model/ModelType.java b/src/main/java/com/minelittlepony/client/model/ModelType.java index e2828f97..e4106d42 100644 --- a/src/main/java/com/minelittlepony/client/model/ModelType.java +++ b/src/main/java/com/minelittlepony/client/model/ModelType.java @@ -56,7 +56,7 @@ public final class ModelType { public static final ModelKey> ARMOUR_OUTER = register("armour_outer", PonyArmourModel::new); public static final ModelKey STETSON = registerGear("stetson", Wearable.STETSON, Stetson::new); - public static final ModelKey SADDLEBAGS = registerGear("saddlebags", Wearable.SADDLE_BAGS, SaddleBags::new); + public static final ModelKey SADDLEBAGS = registerGear("saddlebags", Wearable.SADDLE_BAGS_BOTH, SaddleBags::new); public static final ModelKey CROWN = registerGear("crown", Wearable.CROWN, Crown::new); public static final ModelKey MUFFIN = registerGear("muffin", Wearable.MUFFIN, Muffin::new); public static final ModelKey WITCH_HAT = registerGear("witch_hat", Wearable.HAT, WitchHat::new); diff --git a/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java b/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java index e39e690a..0a11a4ad 100644 --- a/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java +++ b/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java @@ -60,6 +60,9 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants { leftBag.roll = bodySwing; rightBag.roll = -bodySwing; + leftBag.visible = model.isWearing(Wearable.SADDLE_BAGS_BOTH) || model.isWearing(Wearable.SADDLE_BAGS_LEFT); + rightBag.visible = model.isWearing(Wearable.SADDLE_BAGS_BOTH) || model.isWearing(Wearable.SADDLE_BAGS_RIGHT); + dropAmount = hangLow ? 0.15F : 0; dropAmount = model.getMetadata().getInterpolator(interpolatorId).interpolate("dropAmount", dropAmount, 3); } @@ -73,16 +76,22 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants { stack.push(); stack.translate(0, dropAmount, 0); + if (!rightBag.visible || !leftBag.visible) { + stack.translate(0, 0.3F, -0.3F); + } + leftBag.render(stack, renderContext, overlayUv, lightUv, red, green, blue, alpha); rightBag.render(stack, renderContext, overlayUv, lightUv, red, green, blue, alpha); stack.pop(); - strap.render(stack, renderContext, overlayUv, lightUv, red, green, blue, alpha); + if (leftBag.visible && rightBag.visible) { + strap.render(stack, renderContext, overlayUv, lightUv, red, green, blue, alpha); + } } @Override public boolean canRender(IModel model, Entity entity) { - return model.isWearing(Wearable.SADDLE_BAGS); + return model.isWearing(Wearable.SADDLE_BAGS_BOTH) || model.isWearing(Wearable.SADDLE_BAGS_LEFT) || model.isWearing(Wearable.SADDLE_BAGS_RIGHT); } @Override @@ -92,6 +101,6 @@ public class SaddleBags extends AbstractGear implements PonyModelConstants { @Override public Identifier getTexture(T entity, Context context) { - return context.getDefaultTexture(entity, Wearable.SADDLE_BAGS); + return context.getDefaultTexture(entity, Wearable.SADDLE_BAGS_BOTH); } } diff --git a/src/main/java/com/minelittlepony/client/model/part/PegasusWings.java b/src/main/java/com/minelittlepony/client/model/part/PegasusWings.java index 7f91fc7c..b3cd692c 100644 --- a/src/main/java/com/minelittlepony/client/model/part/PegasusWings.java +++ b/src/main/java/com/minelittlepony/client/model/part/PegasusWings.java @@ -40,7 +40,7 @@ public class PegasusWings implements IPart, MsonMode } public Wing getRight() { - return pegasus.isWearing(Wearable.SADDLE_BAGS) ? legacyWing : rightWing; + return pegasus.isBurdened() ? legacyWing : rightWing; } @Override @@ -66,7 +66,7 @@ public class PegasusWings implements IPart, MsonMode if (pegasus.wingsAreOpen()) { flapAngle = pegasus.getWingRotationFactor(ticks); - if (!pegasus.getAttributes().isCrouching && pegasus.isWearing(Wearable.SADDLE_BAGS)) { + if (!pegasus.getAttributes().isCrouching && pegasus.isBurdened()) { flapAngle -= 1F; } } else { @@ -118,7 +118,7 @@ public class PegasusWings implements IPart, MsonMode if (pegasus.wingsAreOpen()) { extended.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha); } else { - boolean bags = pegasus.isWearing(Wearable.SADDLE_BAGS); + boolean bags = pegasus.isWearing(Wearable.SADDLE_BAGS_BOTH); if (bags) { stack.push(); stack.translate(0, 0, 0.198F); diff --git a/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java b/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java deleted file mode 100644 index 93d7ec35..00000000 --- a/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.minelittlepony.client.pony; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; - -import com.minelittlepony.api.pony.IPonyManager; -import com.minelittlepony.client.MineLittlePony; -import com.minelittlepony.util.MathUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * All currently loaded background ponies. - */ -class BackgroundPonyList { - /** - * All currently loaded background ponies. - */ - private final List backgroundPonyList = new ArrayList<>(); - - private final Identifier id; - - public BackgroundPonyList(Identifier id) { - this.id = id; - reloadAll(MinecraftClient.getInstance().getResourceManager()); - } - - public Identifier getId(UUID uuid) { - if (backgroundPonyList.isEmpty() || isUser(uuid)) { - return IPonyManager.getDefaultSkin(uuid); - } - - int bgi = MathUtil.mod(uuid.hashCode(), backgroundPonyList.size()); - - return backgroundPonyList.get(bgi); - } - - public void reloadAll(ResourceManager resourceManager) { - backgroundPonyList.clear(); - backgroundPonyList.addAll(resourceManager.findResources(id.getPath(), path -> path.getPath().endsWith(".png")).keySet()); - MineLittlePony.logger.info("Detected {} ponies installed at {}.", backgroundPonyList.size(), id); - } - - static boolean isUser(UUID uuid) { - return MinecraftClient.getInstance().player != null - && MinecraftClient.getInstance().player.getUuid().equals(uuid); - } -} diff --git a/src/main/java/com/minelittlepony/client/pony/NativePonyData.java b/src/main/java/com/minelittlepony/client/pony/NativePonyData.java index a4ed0498..27c9ec35 100644 --- a/src/main/java/com/minelittlepony/client/pony/NativePonyData.java +++ b/src/main/java/com/minelittlepony/client/pony/NativePonyData.java @@ -57,7 +57,7 @@ class NativePonyData implements IPonyData { @Override public Race getRace() { - return race.getValue(); + return PonyConfig.getEffectiveRace(race.getValue()); } @Override @@ -92,7 +92,7 @@ class NativePonyData implements IPonyData { @Override public boolean hasHorn() { - return getRace() != null && PonyConfig.getEffectiveRace(getRace()).hasHorn(); + return getRace().hasHorn(); } @Override diff --git a/src/main/java/com/minelittlepony/client/pony/PonyData.java b/src/main/java/com/minelittlepony/client/pony/PonyData.java index 036f1ea3..224ad9d1 100644 --- a/src/main/java/com/minelittlepony/client/pony/PonyData.java +++ b/src/main/java/com/minelittlepony/client/pony/PonyData.java @@ -99,7 +99,7 @@ public class PonyData implements IPonyData { @Override public Race getRace() { - return race; + return PonyConfig.getEffectiveRace(race); } @Override @@ -134,7 +134,7 @@ public class PonyData implements IPonyData { @Override public boolean hasHorn() { - return getRace() != null && PonyConfig.getEffectiveRace(getRace()).hasHorn(); + return getRace().hasHorn(); } @Override diff --git a/src/main/java/com/minelittlepony/client/pony/PonyManager.java b/src/main/java/com/minelittlepony/client/pony/PonyManager.java index 9533e827..e3bec42d 100644 --- a/src/main/java/com/minelittlepony/client/pony/PonyManager.java +++ b/src/main/java/com/minelittlepony/client/pony/PonyManager.java @@ -4,7 +4,6 @@ import com.google.common.cache.*; import com.minelittlepony.api.pony.IPony; import com.minelittlepony.api.pony.IPonyManager; import com.minelittlepony.client.MineLittlePony; -import com.minelittlepony.client.render.IPonyRenderContext; import com.minelittlepony.client.render.PonyRenderDispatcher; import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer; import com.minelittlepony.settings.PonyConfig; @@ -30,7 +29,6 @@ import java.util.concurrent.TimeUnit; * */ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloadListener { - private static final Identifier ID = new Identifier("minelittlepony", "background_ponies"); public static final Identifier BACKGROUND_PONIES = new Identifier("minelittlepony", "textures/entity/pony"); @@ -48,22 +46,6 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa this.config = config; } - @Override - public Optional getPony(@Nullable Entity entity) { - if (entity instanceof PlayerEntity player) { - return Optional.of(getPony(player)); - } - - if (entity instanceof LivingEntity living) { - IPonyRenderContext dispatcher = PonyRenderDispatcher.getInstance().getPonyRenderer(living); - if (dispatcher != null) { - return Optional.of(dispatcher.getEntityPony(living)); - } - } - - return Optional.empty(); - } - @Override public IPony getPony(Identifier resource) { try { @@ -74,16 +56,29 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa } @Override - public IPony getPony(PlayerEntity player) { - if (player.getGameProfile() == null) { - return getDefaultPony(player.getUuid()); + public Optional getPony(@Nullable Entity entity) { + if (entity instanceof PlayerEntity player) { + return Optional.of(getPony(player)); } + if (entity instanceof LivingEntity living) { + return Optional.ofNullable(PonyRenderDispatcher.getInstance().getPonyRenderer(living)).map(d -> d.getEntityPony(living)); + } + + return Optional.empty(); + } + + @Override + public IPony getPony(PlayerEntity player) { Identifier skin = getSkin(player); - UUID uuid = player.getGameProfile().getId(); + UUID uuid = player.getGameProfile() == null ? player.getUuid() : player.getGameProfile().getId(); if (skin == null) { - return getDefaultPony(uuid); + if (config.ponyLevel.get() == PonyLevel.PONIES) { + return getBackgroundPony(uuid); + } + + return getAsDefaulted(getPony(DefaultSkinHelper.getTexture(uuid))); } if (player instanceof IPonyManager.ForcedPony) { @@ -93,15 +88,6 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa return getPony(skin, uuid); } - @Nullable - private Identifier getSkin(PlayerEntity player) { - if (player instanceof AbstractClientPlayerEntity) { - return ((AbstractClientPlayerEntity)player).getSkinTexture(); - } - - return null; - } - @Override public IPony getPony(Identifier resource, UUID uuid) { IPony pony = getPony(resource); @@ -113,6 +99,11 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa return pony; } + @Override + public IPony getBackgroundPony(UUID uuid) { + return getAsDefaulted(getPony(MineLittlePony.getInstance().getVariatedTextures().get(BACKGROUND_PONIES, uuid).orElse(DefaultSkinHelper.getTexture(uuid)))); + } + private IPony getAsDefaulted(IPony pony) { try { return defaultedPoniesCache.get(pony.texture(), () -> new Pony(pony.texture(), ((Pony)pony).memoizedData(), true)); @@ -121,18 +112,16 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa } } - @Override - public IPony getDefaultPony(UUID uuid) { - if (config.ponyLevel.get() != PonyLevel.PONIES) { - return getAsDefaulted(getPony(DefaultSkinHelper.getTexture(uuid))); + @Nullable + private Identifier getSkin(PlayerEntity player) { + if (player.getGameProfile() == null) { + return null; + } + if (player instanceof AbstractClientPlayerEntity) { + return ((AbstractClientPlayerEntity)player).getSkinTexture(); } - return getBackgroundPony(uuid); - } - - @Override - public IPony getBackgroundPony(UUID uuid) { - return getAsDefaulted(getPony(MineLittlePony.getInstance().getVariatedTextures().get(BACKGROUND_PONIES, uuid))); + return null; } @Override diff --git a/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java b/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java index 620ccc2e..13333679 100644 --- a/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java +++ b/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java @@ -1,18 +1,20 @@ package com.minelittlepony.client.pony; import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; +import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import com.minelittlepony.client.MineLittlePony; +import com.minelittlepony.util.MathUtil; + +import java.util.*; public class VariatedTextureSupplier implements SimpleSynchronousResourceReloadListener { private static final Identifier ID = new Identifier("minelittlepony", "variated_textures"); - private final Map entries = new HashMap<>(); + private final Map entries = new HashMap<>(); @Override public void reload(ResourceManager manager) { @@ -24,15 +26,46 @@ public class VariatedTextureSupplier implements SimpleSynchronousResourceReloadL return ID; } - private BackgroundPonyList get(Identifier id) { - return entries.computeIfAbsent(id, BackgroundPonyList::new); + private SkinList get(Identifier id) { + return entries.computeIfAbsent(id, SkinList::new); } - public Identifier get(Identifier poolId, UUID seed) { + public Optional get(Identifier poolId, UUID seed) { return get(poolId).getId(seed); } - public Identifier get(Identifier poolId, Entity entity) { + public Optional get(Identifier poolId, Entity entity) { return get(poolId, entity.getUuid()); } + + private static class SkinList { + private final List textures = new ArrayList<>(); + + private final Identifier id; + + public SkinList(Identifier id) { + this.id = id; + reloadAll(MinecraftClient.getInstance().getResourceManager()); + } + + public Optional getId(UUID uuid) { + if (textures.isEmpty() || isUser(uuid)) { + return Optional.empty(); + } + + return Optional.ofNullable(textures.get(MathUtil.mod(uuid.hashCode(), textures.size()))); + } + + public void reloadAll(ResourceManager resourceManager) { + textures.clear(); + textures.addAll(resourceManager.findResources(id.getPath(), path -> path.getPath().endsWith(".png")).keySet()); + MineLittlePony.logger.info("Detected {} ponies installed at {}.", textures.size(), id); + } + + static boolean isUser(UUID uuid) { + return MinecraftClient.getInstance().player != null + && MinecraftClient.getInstance().player.getUuid().equals(uuid); + } + } + } diff --git a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java index 1a390c48..27267921 100644 --- a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java +++ b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java @@ -185,6 +185,10 @@ public class EquineRenderManager boolean special = PonyTextures.isBestPony(entity); - if (wearable == Wearable.SADDLE_BAGS) { + if (wearable.isSaddlebags()) { VillagerProfession profession = entity.getVillagerData().getProfession(); return !special && profession != VillagerProfession.NONE && ( profession == VillagerProfession.CARTOGRAPHER @@ -75,7 +75,7 @@ abstract class AbstractNpcRenderer @Override public Identifier getDefaultTexture(T villager, Wearable wearable) { - if (wearable == Wearable.SADDLE_BAGS) { + if (wearable.isSaddlebags()) { return clothing.createTexture(villager, "accessory"); } return getTexture(villager); diff --git a/src/main/java/com/minelittlepony/settings/PonyConfig.java b/src/main/java/com/minelittlepony/settings/PonyConfig.java index b4fce360..b680e9ba 100644 --- a/src/main/java/com/minelittlepony/settings/PonyConfig.java +++ b/src/main/java/com/minelittlepony/settings/PonyConfig.java @@ -99,7 +99,7 @@ public class PonyConfig extends Config { * Gets the actual race determined by the given pony level. * PonyLevel.HUMANS would force all races to be humans. * PonyLevel.BOTH is no change. - * PonyLevel.PONIES (should) return a pony if this is a human. Don't be fooled, though. It doesn't. + * PonyLevel.PONIES no change. */ public static Race getEffectiveRace(Race race) { diff --git a/src/main/resources/assets/minelittlepony/models/components/pegasus_wings.json b/src/main/resources/assets/minelittlepony/models/components/pegasus_wings.json index e9c03407..cf01bbb9 100644 --- a/src/main/resources/assets/minelittlepony/models/components/pegasus_wings.json +++ b/src/main/resources/assets/minelittlepony/models/components/pegasus_wings.json @@ -10,9 +10,9 @@ "pivot": [0, 13, -2], "rotate": [90, 0, 0], "cubes": [ - {"from": [4, 5, 2], "size": [2, 6, 2] }, - {"from": [4, 5, 4], "size": [2, 8, 2] }, - {"from": [4, 5, 6], "size": [2, 6, 2] } + {"from": [4.1, 5, 1.999], "size": [2, 6, 2] }, + {"from": [4.1, 5, 4.001], "size": [2, 8, 2] }, + {"from": [4.1, 5, 6.002], "size": [2, 6, 2] } ] }, "extended": { @@ -40,9 +40,9 @@ "pivot": [0, 13, -2], "rotate": [90, 0, 0], "cubes": [ - {"from": [-6, 5, 2], "size": [2, 6, 2] }, - {"from": [-6, 5, 4], "size": [2, 8, 2] }, - {"from": [-6, 5, 6], "size": [2, 6, 2] } + {"from": [-6.001, 5, 1.999], "size": [2, 6, 2] }, + {"from": [-6.001, 5, 4.001], "size": [2, 8, 2] }, + {"from": [-6.001, 5, 6.002], "size": [2, 6, 2] } ] }, "extended": { @@ -70,9 +70,9 @@ "pivot": [0, 13, -2], "rotate": [90, 0, 0], "cubes": [ - {"from": [-6, 5, 2], "size": [2, 6, 2] }, - {"from": [-6, 5, 4], "size": [2, 8, 2] }, - {"from": [-6, 5, 6], "size": [2, 6, 2] } + {"from": [-6.001, 5, 1.999], "size": [2, 6, 2] }, + {"from": [-6.001, 5, 4.001], "size": [2, 8, 2] }, + {"from": [-6.001, 5, 6.002], "size": [2, 6, 2] } ] }, "extended": { diff --git a/src/main/resources/assets/minelittlepony/textures/entity/alex_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/alex_pony.png deleted file mode 100644 index 9afa16d9..00000000 Binary files a/src/main/resources/assets/minelittlepony/textures/entity/alex_pony.png and /dev/null differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/alex_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/alex_pony.png new file mode 100644 index 00000000..25e96514 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/alex_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/ari_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/ari_pony.png new file mode 100644 index 00000000..92cc59f9 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/ari_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/efe_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/efe_pony.png new file mode 100644 index 00000000..ab3c6791 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/efe_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/kai_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/kai_pony.png new file mode 100644 index 00000000..eea3307f Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/kai_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/makena_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/makena_pony.png new file mode 100644 index 00000000..7b884742 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/makena_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/noor_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/noor_pony.png new file mode 100644 index 00000000..acbf9b14 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/noor_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/steve_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/steve_pony.png new file mode 100644 index 00000000..e2593303 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/steve_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/sunny_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/sunny_pony.png new file mode 100644 index 00000000..b9918a80 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/sunny_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/slim/zuri_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/zuri_pony.png new file mode 100644 index 00000000..bf02194f Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/slim/zuri_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/alex_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/alex_pony.png new file mode 100644 index 00000000..d861b6c9 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/alex_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/ari_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/ari_pony.png new file mode 100644 index 00000000..9e6ef2c6 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/ari_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/efe_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/efe_pony.png new file mode 100644 index 00000000..36f32d49 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/efe_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/kai_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/kai_pony.png new file mode 100644 index 00000000..bd254da5 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/kai_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/makena_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/makena_pony.png new file mode 100644 index 00000000..4c4b8de2 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/makena_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/noor_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/noor_pony.png new file mode 100644 index 00000000..8640be5f Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/noor_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/steve_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/steve_pony.png similarity index 100% rename from src/main/resources/assets/minelittlepony/textures/entity/steve_pony.png rename to src/main/resources/assets/minelittlepony/textures/entity/player/wide/steve_pony.png diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/sunny_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/sunny_pony.png new file mode 100644 index 00000000..7ec15d83 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/sunny_pony.png differ diff --git a/src/main/resources/assets/minelittlepony/textures/entity/player/wide/zuri_pony.png b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/zuri_pony.png new file mode 100644 index 00000000..be18b981 Binary files /dev/null and b/src/main/resources/assets/minelittlepony/textures/entity/player/wide/zuri_pony.png differ diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index 80cd505c..d9a6f575 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -7,11 +7,11 @@ "client": [ "IResizeable", "MixinCamera", - "MixinDefaultPlayerSkin", + "MixinDefaultSkinHelper", "MixinEntityRenderDispatcher", "MixinEntityRenderers", "MixinSkullBlockEntityRenderer", - "MixinFirstPersonRenderer", + "MixinHeldItemRenderer", "MixinItemRenderer", "MixinTexturedRenderLayers", "MixinSpriteIdentifier",