Remove unneccessary layers when rendering villagers. Should help with #222

This commit is contained in:
Sollace 2022-12-21 23:02:43 +01:00
parent 8c1a705b9e
commit 540f8b9f3f
2 changed files with 12 additions and 5 deletions

View file

@ -3,7 +3,6 @@ package com.minelittlepony.client.render.entity.feature;
import net.minecraft.client.render.*;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.random.Random;
@ -35,13 +34,13 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
MOD_GEARS.stream().map(e -> new Entry(e.get(), Wearable.NONE))
).collect(Collectors.toList());
private final LoadingCache<Entity, List<Entry>> randomisedGearCache = CacheBuilder.newBuilder()
private final LoadingCache<UUID, List<Entry>> randomisedGearCache = CacheBuilder.newBuilder()
.expireAfterAccess(3, TimeUnit.MINUTES)
.build(CacheLoader.from(entity -> {
.build(CacheLoader.from(uuid -> {
List<Entry> randomizedOrder = new ArrayList<>();
List<Entry> pool = new ArrayList<>(gears);
Random rng = Random.create(entity.getUuid().getLeastSignificantBits());
Random rng = Random.create(uuid.getLeastSignificantBits());
while (!pool.isEmpty()) {
randomizedOrder.add(pool.remove(rng.nextInt(pool.size() + 1) % pool.size()));
@ -63,7 +62,7 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
final Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
randomisedGearCache.getUnchecked(entity)
randomisedGearCache.getUnchecked(entity.getUuid())
.stream()
.filter(entry -> getContext().shouldRender(model, entity, entry.wearable, entry.gear))
.forEach(entry -> {

View file

@ -13,6 +13,7 @@ import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.api.pony.meta.Wearable;
import com.minelittlepony.client.model.*;
import com.minelittlepony.client.render.entity.PonyRenderer;
import com.minelittlepony.client.render.entity.feature.*;
import com.minelittlepony.client.render.entity.npc.textures.*;
import java.util.HashMap;
@ -36,6 +37,12 @@ abstract class AbstractNpcRenderer<T extends MobEntity & VillagerDataContainer>
addFeature(clothing);
}
@Override
protected void addLayers(EntityRendererFactory.Context context) {
addFeature(createItemHoldingLayer());
addFeature(new GearFeature<>(this));
}
@Override
public boolean shouldRender(ClientPonyModel<T> model, T entity, Wearable wearable, IGear gear) {
@ -58,6 +65,7 @@ abstract class AbstractNpcRenderer<T extends MobEntity & VillagerDataContainer>
return super.shouldRender(model, entity, wearable, gear);
}
@Override
public void render(T entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
model = manager.setModel(models.computeIfAbsent(getEntityPony(entity).race(), this::createModel)).body();