diff --git a/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java b/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java index 7e58384..da1219e 100644 --- a/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java +++ b/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java @@ -1,10 +1,18 @@ package org.polyfrost.crosshair.mixin; -import net.minecraft.client.gui.Gui; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.GuiIngameForge; +import org.lwjgl.opengl.GL11; import org.polyfrost.crosshair.CrosshairHUD; +import org.polyfrost.oneconfig.api.platform.v1.Platform; +import org.polyfrost.polyui.color.PolyColor; +import org.polyfrost.polyui.component.Drawable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -12,17 +20,40 @@ @Mixin(GuiIngameForge.class) public abstract class GuiIngameMixin { + @Shadow + private ScaledResolution res; + @Redirect(method = "renderCrosshairs", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;bind(Lnet/minecraft/util/ResourceLocation;)V"), remap = false) private void bindTexture(GuiIngameForge it, ResourceLocation res) { if (CrosshairHUD.INSTANCE.getUseVanilla()) bind(res); else GlStateManager.bindTexture(CrosshairHUD.INSTANCE.getId()); } + @WrapWithCondition(method = "renderCrosshairs", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;tryBlendFuncSeparate(IIII)V", ordinal = 0)) + private boolean blendFunc(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) { + return CrosshairHUD.INSTANCE.getUseVanillaBlending(); + } + @Redirect(method = "renderCrosshairs", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;drawTexturedModalRect(IIIIII)V")) - private void drawCrosshair(GuiIngameForge it, int x, int y, int u, int v, int w, int h) { - final float tex = CrosshairHUD.INSTANCE.getUseVanilla() ? 256f : CrosshairHUD.INSTANCE.getWidth(); - // #optimize-fold-zeroes - Gui.drawModalRectWithCustomSizedTexture(x, y, 0f, 0f, w, h, tex, tex); + private void drawCrosshair(GuiIngameForge it, int xIn, int yIn, int u, int v, int wIn, int hIn) { + Drawable wrapper = CrosshairHUD.INSTANCE.get(); + float scale = Platform.screen().pixelRatio() / res.getScaleFactor(); + double size = 15f * wrapper.getScaleX(); + double x = wrapper.getX() * scale; + double y = wrapper.getY() * scale; + double tex = CrosshairHUD.INSTANCE.getUseVanilla() ? 15d / 256d : 1d; + + PolyColor color = CrosshairHUD.INSTANCE.getColor(); + GL11.glColor4ub((byte) color.red(), (byte) color.green(), (byte) color.blue(), (byte) color.alpha()); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + worldRenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldRenderer.pos(x, y + size, 10d).tex(0d, tex).endVertex(); + worldRenderer.pos(x + size, y + size, 10d).tex(tex, tex).endVertex(); + worldRenderer.pos(x + size, y, 10d).tex(tex, 0d).endVertex(); + worldRenderer.pos(x, y, 10d).tex(0d, 0d).endVertex(); + tessellator.draw(); + GL11.glColor4f(1f, 1f, 1f, 1f); } @Shadow(remap = false) diff --git a/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt b/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt index c69660c..37796ab 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/CrosshairHUD.kt @@ -2,9 +2,11 @@ package org.polyfrost.crosshair import net.minecraft.client.renderer.texture.TextureUtil import org.polyfrost.oneconfig.api.config.v1.annotations.Button +import org.polyfrost.oneconfig.api.config.v1.annotations.Color import org.polyfrost.oneconfig.api.config.v1.annotations.Include import org.polyfrost.oneconfig.api.config.v1.annotations.Switch import org.polyfrost.oneconfig.api.hud.v1.LegacyHud +import org.polyfrost.polyui.color.rgba import org.polyfrost.polyui.unit.Vec2 import org.polyfrost.polyui.utils.getResourceStream import org.polyfrost.universal.UMatrixStack @@ -19,6 +21,9 @@ object CrosshairHUD : LegacyHud() { @Switch(title = "Use Vanilla") var useVanilla = false + @Switch(title = "Use Vanilla Blending") + var useVanillaBlending = true + @Switch(title = "Show in F3") var showInDebug = false @@ -28,6 +33,9 @@ object CrosshairHUD : LegacyHud() { @Switch(title = "Show in 3rd Person") var showInThirdPerson = true + @Color(title = "Color") + var color = rgba(255, 255, 255) + @Include var currentCrosshair: String? = null @@ -35,7 +43,8 @@ object CrosshairHUD : LegacyHud() { fun openEditor() { PolyCrosshairUI.open() } val id = GL.generateTexture() - private var texSize = 15f + var texSize = 15f + private set override var width: Float get() = texSize