Fixed spells not rendering on non-pony entities

This commit is contained in:
Sollace 2024-01-22 13:48:24 +00:00
parent 39672e5028
commit 34aa3b8ced
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 49 additions and 41 deletions

View file

@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.client.FirstPersonRendererOverrides.ArmRenderer;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate;
import com.minelittlepony.unicopia.client.render.spell.SpellEffectsRenderDispatcher;
import net.minecraft.client.MinecraftClient;
@ -13,14 +14,14 @@ import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Arm;
public class AccessoryFeatureRenderer<
T extends LivingEntity,
M extends BipedEntityModel<T>> extends FeatureRenderer<T, M> {
M extends EntityModel<T>> extends FeatureRenderer<T, M> {
private static final List<FeatureFactory<?>> REGISTRY = new ArrayList<>();
@ -40,6 +41,10 @@ public class AccessoryFeatureRenderer<
@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if (MineLPDelegate.getInstance().getRace(entity).isEquine()) {
return;
}
features.forEach(feature -> feature.render(matrices, vertexConsumers, light, entity, limbAngle, limbDistance, tickDelta, animationProgress, headYaw, headPitch));
Caster.of(entity).ifPresent(caster -> {
@ -60,7 +65,7 @@ public class AccessoryFeatureRenderer<
}
public interface FeatureFactory<T extends LivingEntity> {
Feature<T> create(FeatureRendererContext<T, ? extends BipedEntityModel<T>> context);
Feature<T> create(FeatureRendererContext<T, ? extends EntityModel<T>> context);
}
public interface Feature<T extends LivingEntity> {
@ -75,11 +80,11 @@ public class AccessoryFeatureRenderer<
public interface FeatureRoot<
T extends LivingEntity,
M extends BipedEntityModel<T>> {
M extends EntityModel<T>> {
AccessoryFeatureRenderer<T, M> getAccessories();
@SuppressWarnings("unchecked")
@Nullable
static <T extends LivingEntity, M extends BipedEntityModel<T>> FeatureRoot<T, M> of(T entity) {
static <T extends LivingEntity, M extends EntityModel<T>> FeatureRoot<T, M> of(T entity) {
var renderer = MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(entity);
if (renderer instanceof FeatureRoot) {
return (FeatureRoot<T, M>)renderer;

View file

@ -1,19 +1,9 @@
package com.minelittlepony.unicopia.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.unicopia.client.render.AccessoryFeatureRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
@Mixin(ArmorFeatureRenderer.class)
@ -21,13 +11,13 @@ abstract class MixinArmorFeatureRenderer<
T extends LivingEntity,
M extends BipedEntityModel<T>,
A extends BipedEntityModel<T>>
extends FeatureRenderer<T, M> implements AccessoryFeatureRenderer.FeatureRoot<T, M> {
extends FeatureRenderer<T, M>/* implements AccessoryFeatureRenderer.FeatureRoot<T, M>*/ {
private AccessoryFeatureRenderer<T, M> accessories;
//private AccessoryFeatureRenderer<T, M> accessories;
MixinArmorFeatureRenderer() { super(null); }
@Override
/*@Override
public AccessoryFeatureRenderer<T, M> getAccessories() {
return accessories;
}
@ -40,5 +30,5 @@ abstract class MixinArmorFeatureRenderer<
@Inject(method = "render", at = @At("RETURN"))
private void onRender(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch, CallbackInfo info) {
getAccessories().render(stack, renderContext, lightUv, entity, limbDistance, limbAngle, tickDelta, age, headYaw, headPitch);
}
}*/
}

View file

@ -1,17 +1,25 @@
package com.minelittlepony.unicopia.mixin.client;
import java.util.List;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.unicopia.client.render.AccessoryFeatureRenderer;
import com.minelittlepony.unicopia.client.render.AnimalPoser;
import com.minelittlepony.unicopia.client.render.PlayerPoser;
import com.minelittlepony.unicopia.client.render.AccessoryFeatureRenderer.FeatureRoot;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.render.entity.model.EntityModel;
@ -21,8 +29,31 @@ import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
@Mixin(LivingEntityRenderer.class)
abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends EntityModel<T>> extends EntityRenderer<T> implements FeatureRendererContext<T, M> {
abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends EntityModel<T>> extends EntityRenderer<T>
implements FeatureRendererContext<T, M>, FeatureRoot<T, M> {
@Shadow
private @Final List<FeatureRenderer<T, M>> features;
MixinLivingEntityRenderer() { super(null); }
@Nullable
private AccessoryFeatureRenderer<T, M> accessories;
@Override
@SuppressWarnings("unchecked")
public AccessoryFeatureRenderer<T, M> getAccessories() {
if (accessories == null) {
accessories = features.stream()
.filter(a -> a instanceof FeatureRoot)
.map(a -> ((FeatureRoot<T, M>)a).getAccessories())
.findFirst()
.orElseGet(() -> {
var feature = new AccessoryFeatureRenderer<>(this);
features.add(feature);
return feature;
});
}
return accessories;
}
@Inject(method = "render",
at = @At(
@ -36,6 +67,7 @@ abstract class MixinLivingEntityRenderer<T extends LivingEntity, M extends Entit
VertexConsumerProvider vertices,
int light,
CallbackInfo into) {
getAccessories();
if (entity instanceof PlayerEntity player) {
PlayerPoser.INSTANCE.applyPosing(matrices, player, (BipedEntityModel<?>)getModel(), PlayerPoser.Context.THIRD_PERSON);
}

View file

@ -1,13 +1,11 @@
package com.minelittlepony.unicopia.mixin.client;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.unicopia.client.render.AccessoryFeatureRenderer;
import com.minelittlepony.unicopia.client.render.PlayerPoser;
import com.minelittlepony.unicopia.client.render.AccessoryFeatureRenderer.FeatureRoot;
@ -21,31 +19,14 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Arm;
@Mixin(PlayerEntityRenderer.class)
abstract class MixinPlayerEntityRenderer
extends LivingEntityRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>>
implements FeatureRoot<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {
@Nullable
private AccessoryFeatureRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> accessories;
abstract class MixinPlayerEntityRenderer extends LivingEntityRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {
MixinPlayerEntityRenderer() { super(null, null, 0); }
@Override
@SuppressWarnings("unchecked")
public AccessoryFeatureRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> getAccessories() {
if (accessories == null) {
accessories = features.stream()
.filter(a -> a instanceof FeatureRoot)
.map(a -> ((FeatureRoot<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>>)a).getAccessories())
.findFirst()
.orElseGet(() -> new AccessoryFeatureRenderer<>(this));
}
return accessories;
}
@Inject(method = "renderArm", at = @At("RETURN"))
private void onRenderArm(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, ModelPart arm, ModelPart sleeve, CallbackInfo info) {
Arm a = this.getModel().leftArm == arm ? Arm.LEFT : Arm.RIGHT;
getAccessories().renderArm(matrices, vertexConsumers, light, player, arm, a);
((FeatureRoot<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>>)this).getAccessories().renderArm(matrices, vertexConsumers, light, player, arm, a);
}
@Inject(method = "renderArm",