Clean up some messy refactorings

This commit is contained in:
Sollace 2023-02-15 20:16:57 +00:00
parent f0d16efd18
commit b5b168df06
3 changed files with 21 additions and 27 deletions

View file

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

View file

@ -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<T extends VillagerDataContainer> implements TextureSupplier<T> {
public static <T extends VillagerDataContainer> TextureSupplier<T> create(TextureSupplier<String> formatter) {
@ -40,7 +36,7 @@ public class ProfessionTextureSupplier<T extends VillagerDataContainer> 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<T extends VillagerDataContainer> implemen
return getTexture(VillagerType.PLAINS, profession);
});
}
protected Optional<Identifier> 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;
}
}

View file

@ -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<Identifier> verifyTexture(Identifier texture) {
return textureExists(texture) ? Optional.of(texture) : Optional.empty();
}
}