From 94592212c620d28db728c04dd187c42bc2a4fae6 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 27 Feb 2023 13:31:37 +0000 Subject: [PATCH] Simplify armour code and fix armour visibility being set before setting the armour variant --- .../minelittlepony/api/config/PonyConfig.java | 4 ++ .../api/model/armour/IArmourModel.java | 69 +----------------- .../model/armour/IArmourTextureResolver.java | 2 +- .../client/GuiPonySettings.java | 3 + .../armour/DefaultArmourTextureResolver.java | 16 ++++- .../client/model/armour/PonyArmourModel.java | 71 ++++++++++--------- .../client/model/entity/ParaspriteModel.java | 5 -- .../model/entity/race/SeaponyModel.java | 4 +- .../render/entity/PlayerPonyRenderer.java | 8 ++- .../render/entity/feature/ArmourFeature.java | 29 ++++---- .../client/settings/ClientPonyConfig.java | 2 + .../assets/minelittlepony/lang/en_us.json | 1 + .../models/armor/inner_pony_armor.json | 2 +- .../models/armor/outer_pony_armor.json | 2 +- 14 files changed, 88 insertions(+), 130 deletions(-) diff --git a/src/main/java/com/minelittlepony/api/config/PonyConfig.java b/src/main/java/com/minelittlepony/api/config/PonyConfig.java index 9e39cab6..18879d08 100644 --- a/src/main/java/com/minelittlepony/api/config/PonyConfig.java +++ b/src/main/java/com/minelittlepony/api/config/PonyConfig.java @@ -61,6 +61,10 @@ public class PonyConfig extends Config { .addComment("Overrides pony races") .addComment("Possible values: HUMAN (default), EARTH, PEGASUS, UNICORN, ALICORN, CHANGELING, ZEBRA, CHANGEDLING, GRYPHON, HIPPOGRIFF, KIRIN, BAYPONT, SEAPONY"); + public final Setting disablePonifiedArmour = value("debug", "usePonifiedArmour", false) + .addComment("Disables pony armour textures.") + .addComment("If enabled, only the vanilla textures will be considered"); + public final Setting flappyElytras = value("customisation", "flappyElytras", false) .addComment("Pegasi will use their wings to fly even when they're wearing an elytra"); public final Setting noFun = value("customisation", "noFun", false) diff --git a/src/main/java/com/minelittlepony/api/model/armour/IArmourModel.java b/src/main/java/com/minelittlepony/api/model/armour/IArmourModel.java index e2a0c945..cd438975 100644 --- a/src/main/java/com/minelittlepony/api/model/armour/IArmourModel.java +++ b/src/main/java/com/minelittlepony/api/model/armour/IArmourModel.java @@ -12,13 +12,6 @@ public interface IArmourModel { */ void synchroniseAngles(IModel model); - /** - * Resets the state of this model to all invisible. - */ - void setInVisible(); - - void setVariant(ArmourVariant variant); - /** * Prepares an armour model for rendering, first hiding all the pieces and then incrementally showing them as appropriate. * @@ -27,65 +20,5 @@ public interface IArmourModel { * * @return false to skip this render pass. */ - default boolean prepareToRender(EquipmentSlot slot, ArmourLayer layer) { - setInVisible(); - - switch (layer) { - case OUTER: - switch (slot) { - case HEAD: - showHelmet(); - return true; - case FEET: - showBoots(); - return true; - case CHEST: - showSaddle(); - return true; - default: - return false; - } - case INNER: - switch (slot) { - case LEGS: - showLeggings(); - return true; - case CHEST: - showChestplate(); - return true; - default: - return false; - } - } - - return false; - } - - /** - * Called to display the model's boots. - */ - void showBoots(); - - /** - * Called to display the leg part of the model. Legs and boots use the same components just with separated texture files - * so it's reasonable that this would also call showBoots() - */ - void showLeggings(); - - /** - * Shows the chestplate and saddle. - * - * @param outside true when being called to render the external cloth layer (saddle), false for the main body piece. - */ - void showChestplate(); - - /** - * Ponies wear saddles. #dealwithit - */ - void showSaddle(); - - /** - * Used to make the helmet visible - */ - void showHelmet(); + boolean setVisibilities(EquipmentSlot slot, ArmourLayer layer, ArmourVariant variant); } diff --git a/src/main/java/com/minelittlepony/api/model/armour/IArmourTextureResolver.java b/src/main/java/com/minelittlepony/api/model/armour/IArmourTextureResolver.java index a55b6249..0d9ed6a6 100644 --- a/src/main/java/com/minelittlepony/api/model/armour/IArmourTextureResolver.java +++ b/src/main/java/com/minelittlepony/api/model/armour/IArmourTextureResolver.java @@ -15,7 +15,7 @@ import com.minelittlepony.client.model.armour.DefaultArmourTextureResolver; * This is for modders who want to override the default implementation found in {@link DefaultArmourTextureResolver}. */ public interface IArmourTextureResolver { - IArmourTextureResolver DEFAULT = new DefaultArmourTextureResolver(); + IArmourTextureResolver DEFAULT = DefaultArmourTextureResolver.INSTANCE; /** * Gets the armour texture to be used for the given entity, armour piece, slot, and render layer. diff --git a/src/main/java/com/minelittlepony/client/GuiPonySettings.java b/src/main/java/com/minelittlepony/client/GuiPonySettings.java index 9260103f..a0568d9a 100644 --- a/src/main/java/com/minelittlepony/client/GuiPonySettings.java +++ b/src/main/java/com/minelittlepony/client/GuiPonySettings.java @@ -101,6 +101,9 @@ public class GuiPonySettings extends GameGui { content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.race"); content.addButton(new EnumSlider<>(LEFT, row += 15, config.raceOverride.get()) .onChange(config.raceOverride::set)); + content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.armour"); + content.addButton(new Toggle(LEFT, row += 15, config.disablePonifiedArmour.get()) + .onChange(config.disablePonifiedArmour::set)); } row += 20; diff --git a/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java b/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java index 4b79b6d4..805ff197 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java +++ b/src/main/java/com/minelittlepony/client/model/armour/DefaultArmourTextureResolver.java @@ -11,6 +11,7 @@ import net.minecraft.util.Identifier; import com.google.common.base.Strings; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import com.minelittlepony.api.config.PonyConfig; import com.minelittlepony.api.model.armour.ArmourLayer; import com.minelittlepony.api.model.armour.ArmourVariant; import com.minelittlepony.api.model.armour.IArmourTextureResolver; @@ -43,17 +44,23 @@ import java.util.concurrent.TimeUnit; * @see IArmourTextureResolver */ public class DefaultArmourTextureResolver implements IArmourTextureResolver { + public static final DefaultArmourTextureResolver INSTANCE = new DefaultArmourTextureResolver(); private final Cache cache = CacheBuilder.newBuilder() .expireAfterAccess(30, TimeUnit.SECONDS) .build(); + public void invalidate() { + cache.invalidateAll(); + } + @Override public Identifier getTexture(LivingEntity entity, ItemStack stack, EquipmentSlot slot, ArmourLayer layer, @Nullable String type) { Identifier material = new Identifier(((ArmorItem) stack.getItem()).getMaterial().getName()); String custom = getCustom(stack); try { + cache.invalidateAll(); return cache.get(String.format("%s#%s#%s#%s", material, layer, type, custom), () -> { String typed = Strings.nullToEmpty(type); String extra = typed.isEmpty() ? "" : "_" + typed; @@ -106,10 +113,13 @@ public class DefaultArmourTextureResolver implements IArmourTextureResolver { domain = "minelittlepony"; // it's a vanilla armor. I provide these. } - Identifier pony = new Identifier(domain, human.getPath().replace(".png", "_pony.png")); + if (!PonyConfig.getInstance().disablePonifiedArmour.get()) { - if (isValid(pony)) { - return pony; + Identifier pony = new Identifier(domain, human.getPath().replace(".png", "_pony.png")); + + if (isValid(pony)) { + return pony; + } } if (isValid(human)) { diff --git a/src/main/java/com/minelittlepony/client/model/armour/PonyArmourModel.java b/src/main/java/com/minelittlepony/client/model/armour/PonyArmourModel.java index 8b75cf24..f274771d 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/PonyArmourModel.java +++ b/src/main/java/com/minelittlepony/client/model/armour/PonyArmourModel.java @@ -2,6 +2,7 @@ package com.minelittlepony.client.model.armour; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import com.minelittlepony.api.model.IModel; @@ -15,8 +16,6 @@ public class PonyArmourModel extends AbstractPonyModel extends AbstractPonyModel extends AbstractPonyModel extends AbstractPonyModel extends AbstractPonyModel extends EntityModel { root.pitch = MathHelper.clamp((float)entity.getVelocity().horizontalLength() / 10F, 0, 0.1F); body.pitch = 0; - lips.visible = false; if (entity.hasPassengers()) { root.yaw = 0; @@ -72,12 +71,10 @@ public class ParaspriteModel extends EntityModel { float basWingExpand = 1; float innerWingExpand = basWingExpand / 2F; - leftWing.visible = true; leftWing.pitch = 0; leftWing.roll = basWingExpand + cos + 0.3F; leftWing.yaw = basWingExpand - sin; - rightWing.visible = true; rightWing.pitch = 0; rightWing.roll = -basWingExpand - cos - 0.3F; rightWing.yaw = -basWingExpand + sin; @@ -85,12 +82,10 @@ public class ParaspriteModel extends EntityModel { sin = -(float)Math.sin(ticks + Math.PI / 4F) / 2F; cos = (float)Math.cos(ticks + Math.PI / 4F) / 3F; - leftWing2.visible = true; leftWing2.pitch = 0; leftWing2.roll = innerWingExpand + sin - 0.3F; leftWing2.yaw = innerWingExpand - cos + 0.3F; - rightWing2.visible = true; rightWing2.pitch = 0; rightWing2.roll = -innerWingExpand - sin + 0.3F; rightWing2.yaw = -innerWingExpand + cos - 0.3F; diff --git a/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java b/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java index 38e88619..58723fc0 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java @@ -4,6 +4,8 @@ import com.minelittlepony.client.model.armour.PonyArmourModel; import com.minelittlepony.mson.api.ModelContext; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.ModelAttributes; +import com.minelittlepony.api.model.armour.ArmourLayer; +import com.minelittlepony.api.model.armour.ArmourVariant; import com.minelittlepony.api.pony.IPony; import net.minecraft.client.model.ModelPart; @@ -138,7 +140,7 @@ public class SeaponyModel extends UnicornModel { } @Override - public void showBoots() { + public void showLeggings(ArmourLayer layer, ArmourVariant variant) { rightArm.visible = true; leftArm.visible = true; } diff --git a/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java index ce72639c..8fc17d99 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java @@ -6,7 +6,6 @@ import com.minelittlepony.api.pony.meta.Race; import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.client.model.*; -import com.minelittlepony.client.model.gear.SaddleBags; import com.minelittlepony.client.render.DebugBoundingBoxRenderer; import com.minelittlepony.client.render.IPonyRenderContext; import com.minelittlepony.client.render.EquineRenderManager; @@ -197,8 +196,11 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen @Override public Identifier getDefaultTexture(AbstractClientPlayerEntity entity, Wearable wearable) { return SkinsProxy.instance.getSkin(wearable.getId(), entity).orElseGet(() -> { - if (wearable.isSaddlebags() && getInternalRenderer().getModel().getMetadata().getRace() == Race.BATPONY) { - return SaddleBags.TEXTURE; + if (wearable.isSaddlebags()) { + if (getInternalRenderer().getModel().getMetadata().getRace() == Race.BATPONY) { + return wearable.getDefaultTexture(); + } + return manager.getTexture(entity); } return wearable.getDefaultTexture(); diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java index 253d5e61..192aed22 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java @@ -56,15 +56,21 @@ public class ArmourFeature & IP return; } - model.setMetadata(pony.body().getMetadata()); + IArmourTextureResolver resolver = model.getArmourTextureResolver(); + + boolean glint = itemstack.hasGlint(); + + Identifier texture = resolver.getTexture(entity, itemstack, armorSlot, layer, null); + + Item item = itemstack.getItem(); + + if (model.setVisibilities(armorSlot, layer, resolver.getVariant(layer, texture))) { + model.setMetadata(pony.body().getMetadata()); - if (model.prepareToRender(armorSlot, layer)) { pony.body().copyAttributes(model); model.setAngles(entity, limbAngle, limbDistance, age, headYaw, headPitch); model.synchroniseAngles(pony.body()); - Item item = itemstack.getItem(); - float red = 1; float green = 1; float blue = 1; @@ -76,25 +82,22 @@ public class ArmourFeature & IP blue = Color.b(color); } - IArmourTextureResolver resolver = model.getArmourTextureResolver(); - - boolean glint = itemstack.hasGlint(); - - renderArmourPart(stack, renderContext, lightUv, glint, model, red, green, blue, resolver, layer, resolver.getTexture(entity, itemstack, armorSlot, layer, null)); - + renderArmourPart(stack, renderContext, lightUv, glint, model, red, green, blue, texture); if (item instanceof DyeableArmorItem) { - renderArmourPart(stack, renderContext, lightUv, false, model, 1, 1, 1, resolver, layer, resolver.getTexture(entity, itemstack, armorSlot, layer, "overlay")); + texture = resolver.getTexture(entity, itemstack, armorSlot, layer, "overlay"); + if (model.setVisibilities(armorSlot, layer, resolver.getVariant(layer, texture))) { + renderArmourPart(stack, renderContext, lightUv, false, model, 1, 1, 1, texture); + } } } } private static & IArmourModel> void renderArmourPart( MatrixStack matrices, VertexConsumerProvider provider, - int light, boolean glint, V model, float r, float g, float b, IArmourTextureResolver resolver, ArmourLayer layer, Identifier texture) { + int light, boolean glint, V model, float r, float g, float b, Identifier texture) { VertexConsumer vertices = ItemRenderer.getArmorGlintConsumer(provider, RenderLayer.getArmorCutoutNoCull(texture), false, glint); - model.setVariant(resolver.getVariant(layer, texture)); model.render(matrices, vertices, light, OverlayTexture.DEFAULT_UV, r, g, b, 1); } } diff --git a/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java b/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java index 3b385017..47a833f5 100644 --- a/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java +++ b/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java @@ -4,6 +4,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.entity.player.PlayerEntity; import com.minelittlepony.api.config.PonyConfig; +import com.minelittlepony.client.model.armour.DefaultArmourTextureResolver; import com.minelittlepony.client.render.MobRenderers; import com.minelittlepony.common.client.gui.VisibilityMode; import com.minelittlepony.common.util.settings.Setting; @@ -24,6 +25,7 @@ public class ClientPonyConfig extends PonyConfig { public ClientPonyConfig(Path path) { super(path); MobRenderers.REGISTRY.values().forEach(r -> value("entities", r.name, true)); + disablePonifiedArmour.onChanged(t -> DefaultArmourTextureResolver.INSTANCE.invalidate()); } @Override diff --git a/src/main/resources/assets/minelittlepony/lang/en_us.json b/src/main/resources/assets/minelittlepony/lang/en_us.json index 0475a96d..36b85c28 100644 --- a/src/main/resources/assets/minelittlepony/lang/en_us.json +++ b/src/main/resources/assets/minelittlepony/lang/en_us.json @@ -50,6 +50,7 @@ "minelp.debug.scale.min": "Miniscule", "minelp.debug.size": "Size Override", "minelp.debug.race": "Race Override", + "minelp.debug.armour": "Disable ponified armour textures", "hdskins.mode.minelp_seapony": "Seapony", "hdskins.mode.minelittlepony_crown": "Crown", diff --git a/src/main/resources/assets/minelittlepony/models/armor/inner_pony_armor.json b/src/main/resources/assets/minelittlepony/models/armor/inner_pony_armor.json index 46a2207b..001831f8 100644 --- a/src/main/resources/assets/minelittlepony/models/armor/inner_pony_armor.json +++ b/src/main/resources/assets/minelittlepony/models/armor/inner_pony_armor.json @@ -1,7 +1,7 @@ { "parent": "minelittlepony:steve_pony", "texture": {"w": 64, "h": 32}, - "dilate": 0.27, + "dilate": 0.2, "data": { "body": { "texture": { "u": 16, "v": 18 }, diff --git a/src/main/resources/assets/minelittlepony/models/armor/outer_pony_armor.json b/src/main/resources/assets/minelittlepony/models/armor/outer_pony_armor.json index 56b86655..c38bbb07 100644 --- a/src/main/resources/assets/minelittlepony/models/armor/outer_pony_armor.json +++ b/src/main/resources/assets/minelittlepony/models/armor/outer_pony_armor.json @@ -1,4 +1,4 @@ { "parent": "minelittlepony:armor/inner_pony_armor", - "dilate": 0.3 + "dilate": 0.4 }