Fixed magic rendering around polearms

This commit is contained in:
Sollace 2022-09-20 18:16:33 +02:00
parent 2f65f5b0c0
commit bc19a32a41
2 changed files with 23 additions and 3 deletions

View file

@ -1,11 +1,17 @@
package com.minelittlepony.unicopia.client.minelittlepony; package com.minelittlepony.unicopia.client.minelittlepony;
import java.util.Optional;
import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.LevitatingItemRenderer;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient; 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.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
public final class MineLPConnector { public final class MineLPConnector {
public static Race getPlayerPonyRace() { public static Race getPlayerPonyRace() {
@ -39,4 +45,16 @@ public final class MineLPConnector {
return Race.HUMAN; return Race.HUMAN;
} }
} }
public static Optional<VertexConsumer> 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();
}
} }

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.client.render; 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.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer; 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.ModelPredicateProviderRegistry;
import net.minecraft.client.item.UnclampedModelPredicateProvider; import net.minecraft.client.item.UnclampedModelPredicateProvider;
import net.minecraft.client.model.*; import net.minecraft.client.model.*;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.model.TridentEntityModel; import net.minecraft.client.render.entity.model.TridentEntityModel;
import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.render.item.ItemRenderer;
@ -69,8 +70,9 @@ public class PolearmRenderer implements DynamicItemRenderer, UnclampedModelPredi
matrices.scale(1, -1, -1); matrices.scale(1, -1, -1);
Identifier id = Registry.ITEM.getId(stack.getItem()); Identifier id = Registry.ITEM.getId(stack.getItem());
Identifier texture = new Identifier(id.getNamespace(), "textures/entity/polearm/" + id.getPath() + ".png"); 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, MineLPConnector.getItemBuffer(vertexConsumers, texture).orElseGet(() -> {
model.render(matrices, vertexConsumer2, light, overlay, 1, 1, 1, 1); return ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(texture), false, stack.hasGlint());
}), light, overlay, 1, 1, 1, 1);
matrices.pop(); matrices.pop();
} }
} }