From 62ca1de5964d2023f1de20846061bf0029b82c50 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 10 Feb 2021 13:18:01 +0200 Subject: [PATCH] Added support for a glowing effect around glowing bracelets when canvas is installed --- build.gradle | 16 +++++++++-- gradle.properties | 3 +- .../render/BraceletFeatureRenderer.java | 8 ++++-- .../unicopia/client/render/CanvasCompat.java | 28 +++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/client/render/CanvasCompat.java diff --git a/build.gradle b/build.gradle index 81b6d481..a205b869 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,14 @@ minecraft { } repositories { + maven { + name = "dblsaiko" + url = "https://maven.dblsaiko.net/" + } + maven { + name = "Cotton" + url = "http://server.bbkr.space:8081/artifactory/libs-release/" + } maven { name = 'minelp' url = 'http://repo.minelittlepony-mod.com/maven/snapshot' @@ -50,9 +58,9 @@ dependencies { //modApi "net.fabricmc.fabric-api:fabric-events-lifecycle-v0:0.1.0+" //modApi "net.fabricmc.fabric-api:fabric-resource-loader-v0:0.1.0+" - modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modApi "com.minelittlepony:MineLittlePony:${project.minelp_version}" + modApi "com.minelittlepony:MineLittlePony:${project.minelp_version}" modApi "com.minelittlepony:Kirin:${project.kirin_version}" include "com.minelittlepony:Kirin:${project.kirin_version}" @@ -60,6 +68,10 @@ dependencies { modCompileOnly("io.github.prospector:modmenu:${project.modmenu_version}") { transitive = false } + modCompileOnly("grondag:canvas-mc116:${project.canvas_version}") { + exclude(group: "net.fabricmc.fabric-api") + exclude(module: "fabric-loader") + } } processResources { diff --git a/gradle.properties b/gradle.properties index c77a33f1..28fe2952 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.daemon=false minecraft_version=1.16.4 yarn_mappings=1.16.4+build.6 loader_version=0.10.6+build.214 - fabric_version=0.25.1+build.416-1.16 + fabric_version=0.30.0+1.16 # Mod Properties group=com.minelittlepony @@ -18,5 +18,6 @@ org.gradle.daemon=false # Dependencies modmenu_version=1.14.+ + canvas_version=1.0.+ minelp_version=4.2.1-1.16.2-SNAPSHOT kirin_version=1.7.1-1.16.2-SNAPSHOT diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/BraceletFeatureRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/BraceletFeatureRenderer.java index b2a193fd..613bba3a 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/BraceletFeatureRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/BraceletFeatureRenderer.java @@ -14,7 +14,6 @@ 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.item.ItemRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; @@ -59,10 +58,13 @@ public class BraceletFeatureRenderer< arm.render(stack, consumer, lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); } - VertexConsumer consumer = ItemRenderer.getArmorGlintConsumer(renderContext, RenderLayer.getArmorCutoutNoCull(TEXTURE), false, false); + boolean glowing = ((GlowableItem)item.getItem()).isGlowing(item); + + VertexConsumer consumer = CanvasCompat.getGlowingConsumer(glowing, renderContext, RenderLayer.getArmorCutoutNoCull(TEXTURE)); + model.setAngles(getContextModel()); model.setVisible(entity.getMainArm()); - model.render(stack, consumer, ((GlowableItem)item.getItem()).isGlowing(item) ? 0x0F00F0 : lightUv, OverlayTexture.DEFAULT_UV, Color.r(j), Color.g(j), Color.b(j), 1); + model.render(stack, consumer, glowing ? 0x0F00F0 : lightUv, OverlayTexture.DEFAULT_UV, Color.r(j), Color.g(j), Color.b(j), 1); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/CanvasCompat.java b/src/main/java/com/minelittlepony/unicopia/client/render/CanvasCompat.java new file mode 100644 index 00000000..e59ea979 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/client/render/CanvasCompat.java @@ -0,0 +1,28 @@ +package com.minelittlepony.unicopia.client.render; + +import grondag.canvas.material.state.MaterialFinderImpl; +import grondag.canvas.material.state.RenderLayerHelper; +import grondag.frex.api.material.FrexVertexConsumerProvider; +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.item.ItemRenderer; + +final class CanvasCompat { + static VertexConsumer getGlowingConsumer(boolean glowing, VertexConsumerProvider renderContext, RenderLayer layer) { + if (!glowing || !RendererAccess.INSTANCE.hasRenderer() || !FabricLoader.getInstance().isModLoaded("canvas")) { + return ItemRenderer.getArmorGlintConsumer(renderContext, layer, false, false); + } + + if (!(renderContext instanceof FrexVertexConsumerProvider)) { + return ItemRenderer.getArmorGlintConsumer(renderContext, layer, false, false); + } + + return ((FrexVertexConsumerProvider)renderContext).getConsumer(MaterialFinderImpl.threadLocal() + .copyFrom(RenderLayerHelper.copyFromLayer(layer)) + .emissive(true) + .find()); + } +}