diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-08 00:06:16 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-08 00:06:16 +0100 |
commit | f1930397ccfb9d953bbd93ace46508c487dd6579 (patch) | |
tree | c7fd86a725443d7ea5ed898414ff391a1d66d8fa /src/main/java/at/hannibal2 | |
parent | 973c70eb98bfb811ebce565b71d388eb948aa327 (diff) | |
download | skyhanni-f1930397ccfb9d953bbd93ace46508c487dd6579.tar.gz skyhanni-f1930397ccfb9d953bbd93ace46508c487dd6579.tar.bz2 skyhanni-f1930397ccfb9d953bbd93ace46508c487dd6579.zip |
Added option to change the Blaze Slayer Dagger GUI positons.
Diffstat (limited to 'src/main/java/at/hannibal2')
4 files changed, 59 insertions, 95 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java index 329bcd028..d8b2a7a99 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/Position.java @@ -31,6 +31,8 @@ public class Position { private int y; @Expose private float scale = 1F; + @Expose + private boolean center = false; @Expose private boolean centerX; @@ -52,6 +54,15 @@ public class Position { this.scale = scale; } + public Position(int x, int y, float scale, boolean center) { + this.x = x; + this.y = y; + this.centerX = false; + this.centerY = true; + this.scale = scale; + this.center = center; + } + public Position(int x, int y, boolean centerX, boolean centerY) { this.x = x; this.y = y; @@ -65,6 +76,7 @@ public class Position { this.centerX = other.centerX; this.centerY = other.centerY; this.scale = other.getScale(); + this.center = other.isCenter(); } public float getEffectiveScale() { @@ -76,6 +88,10 @@ public class Position { return scale; } + public boolean isCenter() { + return center; + } + public void setScale(float newScale) { scale = Math.max(Math.min(10F, newScale), 0.1f); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java index 6ca5ec984..1c0003eab 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java @@ -121,6 +121,12 @@ public class SlayerConfig { @ConfigEditorBoolean @FeatureToggle public boolean hideDaggerWarning = false; + + @Expose + public Position positionTop = new Position(-475, 173, 4.4f, true); + + @Expose + public Position positionBottom = new Position(-475, 230, 3.2f, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt index ce892f31f..0e9b9f8ae 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.slayer.blaze import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor import at.hannibal2.skyhanni.data.ClickType import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.GuiRenderEvent @@ -12,23 +13,19 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision +import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.getLorenzVec -import io.github.moulberry.moulconfig.internal.TextRenderUtils import net.minecraft.client.Minecraft -import net.minecraft.client.gui.ScaledResolution -import net.minecraft.client.renderer.GlStateManager import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BlazeSlayerDaggerHelper { + private val config get() = SkyHanniMod.feature.slayer.blazes.hellion private var clientSideClicked = false - private var textTopLeft = "" - private var textTopRight = "" - private var textBottomLeft = "" - private var textBottomRight = "" + private var textTop = "" + private var textBottom = "" private var lastDaggerCheck = 0L private var lastNearestCheck = 0L @@ -58,10 +55,8 @@ class BlazeSlayerDaggerHelper { return } - textTopLeft = "" - textTopRight = "" - textBottomLeft = "" - textBottomRight = "" + textTop = "" + textBottom = "" } private fun setDaggerText(holding: Dagger) { @@ -71,10 +66,8 @@ class BlazeSlayerDaggerHelper { val first = Dagger.entries[SkyHanniMod.feature.slayer.blazes.hellion.firstDagger] val second = first.other() - textTopLeft = format(holding, true, first) - textTopRight = format(holding, true, second) - textBottomLeft = format(holding, false, first) - textBottomRight = format(holding, false, second) + textTop = format(holding, true, first) + " " + format(holding, true, second) + textBottom = format(holding, false, first) + " " + format(holding, false, second) } private fun findNearest(): HellionShield? { @@ -194,7 +187,7 @@ class BlazeSlayerDaggerHelper { } private fun isEnabled(): Boolean { - return LorenzUtils.inSkyBlock && SkyHanniMod.feature.slayer.blazes.hellion.daggers + return LorenzUtils.inSkyBlock && config.daggers } @SubscribeEvent @@ -242,75 +235,13 @@ class BlazeSlayerDaggerHelper { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - if (textTopLeft.isEmpty()) return - - if (Minecraft.getMinecraft().currentScreen != null) return - - val scaledResolution = ScaledResolution(Minecraft.getMinecraft()) - val width = scaledResolution.scaledWidth - val height = scaledResolution.scaledHeight - - val sizeFactor = (width.toFloat() / 960f).roundToPrecision(3) - - GlStateManager.enableBlend() - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) - val renderer = Minecraft.getMinecraft().fontRendererObj - - GlStateManager.pushMatrix() - GlStateManager.translate(((width / 2) / 1.18).toFloat(), (height / 3.8).toFloat(), 0.0f) - GlStateManager.scale(4.0f, 4.0f, 4.0f) - TextRenderUtils.drawStringCenteredScaledMaxWidth( - textTopLeft, - renderer, - 0f, - 0f, - false, - (60f * sizeFactor).toInt(), - 0 - ) - GlStateManager.popMatrix() - - GlStateManager.pushMatrix() - GlStateManager.translate(((width / 2) * 1.18).toFloat(), (height / 3.8).toFloat(), 0.0f) - GlStateManager.scale(4.0f, 4.0f, 4.0f) - TextRenderUtils.drawStringCenteredScaledMaxWidth( - textTopRight, - renderer, - 0f, - 0f, - false, - (60f * sizeFactor).toInt(), - 0 - ) - GlStateManager.popMatrix() - - GlStateManager.pushMatrix() - GlStateManager.translate(((width / 2) / 1.18).toFloat(), (height / 3.0).toFloat(), 0.0f) - GlStateManager.scale(4.0f, 4.0f, 4.0f) - TextRenderUtils.drawStringCenteredScaledMaxWidth( - textBottomLeft, - renderer, - 0f, - 0f, - false, - (20f * sizeFactor).toInt(), - 0 - ) - GlStateManager.popMatrix() - - GlStateManager.pushMatrix() - GlStateManager.translate(((width / 2) * 1.18).toFloat(), (height / 3.0).toFloat(), 0.0f) - GlStateManager.scale(4.0f, 4.0f, 4.0f) - TextRenderUtils.drawStringCenteredScaledMaxWidth( - textBottomRight, - renderer, - 0f, - 0f, - false, - (20f * sizeFactor).toInt(), - 0 - ) - GlStateManager.popMatrix() + + if (textTop == "") return + val currentScreen = Minecraft.getMinecraft().currentScreen + if (currentScreen != null && currentScreen !is GuiPositionEditor) return + + config.positionTop.renderString(textTop, posLabel = "Blaze Slayer Dagger Top") + config.positionBottom.renderString(textBottom, posLabel = "Blaze Slayer Dagger Bottom") } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 4a5754b6c..7e10b0351 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -303,7 +303,6 @@ object RenderUtils { val z = pos.z - player.lastTickPosZ + (pos.z - player.posZ - (pos.z - player.lastTickPosZ)) * partialTicks - //7 – 25 val translate = LorenzVec(x, y, z) @@ -353,7 +352,6 @@ object RenderUtils { return lastValue + (currentValue - lastValue) * multiplier } - fun Position.transform(): Pair<Int, Int> { GlStateManager.translate(getAbsX().toFloat(), getAbsY().toFloat(), 0F) GlStateManager.scale(effectiveScale, effectiveScale, 1F) @@ -365,11 +363,11 @@ object RenderUtils { fun Position.renderString(string: String?, offsetX: Int = 0, offsetY: Int = 0, posLabel: String) { if (string == null) return if (string == "") return - val x = renderString0(string, offsetX, offsetY) + val x = renderString0(string, offsetX, offsetY, isCenter) GuiEditManager.add(this, posLabel, x, 10) } - private fun Position.renderString0(string: String?, offsetX: Int = 0, offsetY: Int = 0): Int { + private fun Position.renderString0(string: String?, offsetX: Int = 0, offsetY: Int = 0, centered: Boolean): Int { val display = "§f$string" GlStateManager.pushMatrix() transform() @@ -380,7 +378,16 @@ object RenderUtils { val y = offsetY GlStateManager.translate(x + 1.0, y + 1.0, 0.0) - renderer.drawStringWithShadow(display, 0f, 0f, 0) + + if (centered) { + val strLen: Int = renderer.getStringWidth(string) + val x2 = x - strLen / 2f + GL11.glTranslatef(x2, 0f, 0f) + renderer.drawStringWithShadow(display, 0f, 0f, 0) + GL11.glTranslatef(-x2, 0f, 0f) + } else { + renderer.drawStringWithShadow(display, 0f, 0f, 0) + } GlStateManager.popMatrix() @@ -394,7 +401,7 @@ object RenderUtils { var offsetY = 0 var longestX = 0 for (s in list) { - val x = renderString0(s, offsetY = offsetY) + val x = renderString0(s, offsetY = offsetY, centered = false) if (x > longestX) { longestX = x } @@ -756,7 +763,6 @@ object RenderUtils { return LorenzVec(x, y, z) } - fun drawFilledBoundingBox(aabb: AxisAlignedBB, c: Color, alphaMultiplier: Float = 1f) { GlStateManager.enableBlend() GlStateManager.disableLighting() @@ -927,7 +933,12 @@ object RenderUtils { GlStateManager.disableBlend() } - fun LorenzRenderWorldEvent.outlineTopFace(boundingBox: AxisAlignedBB, lineWidth: Int, colour: Color, depth: Boolean) { + fun LorenzRenderWorldEvent.outlineTopFace( + boundingBox: AxisAlignedBB, + lineWidth: Int, + colour: Color, + depth: Boolean + ) { val cornerOne = LorenzVec(boundingBox.minX, boundingBox.maxY, boundingBox.minZ) val cornerTwo = LorenzVec(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ) val cornerThree = LorenzVec(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ) @@ -1021,4 +1032,4 @@ object RenderUtils { GlStateManager.enableLighting() GlStateManager.enableDepth() } -}
\ No newline at end of file +} |