Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed May 9, 2024
1 parent dc8741d commit 36c4a5d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.polyfrost.polynametag.mixin;

import net.minecraft.client.renderer.EntityRenderer;
import org.polyfrost.polynametag.PolyNametag;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin {

@Inject(method = "renderWorld", at = @At("HEAD"))
private void start(float partialTicks, long finishTimeNano, CallbackInfo ci) {
PolyNametag.INSTANCE.setDrawingWorld(false);
}

@Inject(method = "renderWorld", at = @At("TAIL"))
private void end(float partialTicks, long finishTimeNano, CallbackInfo ci) {
PolyNametag.INSTANCE.setDrawingWorld(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void drawBG(Entity entityIn, String str, double x, double y, double z, i
@Inject(method = "renderLivingLabel", at = @At("HEAD"), cancellable = true)
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.getDrawingInGUI()) {
if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingWorld()) {
PolyNametag.INSTANCE.getLabels().add(new PolyNametag.LabelInfo((Render<Entity>) (Object) this, entityIn, str, x, y, z, maxDistance));
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void drawBG(EntityLivingBase entity, double x, double y, double z, Callb
@Inject(method = "renderName(Lnet/minecraft/entity/EntityLivingBase;DDD)V", at = @At("HEAD"), cancellable = true)
private void move(EntityLivingBase entity, double x, double y, double z, CallbackInfo ci) {
if (!ModConfig.INSTANCE.enabled) return;
if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingInGUI()) {
if (!PolyNametag.INSTANCE.getDrawing() && !PolyNametag.INSTANCE.getDrawingWorld()) {
PolyNametag.INSTANCE.getNames().add(new PolyNametag.NameInfo((RendererLivingEntity<EntityLivingBase>) (Object) this, entity, x, y, z));
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class OnlineIndicatorMixin {
@Dynamic("Essential")
@Inject(method = "drawNametagIndicator", at = @At("HEAD"), cancellable = true)
private static void skip(UMatrixStack matrixStack, Entity entity, String str, int light, CallbackInfo ci) {
if (ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.enabled) return;
if (!PolyNametag.INSTANCE.getDrawingEssential()) ci.cancel();
}

Expand All @@ -51,7 +51,7 @@ private static void skip(UMatrixStack matrixStack, Entity entity, String str, in
index = 3
)
private static double polyNametag$modifyBackgroundZ(double z) {
if (ModConfig.INSTANCE.enabled) return z;
if (!ModConfig.INSTANCE.enabled) return z;
if (!NametagRenderingKt.shouldDrawBackground()) return z;
return z + 0.01;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.awt.*;
Expand All @@ -30,10 +27,16 @@ public abstract class AboveHeadRenderMixin {
@Dynamic("LevelHead")
@Inject(method = "renderName", at = @At("HEAD"))
private void move(LevelheadTag tag, EntityPlayer entityIn, double x, double y, double z, CallbackInfo ci) {
if (ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.enabled) return;
PolyNametag.INSTANCE.setDrawEssential(false);
}

@Dynamic("LevelHead")
@ModifyVariable(method = "renderName", at = @At("STORE"), name = "xMultiplier")
private int stupid(int value) {
return PolyNametag.INSTANCE.isPatcher() ? 1 : value;
}

@Dynamic("LevelHead")
@Redirect(
method = "render(Lnet/minecraftforge/client/event/RenderLivingEvent$Specials$Post;)V",
Expand Down Expand Up @@ -64,7 +67,7 @@ private void move(LevelheadTag tag, EntityPlayer entityIn, double x, double y, d
@Dynamic("LevelHead")
@Inject(method = "renderName", at = @At(value = "INVOKE", target = "Lgg/essential/universal/UGraphics;drawDirect()V", shift = At.Shift.AFTER))
private void drawBG(LevelheadTag tag, EntityPlayer entityIn, double x, double y, double z, CallbackInfo ci) {
if (ModConfig.INSTANCE.enabled) return;
if (!ModConfig.INSTANCE.enabled) return;
int stringWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(tag.getString()) / 2;
float[] color = NametagRenderingKt.getBackBackgroundGLColorOrEmpty();
NametagRenderingKt.drawFrontBackground(-stringWidth - 2, stringWidth + 1, new Color(color[0], color[1], color[2], color[3]), entityIn);
Expand Down
9 changes: 1 addition & 8 deletions src/main/kotlin/org/polyfrost/polynametag/PolyNametag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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.RenderWorldEvent
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Loader
Expand Down Expand Up @@ -47,17 +46,11 @@ object PolyNametag {
var names: MutableList<NameInfo> = ArrayList()

var drawing = false
var drawingInGUI = false
var drawingWorld = false
var drawEssential = false

@SubscribeEvent
fun startWorld(event: RenderWorldEvent.Pre) {
drawingInGUI = false
}

@SubscribeEvent
fun onRender(event: RenderWorldLastEvent) {
drawingInGUI = true
if (!ModConfig.enabled) return
if (names.isEmpty() && labels.isEmpty()) return
GlStateManager.pushMatrix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ class NametagPreview(
renderManager.playerViewY = 180f
renderManager.isRenderShadow = false
val renderer = renderManager.getEntityRenderObject<EntityLivingBase>(entity) as RendererLivingEntity
PolyNametag.drawingInGUI = true
drawing = true
renderer.renderName(entity, 0.0, 0.0, 0.0)
drawing = false
PolyNametag.drawingInGUI = false
entity.riddenByEntity = entity // cancel original nametag
renderManager.doRenderEntity(entity, 0.0, 0.0, 0.0, 0f, 1f, true)
renderManager.isRenderShadow = true
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 @@ -7,6 +7,7 @@
"maxShiftBy": 5
},
"client": [
"EntityRendererMixin",
"FontRendererAccessor",
"GuiInventoryMixin",
"RenderAccessor",
Expand Down

0 comments on commit 36c4a5d

Please sign in to comment.