From b5b168df06e08abb8ff70dc88875f5a641cec417 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 15 Feb 2023 20:16:57 +0000 Subject: [PATCH] Clean up some messy refactorings --- .../render/entity/PonyStandRenderer.java | 13 ++++++----- .../textures/ProfessionTextureSupplier.java | 22 +------------------ .../com/minelittlepony/util/ResourceUtil.java | 13 +++++++++++ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java index 87c5955b..362e4039 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java @@ -3,11 +3,7 @@ package com.minelittlepony.client.render.entity; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.ArmorStandEntityRenderer; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; -import net.minecraft.client.render.entity.feature.ElytraFeatureRenderer; -import net.minecraft.client.render.entity.feature.FeatureRendererContext; -import net.minecraft.client.render.entity.feature.HeadFeatureRenderer; -import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer; +import net.minecraft.client.render.entity.feature.*; import net.minecraft.client.render.entity.model.ArmorStandArmorEntityModel; import net.minecraft.client.render.entity.model.EntityModelLayers; import net.minecraft.client.util.math.MatrixStack; @@ -33,7 +29,12 @@ public class PonyStandRenderer extends ArmorStandEntityRenderer { super(context); human = model; - features.clear(); + features.removeIf(feature -> { + return feature instanceof ArmorFeatureRenderer + || feature instanceof HeldItemFeatureRenderer + || feature instanceof ElytraFeatureRenderer + || feature instanceof HeadFeatureRenderer; + }); addFeature(new Armour(this, context)); addFeature(new HeldItemFeatureRenderer<>(this, context.getHeldItemRenderer())); addFeature(new ElytraFeatureRenderer<>(this, context.getModelLoader())); diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/textures/ProfessionTextureSupplier.java b/src/main/java/com/minelittlepony/client/render/entity/npc/textures/ProfessionTextureSupplier.java index 41a09bb3..e66a7f37 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/textures/ProfessionTextureSupplier.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/textures/ProfessionTextureSupplier.java @@ -1,14 +1,10 @@ package com.minelittlepony.client.render.entity.npc.textures; -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; import net.minecraft.village.*; import com.minelittlepony.util.ResourceUtil; -import java.util.*; - public class ProfessionTextureSupplier implements TextureSupplier { public static TextureSupplier create(TextureSupplier formatter) { @@ -40,7 +36,7 @@ public class ProfessionTextureSupplier implemen private Identifier getTexture(final VillagerType type, final VillagerProfession profession) { String key = ResourceUtil.format("pony/%s/%s", type, profession); - return verifyTexture(formatter.apply(key)).orElseGet(() -> { + return ResourceUtil.verifyTexture(formatter.apply(key)).orElseGet(() -> { if (type == VillagerType.PLAINS) { // if texture loading fails, use the fallback. return fallback; @@ -49,20 +45,4 @@ public class ProfessionTextureSupplier implemen return getTexture(VillagerType.PLAINS, profession); }); } - - protected Optional verifyTexture(Identifier texture) { - return MinecraftClient.getInstance().getResourceManager().getResource(texture).map(i -> texture); - } - - public static boolean isBestPony(LivingEntity entity) { - if (!entity.hasCustomName()) { - return false; - } - String name = entity.getCustomName().getString(); - return "Derpy".equals(name) || (entity.isBaby() && "Dinky".equals(name)); - } - - public static boolean isCrownPony(LivingEntity entity) { - return isBestPony(entity) && entity.getUuid().getLeastSignificantBits() % 20 == 0; - } } diff --git a/src/main/java/com/minelittlepony/util/ResourceUtil.java b/src/main/java/com/minelittlepony/util/ResourceUtil.java index dbcc383b..35a24d19 100644 --- a/src/main/java/com/minelittlepony/util/ResourceUtil.java +++ b/src/main/java/com/minelittlepony/util/ResourceUtil.java @@ -1,5 +1,10 @@ package com.minelittlepony.util; +import net.minecraft.client.MinecraftClient; +import net.minecraft.util.Identifier; + +import java.util.Optional; + public final class ResourceUtil { public static String format(String template, Object... args) { @@ -14,4 +19,12 @@ public final class ResourceUtil { private static String toPathComponent(Object value) { return value.toString().toLowerCase().replaceAll("[^a-z0-9_.-]", "_"); } + + public static boolean textureExists(Identifier texture) { + return MinecraftClient.getInstance().getTextureManager().getOrDefault(texture, null) != null; + } + + public static Optional verifyTexture(Identifier texture) { + return textureExists(texture) ? Optional.of(texture) : Optional.empty(); + } }