More package changes and fixed villager's clothing

This commit is contained in:
Sollace 2019-11-30 14:56:07 +02:00
parent 270e655f91
commit 5cadc01dd8
30 changed files with 183 additions and 122 deletions

View file

@ -11,7 +11,7 @@ import com.minelittlepony.model.BodyPart;
import com.minelittlepony.model.IModel;
import com.minelittlepony.mson.api.ModelContext;
import com.minelittlepony.pony.meta.Wearable;
import com.minelittlepony.util.math.Color;
import com.minelittlepony.util.Color;
import java.util.Calendar;
import java.util.UUID;

View file

@ -11,7 +11,7 @@ import com.minelittlepony.client.render.MagicGlow;
import com.minelittlepony.model.IPart;
import com.minelittlepony.mson.api.ModelContext;
import com.minelittlepony.mson.api.MsonModel;
import com.minelittlepony.util.math.Color;
import com.minelittlepony.util.Color;
import javax.annotation.Nullable;

View file

@ -16,8 +16,8 @@ import com.minelittlepony.pony.meta.Size;
import com.minelittlepony.pony.meta.TailLength;
import com.minelittlepony.pony.meta.TriggerPixels;
import com.minelittlepony.pony.meta.Wearable;
import com.minelittlepony.util.animation.BasicEasingInterpolator;
import com.minelittlepony.util.animation.IInterpolator;
import com.minelittlepony.util.BasicEasingInterpolator;
import com.minelittlepony.util.IInterpolator;
import java.io.FileNotFoundException;
import java.io.IOException;

View file

@ -12,7 +12,7 @@ import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.IPonyManager;
import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
import com.minelittlepony.util.math.MathUtil;
import com.minelittlepony.util.MathUtil;
import javax.annotation.Nullable;

View file

@ -6,7 +6,7 @@ import com.minelittlepony.client.model.ModelWrapper;
import com.minelittlepony.client.transform.PonyPosture;
import com.minelittlepony.mson.api.ModelKey;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.util.math.MathUtil;
import com.minelittlepony.util.MathUtil;
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem;

View file

@ -7,7 +7,7 @@ import com.minelittlepony.model.BodyPart;
import com.minelittlepony.model.PonyModelConstants;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.meta.Wearable;
import com.minelittlepony.util.math.MathUtil;
import com.minelittlepony.util.MathUtil;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;

View file

@ -2,7 +2,7 @@ package com.minelittlepony.client.render;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.util.math.Color;
import com.minelittlepony.util.Color;
import javax.annotation.Nullable;

View file

