From bc19a32a41bc98240d52b7aee8bbe8ebd9d39477 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 20 Sep 2022 18:16:33 +0200 Subject: [PATCH] Fixed magic rendering around polearms --- .../client/minelittlepony/MineLPConnector.java | 18 ++++++++++++++++++ .../client/render/PolearmRenderer.java | 8 +++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java index b3432117..436879e2 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/MineLPConnector.java @@ -1,11 +1,17 @@ package com.minelittlepony.unicopia.client.minelittlepony; +import java.util.Optional; + import com.minelittlepony.client.MineLittlePony; +import com.minelittlepony.client.render.LevitatingItemRenderer; import com.minelittlepony.unicopia.Race; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Identifier; public final class MineLPConnector { public static Race getPlayerPonyRace() { @@ -39,4 +45,16 @@ public final class MineLPConnector { return Race.HUMAN; } } + + public static Optional getItemBuffer(VertexConsumerProvider vertexConsumers, Identifier texture) { + if (!FabricLoader.getInstance().isModLoaded("minelp")) { + return Optional.empty(); + } + + if (LevitatingItemRenderer.isEnabled()) { + return Optional.of(vertexConsumers.getBuffer(LevitatingItemRenderer.getRenderLayer(texture))); + } + + return Optional.empty(); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java index 04170d03..72ac6310 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.client.render; +import com.minelittlepony.unicopia.client.minelittlepony.MineLPConnector; + import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer; @@ -7,7 +9,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.item.UnclampedModelPredicateProvider; import net.minecraft.client.model.*; -import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.model.TridentEntityModel; import net.minecraft.client.render.item.ItemRenderer; @@ -69,8 +70,9 @@ public class PolearmRenderer implements DynamicItemRenderer, UnclampedModelPredi matrices.scale(1, -1, -1); Identifier id = Registry.ITEM.getId(stack.getItem()); Identifier texture = new Identifier(id.getNamespace(), "textures/entity/polearm/" + id.getPath() + ".png"); - VertexConsumer vertexConsumer2 = ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(texture), false, stack.hasGlint()); - model.render(matrices, vertexConsumer2, light, overlay, 1, 1, 1, 1); + model.render(matrices, MineLPConnector.getItemBuffer(vertexConsumers, texture).orElseGet(() -> { + return ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(texture), false, stack.hasGlint()); + }), light, overlay, 1, 1, 1, 1); matrices.pop(); } }