mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 12:37:59 +01:00
Use a fast map for storing gear offsets and unravel lambdas
This commit is contained in:
parent
24ed233210
commit
7fe4aa0d36
1 changed files with 14 additions and 16 deletions
|
@ -1,5 +1,7 @@
|
||||||
package com.minelittlepony.client.render.entity.feature;
|
package com.minelittlepony.client.render.entity.feature;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2FloatLinkedOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
|
||||||
import net.minecraft.client.render.*;
|
import net.minecraft.client.render.*;
|
||||||
import net.minecraft.client.render.entity.model.EntityModel;
|
import net.minecraft.client.render.entity.model.EntityModel;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
@ -34,13 +36,13 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
|
||||||
MOD_GEARS.stream().map(e -> new Entry(e.get(), Wearable.NONE))
|
MOD_GEARS.stream().map(e -> new Entry(e.get(), Wearable.NONE))
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
|
|
||||||
private final LoadingCache<UUID, List<Entry>> randomisedGearCache = CacheBuilder.newBuilder()
|
private final LoadingCache<Long, List<Entry>> randomisedGearCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterAccess(3, TimeUnit.MINUTES)
|
.expireAfterAccess(3, TimeUnit.MINUTES)
|
||||||
.build(CacheLoader.from(uuid -> {
|
.build(CacheLoader.from(id -> {
|
||||||
List<Entry> randomizedOrder = new ArrayList<>();
|
List<Entry> randomizedOrder = new ArrayList<>();
|
||||||
List<Entry> pool = new ArrayList<>(gears);
|
List<Entry> pool = new ArrayList<>(gears);
|
||||||
|
|
||||||
Random rng = Random.create(uuid.getLeastSignificantBits());
|
Random rng = Random.create(id);
|
||||||
|
|
||||||
while (!pool.isEmpty()) {
|
while (!pool.isEmpty()) {
|
||||||
randomizedOrder.add(pool.remove(rng.nextInt(pool.size() + 1) % pool.size()));
|
randomizedOrder.add(pool.remove(rng.nextInt(pool.size() + 1) % pool.size()));
|
||||||
|
@ -59,30 +61,26 @@ public class GearFeature<T extends LivingEntity, M extends EntityModel<T> & IPon
|
||||||
}
|
}
|
||||||
|
|
||||||
final M model = getModelWrapper().body();
|
final M model = getModelWrapper().body();
|
||||||
|
final Object2FloatMap<BodyPart> renderStackingOffsets = new Object2FloatLinkedOpenHashMap<>();
|
||||||
|
|
||||||
final Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
for (var entry : randomisedGearCache.getUnchecked(entity.getUuid().getLeastSignificantBits())) {
|
||||||
|
|
||||||
randomisedGearCache.getUnchecked(entity.getUuid()).forEach(entry -> {
|
|
||||||
if (getContext().shouldRender(model, entity, entry.wearable, entry.gear)) {
|
if (getContext().shouldRender(model, entity, entry.wearable, entry.gear)) {
|
||||||
stack.push();
|
stack.push();
|
||||||
BodyPart part = entry.gear.getGearLocation();
|
BodyPart part = entry.gear.getGearLocation();
|
||||||
entry.gear.transform(model, stack);
|
entry.gear.transform(model, stack);
|
||||||
|
|
||||||
if (entry.gear instanceof IStackable) {
|
if (entry.gear instanceof IStackable s) {
|
||||||
renderStackingOffsets.compute(part, (k, v) -> {
|
float v = renderStackingOffsets.getFloat(part);
|
||||||
float offset = ((IStackable)entry.gear).getStackingHeight();
|
if (v != 0) {
|
||||||
if (v != null) {
|
stack.translate(0, -v, 0);
|
||||||
stack.translate(0, -v, 0);
|
}
|
||||||
offset += v;
|
renderStackingOffsets.put(part, v + s.getStackingHeight());
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderGear(model, entity, entry.gear, stack, renderContext, lightUv, limbDistance, limbAngle, tickDelta);
|
renderGear(model, entity, entry.gear, stack, renderContext, lightUv, limbDistance, limbAngle, tickDelta);
|
||||||
stack.pop();
|
stack.pop();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderGear(M model, T entity, IGear gear, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, float limbDistance, float limbAngle, float tickDelta) {
|
private void renderGear(M model, T entity, IGear gear, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, float limbDistance, float limbAngle, float tickDelta) {
|
||||||
|
|
Loading…
Reference in a new issue