summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-07-05 12:29:49 +0200
committerGitHub <noreply@github.com>2023-07-05 12:29:49 +0200
commitc4092f9f36ef2d6a1914ee5ef606522d35e14cdc (patch)
tree5f606fa38d17f3e2471e75060c06acb9f65a2c81 /src/main/java/at/hannibal2/skyhanni/utils
parent5bedd8978dc05f60ef752a95a2062e99be41281c (diff)
downloadskyhanni-c4092f9f36ef2d6a1914ee5ef606522d35e14cdc.tar.gz
skyhanni-c4092f9f36ef2d6a1914ee5ef606522d35e14cdc.tar.bz2
skyhanni-c4092f9f36ef2d6a1914ee5ef606522d35e14cdc.zip
mirror verse jump and run (#265)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Roman / Linnea Gräf <nea@nea.moe>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt37
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt60
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ParkourJson.java21
4 files changed, 98 insertions, 33 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 77a47b895..129cec02e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -32,36 +32,25 @@ import kotlin.reflect.KProperty0
object LorenzUtils {
- val onHypixel: Boolean
- get() = (HypixelData.hypixelLive || HypixelData.hypixelAlpha) && Minecraft.getMinecraft().thePlayer != null
+ val onHypixel get() = (HypixelData.hypixelLive || HypixelData.hypixelAlpha) && Minecraft.getMinecraft().thePlayer != null
- val isOnAlphaServer: Boolean
- get() = onHypixel && HypixelData.hypixelAlpha
+ val isOnAlphaServer get() = onHypixel && HypixelData.hypixelAlpha
- val inSkyBlock: Boolean
- get() = onHypixel && HypixelData.skyBlock
+ val inSkyBlock get() = onHypixel && HypixelData.skyBlock
- val inDungeons: Boolean
- get() = inSkyBlock && DungeonData.inDungeon()
+ val inDungeons get() = inSkyBlock && DungeonData.inDungeon()
- val skyBlockIsland: IslandType
- get() = HypixelData.skyBlockIsland
+ val skyBlockIsland get() = HypixelData.skyBlockIsland
- //TODO add cache
- val skyBlockArea: String
- get() = HypixelData.readSkyBlockArea()
+ val skyBlockArea get() = if (inSkyBlock) HypixelData.skyBlockArea else "?"
- val inKuudraFight: Boolean
- get() = skyBlockIsland == IslandType.KUUDRA_ARENA
+ val inKuudraFight get() = skyBlockIsland == IslandType.KUUDRA_ARENA
- val noTradeMode: Boolean
- get() = HypixelData.noTrade
+ val noTradeMode get() = HypixelData.noTrade
- val isBingoProfile: Boolean
- get() = inSkyBlock && (HypixelData.bingo || TestBingo.testBingo)
+ val isBingoProfile get() = inSkyBlock && (HypixelData.bingo || TestBingo.testBingo)
- val lastWorldSwitch: Long
- get() = HypixelData.joinedWorld
+ val lastWorldSwitch get() = HypixelData.joinedWorld
const val DEBUG_PREFIX = "[SkyHanni Debug] §7"
private val log = LorenzLogger("chat/mod_sent")
@@ -389,4 +378,10 @@ object LorenzUtils {
/** transfer string colors from the config to java.awt.Color */
fun String.toChromaColor() = Color(SpecialColour.specialToChromaRGB(this), true)
+
+ fun <E> List<E>.getOrNull(index: Int): E? {
+ return if (index in indices) {
+ get(index)
+ } else null
+ }
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
index b0b363b05..1d1909875 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
@@ -3,10 +3,15 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import net.minecraft.entity.Entity
import net.minecraft.network.play.server.S2APacketParticles
+import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraft.util.Rotations
import net.minecraft.util.Vec3
-import kotlin.math.*
+import kotlin.math.cos
+import kotlin.math.pow
+import kotlin.math.round
+import kotlin.math.sin
+import kotlin.math.sqrt
data class LorenzVec(
val x: Double,
@@ -102,6 +107,12 @@ data class LorenzVec(
return LorenzVec(x, y, z)
}
+ fun boundingToOffset(offX: Int, offY: Int, offZ: Int) = AxisAlignedBB(x, y, z, x + offX, y + offY, z + offZ)
+
+ fun scale(scalar: Double): LorenzVec {
+ return LorenzVec(scalar * x, scalar * y, scalar * z)
+ }
+
companion object {
fun getFromYawPitch(yaw: Double, pitch: Double): LorenzVec {
val yaw: Double = (yaw + 90) * Math.PI / 180
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 69df66afa..c4a4239c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -23,6 +23,8 @@ import java.awt.Color
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
+import kotlin.time.Duration
+import kotlin.time.DurationUnit
object RenderUtils {
@@ -551,7 +553,8 @@ object RenderUtils {
GlStateManager.translate(getAbsX().toFloat(), (getAbsY() + offsetY).toFloat(), 0F)
var offsetX = 0
for (any in line) {
- val renderable = Renderable.fromAny(any, itemScale = itemScale) ?: throw RuntimeException("Unknown render object: $any")
+ val renderable =
+ Renderable.fromAny(any, itemScale = itemScale) ?: throw RuntimeException("Unknown render object: $any")
renderable.render(getAbsX() + offsetX, getAbsY() + offsetY)
offsetX += renderable.width
@@ -783,43 +786,62 @@ object RenderUtils {
}
}
- fun RenderWorldLastEvent.draw3DLine(p1: LorenzVec, p2: LorenzVec, color: Color, lineWidth: Int, depth: Boolean) {
- GlStateManager.disableDepth()
- GlStateManager.disableCull()
+ fun RenderWorldLastEvent.drawFilledBoundingBox(
+ aabb: AxisAlignedBB,
+ c: Color,
+ alphaMultiplier: Float = 1f,
+ /**
+ * If set to `true`, renders the box relative to the camera instead of relative to the world.
+ * If set to `false`, will be relativized to [RenderUtils.getViewerPos].
+ */
+ renderRelativeToCamera: Boolean = false,
+ drawVerticalBarriers: Boolean = true
+ ) {
+ drawFilledBoundingBox(aabb, c, alphaMultiplier, renderRelativeToCamera, drawVerticalBarriers, partialTicks)
+ }
+ fun RenderWorldLastEvent.draw3DLine(
+ p1: LorenzVec, p2: LorenzVec, color: Color, lineWidth: Int, depth: Boolean, targetColor: Color? = null
+ ) {
val render = Minecraft.getMinecraft().renderViewEntity
val worldRenderer = Tessellator.getInstance().worldRenderer
val realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
GlStateManager.pushMatrix()
+ GlStateManager.disableDepth()
+ GlStateManager.disableCull()
+ GlStateManager.disableLighting()
GlStateManager.translate(-realX, -realY, -realZ)
GlStateManager.disableTexture2D()
GlStateManager.enableBlend()
GlStateManager.disableAlpha()
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0)
GL11.glLineWidth(lineWidth.toFloat())
if (!depth) {
GL11.glDisable(GL11.GL_DEPTH_TEST)
GlStateManager.depthMask(false)
}
- GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f)
- worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION)
- worldRenderer.pos(p1.x, p1.y, p1.z).endVertex()
- worldRenderer.pos(p2.x, p2.y, p2.z).endVertex()
+ GlStateManager.color(1f, 1f, 1f, 1f)
+ if (targetColor != null)
+ GlStateManager.shadeModel(GL11.GL_SMOOTH)
+ worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR)
+ worldRenderer.pos(p1.x, p1.y, p1.z).color(color.red, color.green, color.blue, color.alpha).endVertex()
+ val secondColor = targetColor ?: color
+ worldRenderer.pos(p2.x, p2.y, p2.z)
+ .color(secondColor.red, secondColor.green, secondColor.blue, secondColor.alpha).endVertex()
Tessellator.getInstance().draw()
- GlStateManager.translate(realX, realY, realZ)
if (!depth) {
GL11.glEnable(GL11.GL_DEPTH_TEST)
GlStateManager.depthMask(true)
}
+ GlStateManager.shadeModel(GL11.GL_FLAT)
GlStateManager.disableBlend()
GlStateManager.enableAlpha()
GlStateManager.enableTexture2D()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
GlStateManager.disableLighting()
- GlStateManager.enableDepth()
}
fun RenderWorldLastEvent.exactLocation(entity: Entity): LorenzVec {
@@ -832,4 +854,20 @@ object RenderUtils {
val z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks
return LorenzVec(x, y, z)
}
+
+ fun chromaColor(
+ timeTillRepeat: Duration,
+ offset: Float = 0f,
+ saturation: Float = 1F,
+ brightness: Float = 0.8F,
+ timeOverride: Long = System.currentTimeMillis()
+ ): Color {
+ return Color(
+ Color.HSBtoRGB(
+ ((offset + timeOverride / timeTillRepeat.toDouble(DurationUnit.MILLISECONDS)) % 1).toFloat(),
+ saturation,
+ brightness
+ )
+ )
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ParkourJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ParkourJson.java
new file mode 100644
index 000000000..71206d18c
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/ParkourJson.java
@@ -0,0 +1,21 @@
+package at.hannibal2.skyhanni.utils.jsonobjects;
+
+import at.hannibal2.skyhanni.utils.LorenzVec;
+import com.google.gson.annotations.Expose;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ParkourJson {
+ @Expose
+ public List<LorenzVec> locations;
+ @Expose
+ public List<ShortCut> shortCuts = new ArrayList<>();
+
+ public static class ShortCut {
+ @Expose
+ public int from;
+ @Expose
+ public int to;
+ }
+}