Skip to content

Commit

Permalink
fixed nametag lighting & double essential
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jun 26, 2024
1 parent 233a869 commit 437bb67
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>) (Object) this, entityIn, str, x, y, z, maxDistance));
PolyNametag.INSTANCE.getNametags().add(new PolyNametag.LabelInfo((Render<Entity>) (Object) this, entityIn, str, x, y, z, maxDistance));
ci.cancel();
}
}
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<EntityLivingBase>) (Object) this, entity, x, y, z));
PolyNametag.INSTANCE.getNametags().add(new PolyNametag.NameInfo((RendererLivingEntity<EntityLivingBase>) (Object) this, entity, x, y, z));
ci.cancel();
}
}
Expand Down
50 changes: 30 additions & 20 deletions src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -42,34 +42,44 @@ object PolyNametag {
data class LabelInfo(val instance: Render<Entity>, val entity: Entity, val str: String, val x: Double, val y: Double, val z: Double, val maxDistance: Int)
data class NameInfo(val instance: RendererLivingEntity<EntityLivingBase>, val entity: EntityLivingBase, val x: Double, val y: Double, val z: Double)

var labels: MutableList<LabelInfo> = ArrayList()
var names: MutableList<NameInfo> = ArrayList()
var nametags = ArrayList<Any>()

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<Entity>).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<Entity>).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()
}

}
8 changes: 6 additions & 2 deletions src/main/kotlin/org/polyfrost/polynametag/config/ModConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ 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

@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")
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.polynametag.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"EntityRendererMixin",
"FontRendererAccessor",
"GuiInventoryMixin",
"MinecraftAccessor",
"RenderAccessor",
"RendererLivingEntityMixin",
"RenderMixin",
Expand Down

0 comments on commit 437bb67

Please sign in to comment.