@ -18,9 +18,9 @@ public final class MobRenderers {
public static final Map<String, MobRenderers> REGISTRY = new HashMap<>();
public static final MobRenderers VILLAGER = register("villagers", (state, pony) -> {
pony.switchRenderer(state, EntityType.VILLAGER, RenderPonyVillager::new);
pony.switchRenderer(state, EntityType.VILLAGER, VillagerPonyRenderer::new);
pony.switchRenderer(state, EntityType.WITCH, WitchRenderer::new);
pony.switchRenderer(state, EntityType.ZOMBIE_VILLAGER, RenderPonyZombieVillager::new);
pony.switchRenderer(state, EntityType.ZOMBIE_VILLAGER, ZomponyVillagerRenderer::new);
pony.switchRenderer(state, EntityType.WANDERING_TRADER, TraderRenderer::new);
});
public static final MobRenderers ILLAGER = register("illagers", (state, pony) -> {

View file

@ -5,7 +5,7 @@ import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.mson.api.ModelKey;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.meta.Race;
import com.minelittlepony.util.math.MathUtil;
import com.minelittlepony.util.MathUtil;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.entity.EntityRenderDispatcher;

View file

@ -9,7 +9,7 @@ import com.minelittlepony.model.armour.ArmourLayer;
import com.minelittlepony.model.armour.IArmour;
import com.minelittlepony.model.armour.IArmourTextureResolver;
import com.minelittlepony.model.armour.IEquestrianArmour;
import com.minelittlepony.util.math.Color;
import com.minelittlepony.util.Color;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;

View file

@ -14,22 +14,21 @@ import com.minelittlepony.model.IUnicorn;
import com.minelittlepony.model.gear.IGear;
import com.minelittlepony.mson.api.ModelKey;
import com.minelittlepony.pony.meta.Wearable;
import com.minelittlepony.util.resources.ITextureSupplier;
abstract class AbstractVillagerRenderer<
abstract class AbstractNpcRenderer<
T extends MobEntity & VillagerDataContainer,
M extends ClientPonyModel<T> & IUnicorn<ModelPart> & ModelWithHat> extends PonyRenderer.Caster<T, M> {
private final ITextureSupplier<T> baseTextures;
private final TextureSupplier<T> baseTextures;
private final String entityType;
public AbstractVillagerRenderer(EntityRenderDispatcher manager, ModelKey<? super M> key, String type, ITextureSupplier<String> formatter) {
public AbstractNpcRenderer(EntityRenderDispatcher manager, ModelKey<? super M> key, String type, TextureSupplier<String> formatter) {
super(manager, key);
entityType = type;
baseTextures = new PonyTextures<>(formatter);
addFeature(new ClothingLayer<>(this, entityType));
addFeature(new NpcClothingFeature<>(this, entityType));
}
@Override
@ -57,7 +56,7 @@ abstract class AbstractVillagerRenderer<
@Override
public Identifier getDefaultTexture(T villager, Wearable wearable) {
if (wearable == Wearable.SADDLE_BAGS) {
return ClothingLayer.getClothingTexture(villager, entityType);
return NpcClothingFeature.getClothingTexture(villager, entityType);
}
return super.getDefaultTexture(villager, wearable);
}

View file

@ -1,65 +0,0 @@
package com.minelittlepony.client.render.entity.npc;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.feature.VillagerClothingFeatureRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.ModelWithHat;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.entity.LivingEntity;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.village.VillagerDataContainer;
import net.minecraft.village.VillagerProfession;
import net.minecraft.village.VillagerType;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.render.IPonyRenderContext;
import com.minelittlepony.client.render.EquineRenderManager;
class ClothingLayer<
T extends LivingEntity & VillagerDataContainer,
M extends EntityModel<T> & IPonyModel<T> & ModelWithHat,
C extends FeatureRendererContext<T, M> & IPonyRenderContext<T, M>> extends VillagerClothingFeatureRenderer<T, M> {
private final EquineRenderManager<T, M> renderer;
public ClothingLayer(C context, String type) {
super(context, (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager(), type);
renderer = context.getInternalRenderer();
}
public static Identifier getClothingTexture(VillagerDataContainer entity, String entityType) {
VillagerProfession profession = entity.getVillagerData().getProfession();
return createTexture("minelittlepony", "profession", entityType, Registry.VILLAGER_PROFESSION.getId(profession));
}
public static Identifier getHatTexture(VillagerDataContainer entity, String entityType) {
VillagerType villagerType = entity.getVillagerData().getType();
return createTexture("minecraft", "type", entityType, Registry.VILLAGER_TYPE.getId(villagerType));
}
public static Identifier createTexture(String namespace, String type, String entityType, Identifier profession) {
return new Identifier(namespace, String.format("textures/entity/%s/%s/%s.png", entityType, type, profession.getPath()));
}
/*
* TODO: redirect textures
@Override
public void bindTexture(Identifier texture) {
if (texture != SpriteAtlasTexture.BLOCK_ATLAS_TEX) {
if (!"minelittlepony".contentEquals(texture.getNamespace())) {
texture = new Identifier("minelittlepony", texture.getPath());
}
}
renderer.updateMetadata(texture);
super.bindTexture(texture);
}
*/
}

View file

@ -0,0 +1,143 @@
package com.minelittlepony.client.render.entity.npc;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.feature.VillagerResourceMetadata;
import net.minecraft.client.render.entity.feature.VillagerResourceMetadata.HatType;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.ModelWithHat;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.SynchronousResourceReloadListener;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.DefaultedRegistry;
import net.minecraft.util.registry.Registry;
import net.minecraft.village.VillagerData;
import net.minecraft.village.VillagerDataContainer;
import net.minecraft.village.VillagerProfession;
import net.minecraft.village.VillagerType;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.render.IPonyRenderContext;
import com.minelittlepony.client.render.entity.feature.AbstractPonyFeature;
import java.io.IOException;
import java.util.Map;
class NpcClothingFeature<
T extends LivingEntity & VillagerDataContainer,
M extends EntityModel<T> & IPonyModel<T> & ModelWithHat,
C extends FeatureRendererContext<T, M> & IPonyRenderContext<T, M>> extends AbstractPonyFeature<T, M> implements SynchronousResourceReloadListener {
private static final Int2ObjectMap<Identifier> LEVEL_TO_ID = Util.create(new Int2ObjectOpenHashMap<>(), a -> {
a.put(1, new Identifier("stone"));
a.put(2, new Identifier("iron"));
a.put(3, new Identifier("gold"));
a.put(4, new Identifier("emerald"));
a.put(5, new Identifier("diamond"));
});
private final Object2ObjectMap<VillagerType, HatType> typeHatCache = new Object2ObjectOpenHashMap<>();
private final Object2ObjectMap<VillagerProfession, HatType> profHatCache = new Object2ObjectOpenHashMap<>();
private final String entityType;
private final ReloadableResourceManager resourceManager;
public NpcClothingFeature(C context, String type) {
super(context);
entityType = type;
resourceManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
resourceManager.registerListener(this);
}
public static Identifier getClothingTexture(VillagerDataContainer entity, String entityType) {
VillagerProfession profession = entity.getVillagerData().getProfession();
return createTexture("minelittlepony", "profession", entityType, Registry.VILLAGER_PROFESSION.getId(profession));
}
public static Identifier createTexture(String namespace, String type, String entityType, Identifier profession) {
return new Identifier(namespace, String.format("textures/entity/%s/%s/%s.png", entityType, type, profession.getPath()));
}
@Override
public void render(MatrixStack matrixStack, VertexConsumerProvider provider, int i, T entity, float f, float g, float h, float j, float k, float l) {
if (!entity.isInvisible()) {
VillagerData data = entity.getVillagerData();
VillagerType type = data.getType();
VillagerProfession profession = data.getProfession();
HatType typeHatLayer = getHatType(typeHatCache, "type", Registry.VILLAGER_TYPE, type);
HatType profHatLayer = getHatType(profHatCache, "profession", Registry.VILLAGER_PROFESSION, profession);
M entityModel = getModel();
entityModel.setHatVisible(
profHatLayer == VillagerResourceMetadata.HatType.NONE
|| (profHatLayer == VillagerResourceMetadata.HatType.PARTIAL && typeHatLayer != VillagerResourceMetadata.HatType.FULL)
);
Identifier typeSkin = findTexture("type", Registry.VILLAGER_TYPE.getId(type));
getContext().getInternalRenderer().updateMetadata(typeSkin);
renderModel(entityModel, typeSkin, matrixStack, provider, i, entity, 1, 1, 1);
entityModel.setHatVisible(true);
if (profession != VillagerProfession.NONE && !entity.isBaby()) {
Identifier professionSkin = findTexture("profession", Registry.VILLAGER_PROFESSION.getId(profession));
getContext().getInternalRenderer().updateMetadata(professionSkin);
renderModel(entityModel, professionSkin, matrixStack, provider, i, entity, 1, 1, 1);
if (profession != VillagerProfession.NITWIT) {
Identifier levelSkin = findTexture("profession_level", LEVEL_TO_ID.get(MathHelper.clamp(data.getLevel(), 1, LEVEL_TO_ID.size())));
renderModel(entityModel, levelSkin, matrixStack, provider, i, entity, 1, 1, 1);
}
}
}
}
public <K> VillagerResourceMetadata.HatType getHatType(Object2ObjectMap<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) {
if (cache.containsKey(key)) {
return cache.get(key); // People often complain that villagers cause lag,
// so let's do better than Mojang and rather NOT go
// through all the lambda generations if we can avoid it.
}
return loadHatType(cache, type, registry, key);
}
private <K> VillagerResourceMetadata.HatType loadHatType(Map<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) {
return cache.computeIfAbsent(key, k -> {
try (Resource res = resourceManager.getResource(findTexture(type, registry.getId(k)))) {
VillagerResourceMetadata meta = res.getMetadata(VillagerResourceMetadata.READER);
if (meta != null) {
return meta.getHatType();
}
} catch (IOException e) { }
return HatType.NONE;
});
}
@Override
public void apply(ResourceManager manager) {
profHatCache.clear();
typeHatCache.clear();
}
public Identifier findTexture(String category, Identifier identifier) {
return new Identifier("minelittlepony", "textures/entity/" + entityType + "/" + category + "/" + identifier.getPath() + ".png");
}
}

View file

@ -12,7 +12,6 @@ import net.minecraft.village.VillagerProfession;
import net.minecraft.village.VillagerType;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.util.resources.ITextureSupplier;
import java.util.HashMap;
import java.util.Map;
@ -21,9 +20,9 @@ import java.util.Optional;
/**
* Cached pool of villager textures.
*/
public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implements ITextureSupplier<T>, SynchronousResourceReloadListener {
public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implements TextureSupplier<T>, SynchronousResourceReloadListener {
private final ITextureSupplier<String> formatter;
private final TextureSupplier<String> formatter;
private final Identifier fallback;
@ -41,7 +40,7 @@ public class PonyTextures<T extends LivingEntity & VillagerDataContainer> implem
* @param keyMapper Mapper to convert integer ids into a string value for format insertion
* @param fallback The default if any generated textures fail to load. This is stored in place of failing textures.
*/
public PonyTextures(ITextureSupplier<String> formatter) {
public PonyTextures(TextureSupplier<String> formatter) {
this.resourceManager = (ReloadableResourceManager)MinecraftClient.getInstance().getResourceManager();
this.formatter = formatter;
this.fallback = formatter.supplyTexture("villager_pony");

View file

@ -1,4 +1,4 @@
package com.minelittlepony.util.resources;
package com.minelittlepony.client.render.entity.npc;
import net.minecraft.util.Identifier;
@ -6,13 +6,13 @@ import net.minecraft.util.Identifier;
* A texture pool for generating multiple associated textures.
*/
@FunctionalInterface
public interface ITextureSupplier<T> {
public interface TextureSupplier<T> {
/**
* Supplies a new texture. May be generated for returned from a pool indexed by the given key.
*/
Identifier supplyTexture(T key);
static ITextureSupplier<String> formatted(String domain, String path) {
static TextureSupplier<String> formatted(String domain, String path) {
return key -> new Identifier(domain, String.format(path, key));
}
}

View file

@ -2,18 +2,17 @@ package com.minelittlepony.client.render.entity.npc;
import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.client.model.entity.VillagerPonyModel;
import com.minelittlepony.util.resources.ITextureSupplier;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.passive.VillagerEntity;
public class RenderPonyVillager extends AbstractVillagerRenderer<VillagerEntity, VillagerPonyModel<VillagerEntity>> {
public class VillagerPonyRenderer extends AbstractNpcRenderer<VillagerEntity, VillagerPonyModel<VillagerEntity>> {
private static final String TYPE = "villager";
private static final ITextureSupplier<String> FORMATTER = ITextureSupplier.formatted("minelittlepony", "textures/entity/villager/%s.png");
private static final TextureSupplier<String> FORMATTER = TextureSupplier.formatted("minelittlepony", "textures/entity/villager/%s.png");
public RenderPonyVillager(EntityRenderDispatcher manager) {
public VillagerPonyRenderer(EntityRenderDispatcher manager) {
super(manager, ModelType.VILLAGER, TYPE, FORMATTER);
}

View file

@ -2,18 +2,17 @@ package com.minelittlepony.client.render.entity.npc;
import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.client.model.entity.ZomponyVillagerModel;
import com.minelittlepony.util.resources.ITextureSupplier;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.mob.ZombieVillagerEntity;
public class RenderPonyZombieVillager extends AbstractVillagerRenderer<ZombieVillagerEntity, ZomponyVillagerModel> {
public class ZomponyVillagerRenderer extends AbstractNpcRenderer<ZombieVillagerEntity, ZomponyVillagerModel> {
private static final String TYPE = "zombie_villager";
private static final ITextureSupplier<String> FORMATTER = ITextureSupplier.formatted("minelittlepony", "textures/entity/zombie_villager/zombie_%s.png");
private static final TextureSupplier<String> FORMATTER = TextureSupplier.formatted("minelittlepony", "textures/entity/zombie_villager/zombie_%s.png");
public RenderPonyZombieVillager(EntityRenderDispatcher manager) {
public ZomponyVillagerRenderer(EntityRenderDispatcher manager) {
super(manager, ModelType.ZOMBIE_VILLAGER, TYPE, FORMATTER);
}

View file

@ -1,7 +1,7 @@
package com.minelittlepony.client.transform;
import com.minelittlepony.model.IModel;
import com.minelittlepony.util.transform.MotionCompositor;
import com.minelittlepony.util.MotionCompositor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.client.util.math.MatrixStack;

View file

@ -3,7 +3,8 @@ package com.minelittlepony.model;
import com.minelittlepony.client.render.EquineRenderManager;
import com.minelittlepony.client.render.EquineRenderManager.Mode;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.util.math.MathUtil;
import com.minelittlepony.util.MathUtil;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Arm;

View file

@ -5,7 +5,7 @@ import com.minelittlepony.pony.meta.Race;
import com.minelittlepony.pony.meta.Size;
import com.minelittlepony.pony.meta.TailLength;
import com.minelittlepony.pony.meta.Wearable;
import com.minelittlepony.util.animation.IInterpolator;
import com.minelittlepony.util.IInterpolator;
import java.util.UUID;

View file

@ -3,7 +3,7 @@ package com.minelittlepony.pony.meta;
import net.minecraft.client.texture.NativeImage;
import com.minelittlepony.pony.ITriggerPixelMapped;
import com.minelittlepony.util.math.Color;
import com.minelittlepony.util.Color;
/**
* Individual trigger pixels for a pony skin.

View file

@ -1,4 +1,4 @@
package com.minelittlepony.util.animation;
package com.minelittlepony.util;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;

View file

@ -1,4 +1,4 @@
package com.minelittlepony.util.math;
package com.minelittlepony.util;
/**
* Colouration Utilities

View file

@ -1,4 +1,4 @@
package com.minelittlepony.util.animation;
package com.minelittlepony.util;
/**
* Interpolator function for handling transitions between animation states.

View file

@ -1,4 +1,4 @@
package com.minelittlepony.util.math;
package com.minelittlepony.util;
import net.minecraft.util.math.MathHelper;

View file

@ -1,10 +1,8 @@
package com.minelittlepony.util.transform;
package com.minelittlepony.util;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.MathHelper;
import com.minelittlepony.util.math.MathUtil;
/**
* Calculates roll and incline for a player based on their motion vectors.
*

View file

@ -1,4 +0,0 @@
@ParametersAreNonnullByDefault
package com.minelittlepony.util.animation;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,4 +1,4 @@
@ParametersAreNonnullByDefault
package com.minelittlepony.util.math;
package com.minelittlepony.util;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,4 +0,0 @@
@ParametersAreNonnullByDefault
package com.minelittlepony.util.resources;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,4 +0,0 @@
@ParametersAreNonnullByDefault
package com.minelittlepony.util.transform;
import javax.annotation.ParametersAreNonnullByDefault;