Fixed magic not rendering for items held by other entities

This commit is contained in:
Sollace 2023-10-06 00:45:48 +01:00
parent a7acd2a1c1
commit fa0c903c0f
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 25 additions and 21 deletions

View file

@ -1,7 +1,7 @@
package com.minelittlepony.client.render; package com.minelittlepony.client.render;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.IPony; import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.util.render.RenderLayerUtil; import com.minelittlepony.client.util.render.RenderLayerUtil;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -11,7 +11,6 @@ import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.CrossbowItem; import net.minecraft.item.CrossbowItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.screen.PlayerScreenHandler;
@ -37,32 +36,36 @@ public class LevitatingItemRenderer {
*/ */
public void renderItem(ItemRenderer itemRenderer, @Nullable LivingEntity entity, ItemStack stack, ModelTransformationMode mode, boolean left, MatrixStack matrix, VertexConsumerProvider renderContext, @Nullable World world, int lightUv, int posLong) { public void renderItem(ItemRenderer itemRenderer, @Nullable LivingEntity entity, ItemStack stack, ModelTransformationMode mode, boolean left, MatrixStack matrix, VertexConsumerProvider renderContext, @Nullable World world, int lightUv, int posLong) {
if (entity instanceof PlayerEntity && (mode.isFirstPerson() || mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND || mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND)) { if (mode.isFirstPerson()
|| mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND
|| mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND
) {
IPony.getManager().getPony(entity).ifPresentOrElse(pony -> {
matrix.push();
IPony pony = IPony.getManager().getPony((PlayerEntity)entity); boolean doMagic = PonyConfig.getInstance().fpsmagic.get() && pony.hasMagic();
matrix.push(); if (doMagic && mode.isFirstPerson()) {
setupPerspective(itemRenderer, entity, stack, left, matrix);
}
boolean doMagic = MineLittlePony.getInstance().getConfig().fpsmagic.get() && pony.hasMagic(); itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
if (doMagic && mode.isFirstPerson()) { if (doMagic) {
setupPerspective(itemRenderer, entity, stack, left, matrix); VertexConsumerProvider interceptedContext = getProvider(pony, renderContext);
}
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong); matrix.scale(1.1F, 1.1F, 1.1F);
matrix.translate(0.015F, 0.01F, 0.01F);
if (doMagic) { itemRenderer.renderItem(entity, stack, mode, left, matrix, interceptedContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
VertexConsumerProvider interceptedContext = getProvider(pony, renderContext); matrix.translate(-0.03F, -0.02F, -0.02F);
itemRenderer.renderItem(entity, stack, mode, left, matrix, interceptedContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
}
matrix.scale(1.1F, 1.1F, 1.1F); matrix.pop();
matrix.translate(0.015F, 0.01F, 0.01F); }, () -> {
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
itemRenderer.renderItem(entity, stack, mode, left, matrix, interceptedContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong); });
matrix.translate(-0.03F, -0.02F, -0.02F);
itemRenderer.renderItem(entity, stack, mode, left, matrix, interceptedContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
}
matrix.pop();
} else { } else {
itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong); itemRenderer.renderItem(entity, stack, mode, left, matrix, renderContext, world, lightUv, OverlayTexture.DEFAULT_UV, posLong);
} }

View file

@ -37,6 +37,7 @@ public class HeldItemFeature<T extends LivingEntity, M extends EntityModel<T> &
return main ? entity.getMainHandStack() : entity.getOffHandStack(); return main ? entity.getMainHandStack() : entity.getOffHandStack();
} }
@Override @Override
public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) {