@@ -6,8 +6,8 @@ import cc.polyfrost.oneconfig.images.OneImage
66import cc.polyfrost.oneconfig.libs.universal.UResolution
77import cc.polyfrost.oneconfig.utils.dsl.mc
88import net.minecraft.client.gui.Gui
9+ import net.minecraft.client.gui.ScaledResolution
910import net.minecraft.client.renderer.EntityRenderer
10- import net.minecraft.client.renderer.GlStateManager as GL
1111import net.minecraft.client.renderer.texture.DynamicTexture
1212import net.minecraft.client.renderer.texture.TextureUtil
1313import net.minecraft.entity.monster.IMob
@@ -18,12 +18,15 @@ import net.minecraft.entity.passive.EntityWaterMob
1818import net.minecraft.entity.player.EntityPlayer
1919import net.minecraftforge.client.event.RenderGameOverlayEvent
2020import net.minecraftforge.client.event.TextureStitchEvent
21+ import net.minecraftforge.common.MinecraftForge
2122import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
2223import org.lwjgl.opengl.GL11
2324import org.polyfrost.crosshair.config.ModConfig
2425import org.polyfrost.crosshair.mixin.GuiIngameAccessor
26+ import org.polyfrost.crosshair.mixin.MinecraftAccessor
2527import java.awt.image.BufferedImage
2628import kotlin.math.ceil
29+ import net.minecraft.client.renderer.GlStateManager as GL
2730
2831object CrosshairRenderer {
2932 private var drawingImage = BufferedImage (10 , 10 , BufferedImage .TYPE_INT_ARGB )
@@ -65,60 +68,55 @@ object CrosshairRenderer {
6568 vanillaLocation = mc.textureManager.getDynamicTextureLocation(" polycrosshair" , vanilla)
6669 }
6770
68- @SubscribeEvent
69- fun cancel (event : RenderGameOverlayEvent .Pre ) {
70- if (event.type != RenderGameOverlayEvent .ElementType .CROSSHAIRS || ! ModConfig .enabled) return
71- GL .enableAlpha()
72- event.isCanceled = true
73- }
74-
7571 @SubscribeEvent
7672 fun onPackSwitch (event : TextureStitchEvent ) {
7773 updateVanilla()
7874 }
7975
8076 fun drawCrosshair (entityRenderer : EntityRenderer ) {
81- if ( ! ModConfig .enabled) return
82- if ((mc.ingameGUI as ? GuiIngameAccessor )?.shouldShowCrosshair() == false ) return
83-
84- entityRenderer.setupOverlayRendering()
85- GL .pushMatrix()
86- GL .tryBlendFuncSeparate(770 , 771 , 1 , 0 )
87- GL .enableBlend()
88- val renderConfig = ModConfig .renderConfig
89- if (renderConfig.invertColor) {
90- GL .tryBlendFuncSeparate(GL11 .GL_ONE_MINUS_DST_COLOR , GL11 .GL_ONE_MINUS_SRC_COLOR , 1 , 0 )
91- }
92- GL .enableAlpha()
77+ val parent = RenderGameOverlayEvent ((mc as MinecraftAccessor ).timer.renderPartialTicks, ScaledResolution (mc))
78+ MinecraftForge . EVENT_BUS .post( RenderGameOverlayEvent . Pre (parent, RenderGameOverlayEvent . ElementType . CROSSHAIRS ))
79+ if ((mc.ingameGUI as ? GuiIngameAccessor )?.shouldShowCrosshair() == true ) {
80+ entityRenderer.setupOverlayRendering()
81+ GL .pushMatrix()
82+ GL .tryBlendFuncSeparate(770 , 771 , 1 , 0 )
83+ GL .enableBlend()
84+ val renderConfig = ModConfig .renderConfig
85+ if (renderConfig.invertColor) {
86+ GL .tryBlendFuncSeparate(GL11 .GL_ONE_MINUS_DST_COLOR , GL11 .GL_ONE_MINUS_SRC_COLOR , 1 , 0 )
87+ }
88+ GL .enableAlpha()
9389
94- GL11 .glColor4f(1f , 1f , 1f , 1f )
90+ GL11 .glColor4f(1f , 1f , 1f , 1f )
9591
96- (if (ModConfig .mode) textureLocation else vanillaLocation).let { mc.textureManager.bindTexture(it) }
97- val mcScale = UResolution .scaleFactor.toFloat()
98- GL .scale(1 / mcScale, 1 / mcScale, 1f )
99- val crosshair = ModConfig .newCurrentCrosshair
100- GL .translate(crosshair.offsetX.toFloat(), crosshair.offsetY.toFloat(), 0f )
101- GL .translate((UResolution .windowWidth / 2 ).toFloat(), (UResolution .windowHeight / 2 ).toFloat(), 0f )
102- GL .rotate(crosshair.rotation.toFloat(), 0f , 0f , 1f )
103- val scale = crosshair.scale / 100f
104- val textureSize = 16
105- val autoScaledSize = if (ModConfig .canvaSize % 2 == 0 ) 16 else 15
106- val size = ceil((if (ModConfig .mode) autoScaledSize else textureSize) * mcScale * scale).toInt()
107- val translation = ceil((if (ModConfig .mode && crosshair.centered) - autoScaledSize / 2f else - 7f ) * mcScale * scale)
108- GL .translate(translation, translation, 0f )
109- Gui .drawScaledCustomSizeModalRect(0 , 0 , 0f , 0f , textureSize, textureSize, size, size, textureSize.toFloat(), textureSize.toFloat())
110- val c = getColor()
111- if (c.rgb != - 1 ) {
112- if (ModConfig .mode) mc.textureManager.bindTexture(whiteTextureLocation)
113- GL11 .glColor4f(c.red / 255f , c.green / 255f , c.blue / 255f , renderConfig.dynamicOpacity / 100f )
92+ (if (ModConfig .mode) textureLocation else vanillaLocation).let { mc.textureManager.bindTexture(it) }
93+ val mcScale = UResolution .scaleFactor.toFloat()
94+ GL .scale(1 / mcScale, 1 / mcScale, 1f )
95+ val crosshair = ModConfig .newCurrentCrosshair
96+ GL .translate(crosshair.offsetX.toFloat(), crosshair.offsetY.toFloat(), 0f )
97+ GL .translate((UResolution .windowWidth / 2 ).toFloat(), (UResolution .windowHeight / 2 ).toFloat(), 0f )
98+ GL .rotate(crosshair.rotation.toFloat(), 0f , 0f , 1f )
99+ val scale = crosshair.scale / 100f
100+ val textureSize = 16
101+ val autoScaledSize = if (ModConfig .canvaSize % 2 == 0 ) 16 else 15
102+ val size = ceil((if (ModConfig .mode) autoScaledSize else textureSize) * mcScale * scale).toInt()
103+ val translation = ceil((if (ModConfig .mode && crosshair.centered) - autoScaledSize / 2f else - 7f ) * mcScale * scale)
104+ GL .translate(translation, translation, 0f )
114105 Gui .drawScaledCustomSizeModalRect(0 , 0 , 0f , 0f , textureSize, textureSize, size, size, textureSize.toFloat(), textureSize.toFloat())
106+ val c = getColor()
107+ if (c.rgb != - 1 ) {
108+ if (ModConfig .mode) mc.textureManager.bindTexture(whiteTextureLocation)
109+ GL11 .glColor4f(c.red / 255f , c.green / 255f , c.blue / 255f , renderConfig.dynamicOpacity / 100f )
110+ Gui .drawScaledCustomSizeModalRect(0 , 0 , 0f , 0f , textureSize, textureSize, size, size, textureSize.toFloat(), textureSize.toFloat())
111+ }
112+ if (renderConfig.invertColor) {
113+ GL .tryBlendFuncSeparate(GL11 .GL_SRC_ALPHA , GL11 .GL_ONE_MINUS_SRC_ALPHA , 1 , 0 )
114+ }
115+ GL11 .glColor4f(1f , 1f , 1f , 1f )
116+ GL .disableBlend()
117+ GL .popMatrix()
115118 }
116- if (renderConfig.invertColor) {
117- GL .tryBlendFuncSeparate(GL11 .GL_SRC_ALPHA , GL11 .GL_ONE_MINUS_SRC_ALPHA , 1 , 0 )
118- }
119- GL11 .glColor4f(1f , 1f , 1f , 1f )
120- GL .disableBlend()
121- GL .popMatrix()
119+ MinecraftForge .EVENT_BUS .post(RenderGameOverlayEvent .Post (parent, RenderGameOverlayEvent .ElementType .CROSSHAIRS ))
122120 }
123121
124122 val WHITE = OneColor (- 1 )
0 commit comments