From 437bb67fdf94f4cb3125f360048b3b6b9710be1e Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Wed, 26 Jun 2024 13:43:52 +0800 Subject: [PATCH] fixed nametag lighting & double essential --- .../mixin/EntityRendererMixin.java | 5 ++ .../polynametag/mixin/GuiInventoryMixin.java | 14 ++++++ .../polynametag/mixin/MinecraftAccessor.java | 14 ++++++ .../polynametag/mixin/RenderMixin.java | 3 +- .../mixin/RendererLivingEntityMixin.java | 4 +- .../org/polyfrost/polynametag/PolyNametag.kt | 50 +++++++++++-------- .../polyfrost/polynametag/config/ModConfig.kt | 8 ++- src/main/resources/mixins.polynametag.json | 1 + 8 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 src/main/java/org/polyfrost/polynametag/mixin/MinecraftAccessor.java diff --git a/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java index 25558fd..c3f1384 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/EntityRendererMixin.java @@ -19,4 +19,9 @@ private void start(float partialTicks, long finishTimeNano, CallbackInfo ci) { private void end(float partialTicks, long finishTimeNano, CallbackInfo ci) { PolyNametag.INSTANCE.setDrawingWorld(false); } + + @Inject(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/client/renderer/culling/ICamera;F)V", shift = At.Shift.AFTER)) + private void draw(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) { + PolyNametag.INSTANCE.onRender(); + } } \ No newline at end of file diff --git a/src/main/java/org/polyfrost/polynametag/mixin/GuiInventoryMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/GuiInventoryMixin.java index 1aa120e..88311a3 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/GuiInventoryMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/GuiInventoryMixin.java @@ -1,8 +1,12 @@ package org.polyfrost.polynametag.mixin; +import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiInventory; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.entity.EntityLivingBase; +import org.polyfrost.polynametag.PolyNametag; +import org.polyfrost.polynametag.config.ModConfig; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -13,6 +17,16 @@ public class GuiInventoryMixin { @Inject(method = "drawEntityOnScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderManager;renderEntityWithPosYaw(Lnet/minecraft/entity/Entity;DDDFF)Z")) private static void start(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent, CallbackInfo ci) { Minecraft.getMinecraft().getRenderManager().playerViewX = 0f; + int i = 15728880; + int j = i % 65536; + int k = i / 65536; + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) j, (float) k); + PolyNametag.INSTANCE.setDrawingInventory(true); + } + + @Inject(method = "drawEntityOnScreen", at = @At("TAIL")) + private static void end(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent, CallbackInfo ci) { + PolyNametag.INSTANCE.setDrawingInventory(false); } } diff --git a/src/main/java/org/polyfrost/polynametag/mixin/MinecraftAccessor.java b/src/main/java/org/polyfrost/polynametag/mixin/MinecraftAccessor.java new file mode 100644 index 0000000..03ed6f7 --- /dev/null +++ b/src/main/java/org/polyfrost/polynametag/mixin/MinecraftAccessor.java @@ -0,0 +1,14 @@ +package org.polyfrost.polynametag.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.Timer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(Minecraft.class) +public interface MinecraftAccessor { + + @Accessor + Timer getTimer(); + +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java index b2ca401..38b5e95 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/RenderMixin.java @@ -95,7 +95,7 @@ private void drawBG(Entity entityIn, String str, double x, double y, double z, i private void move(Entity entityIn, String str, double x, double y, double z, int maxDistance, CallbackInfo ci) { if (!ModConfig.INSTANCE.enabled) return; if (!PolyNametag.INSTANCE.getDrawing() && PolyNametag.INSTANCE.getDrawingWorld()) { - PolyNametag.INSTANCE.getLabels().add(new PolyNametag.LabelInfo((Render) (Object) this, entityIn, str, x, y, z, maxDistance)); + PolyNametag.INSTANCE.getNametags().add(new PolyNametag.LabelInfo((Render) (Object) this, entityIn, str, x, y, z, maxDistance)); ci.cancel(); } } @@ -120,6 +120,7 @@ private void essential(Entity entityIn, String str, double x, double y, double z PolyNametag.INSTANCE.setDrawingEssential(true); NametagRenderingKt.drawIndicator(entityIn, str); PolyNametag.INSTANCE.setDrawingEssential(false); + instance.setDrawEssential(false); } } diff --git a/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java b/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java index 516da9a..78d2b9f 100644 --- a/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java +++ b/src/main/java/org/polyfrost/polynametag/mixin/RendererLivingEntityMixin.java @@ -30,7 +30,7 @@ public abstract class RendererLivingEntityMixin { ) ) private Entity polyNametag$cancelSelfCheck(RenderManager renderManager) { - boolean shouldShowOwnNametag = ((ModConfig.INSTANCE.enabled && ModConfig.INSTANCE.getShowOwnNametag() && (!PolyNametag.INSTANCE.getDrawingWorld() || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0)) || ModConfig.INSTANCE.getNametagPreview().getDrawing()); + boolean shouldShowOwnNametag = ((ModConfig.INSTANCE.enabled && ModConfig.INSTANCE.getShowOwnNametag() && (ModConfig.INSTANCE.getShowInInventory() || !PolyNametag.INSTANCE.getDrawingInventory()) && (!PolyNametag.INSTANCE.getDrawingWorld() || Minecraft.getMinecraft().gameSettings.thirdPersonView != 0)) || ModConfig.INSTANCE.getNametagPreview().getDrawing()); return shouldShowOwnNametag ? null : renderManager.livingPlayer; } @@ -109,7 +109,7 @@ private void drawBG(EntityLivingBase entity, double x, double y, double z, Callb private void move(EntityLivingBase entity, double x, double y, double z, CallbackInfo ci) { if (!ModConfig.INSTANCE.enabled) return; if (!PolyNametag.INSTANCE.getDrawing() && PolyNametag.INSTANCE.getDrawingWorld()) { - PolyNametag.INSTANCE.getNames().add(new PolyNametag.NameInfo((RendererLivingEntity) (Object) this, entity, x, y, z)); + PolyNametag.INSTANCE.getNametags().add(new PolyNametag.NameInfo((RendererLivingEntity) (Object) this, entity, x, y, z)); ci.cancel(); } } diff --git a/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt b/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt index 74f0276..8a7d3c5 100644 --- a/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt +++ b/src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt @@ -1,19 +1,19 @@ package org.polyfrost.polynametag +import cc.polyfrost.oneconfig.utils.dsl.mc import net.minecraft.client.renderer.GlStateManager -import net.minecraft.client.renderer.RenderHelper +import net.minecraft.client.renderer.OpenGlHelper import net.minecraft.client.renderer.entity.Render import net.minecraft.client.renderer.entity.RendererLivingEntity import net.minecraft.entity.Entity import net.minecraft.entity.EntityLivingBase -import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Loader import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLPostInitializationEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.polyfrost.polynametag.config.ModConfig +import org.polyfrost.polynametag.mixin.MinecraftAccessor import org.polyfrost.polynametag.mixin.RenderAccessor import org.polyfrost.polynametag.render.canDrawIndicator @@ -42,34 +42,44 @@ object PolyNametag { data class LabelInfo(val instance: Render, val entity: Entity, val str: String, val x: Double, val y: Double, val z: Double, val maxDistance: Int) data class NameInfo(val instance: RendererLivingEntity, val entity: EntityLivingBase, val x: Double, val y: Double, val z: Double) - var labels: MutableList = ArrayList() - var names: MutableList = ArrayList() + var nametags = ArrayList() var drawing = false var drawingWorld = false + var drawingInventory = false var drawEssential = false - @SubscribeEvent - fun onRender(event: RenderWorldLastEvent) { + fun onRender() { if (!ModConfig.enabled) return - if (names.isEmpty() && labels.isEmpty()) return + if (nametags.isEmpty()) return GlStateManager.pushMatrix() drawing = true - for (i in names) { - drawEssential = i.entity.canDrawIndicator() - i.instance.renderName(i.entity, i.x, i.y, i.z) - drawEssential = false - } - for (i in labels) { - (i.instance as RenderAccessor).renderNametag(i.entity, i.str, i.x, i.y, i.z, i.maxDistance) + mc.entityRenderer.enableLightmap() + val partialTicks = (mc as MinecraftAccessor).timer.renderPartialTicks + for (name in nametags) { + with(name) { + if (this is LabelInfo) { + val i = if (entity.isBurning) 15728880 else entity.getBrightnessForRender(partialTicks) + val j = i % 65536 + val k = i / 65536 + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j.toFloat() / 1.0f, k.toFloat() / 1.0f) + (instance as RenderAccessor).renderNametag(entity, str, x, y, z, maxDistance) + } else if (this is NameInfo) { + val i = if (entity.isBurning) 15728880 else entity.getBrightnessForRender(partialTicks) + val j = i % 65536 + val k = i / 65536 + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j.toFloat() / 1.0f, k.toFloat() / 1.0f) + drawEssential = entity.canDrawIndicator() + instance.renderName(entity, x, y, z) + drawEssential = false + } + } + } + nametags.clear() drawing = false - names.clear() - labels.clear() + mc.entityRenderer.disableLightmap() GlStateManager.popMatrix() - RenderHelper.disableStandardItemLighting() - GlStateManager.disableRescaleNormal() - GlStateManager.disableBlend() } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/polynametag/config/ModConfig.kt b/src/main/kotlin/org/polyfrost/polynametag/config/ModConfig.kt index 14d655d..4e88192 100644 --- a/src/main/kotlin/org/polyfrost/polynametag/config/ModConfig.kt +++ b/src/main/kotlin/org/polyfrost/polynametag/config/ModConfig.kt @@ -53,8 +53,8 @@ object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"), @Switch(name = "Show own nametag", description = "Whether to show your own nametag") var showOwnNametag = true - @Switch(name = "Offset Essential Indicator", description = "Offset nametag to center if the player has essential indicator drawn") - var essentialOffset = true + @Switch(name = "Show in inventory") + var showInInventory = false @Switch(name = "Background", description = "Whether to render a background behind the nametag") var background = true @@ -62,6 +62,9 @@ object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"), @Color(name = "Background color", description = "The color of the background") var backgroundColor = OneColor(0, 0, 0, 63) + @Switch(name = "Offset Essential Indicator", description = "Offset nametag to center if the player has essential indicator drawn") + var essentialOffset = true + @CustomOption @Transient val nametagPreview = NametagPreview(category = "General") @@ -78,6 +81,7 @@ object ModConfig : Config(Mod("Nametags", ModType.UTIL_QOL, "/polynametag.svg"), !PolyNametag.isPatcher || !PatcherConfig.showOwnNametag } addDependency("cornerRadius", "rounded") + addDependency("showInInventory", "showOwnNametag") hideIf("essentialOffset") { !PolyNametag.isEssential } if (!hasMigratedPatcher) { diff --git a/src/main/resources/mixins.polynametag.json b/src/main/resources/mixins.polynametag.json index 739decf..77a432f 100644 --- a/src/main/resources/mixins.polynametag.json +++ b/src/main/resources/mixins.polynametag.json @@ -10,6 +10,7 @@ "EntityRendererMixin", "FontRendererAccessor", "GuiInventoryMixin", + "MinecraftAccessor", "RenderAccessor", "RendererLivingEntityMixin", "RenderMixin",