diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-06-23 08:19:22 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-23 08:19:22 +1000 |
commit | 649e7ecd4c601d05d51c1decab91675e77e99ef9 (patch) | |
tree | 600a2c6abf4298a602df747591f1064bdbe4029f /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 34e7fe2a360da747750b90c7f11a136e5513d1d8 (diff) | |
parent | 46968a541e2231caadd9a9fc471277054bd012cd (diff) | |
download | skyhanni-649e7ecd4c601d05d51c1decab91675e77e99ef9.tar.gz skyhanni-649e7ecd4c601d05d51c1decab91675e77e99ef9.tar.bz2 skyhanni-649e7ecd4c601d05d51c1decab91675e77e99ef9.zip |
Merge branch 'hannibal002:beta' into frozen_treasure_tracker
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
5 files changed, 30 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt index e16df26e9..a35d0de06 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt @@ -39,4 +39,18 @@ object BlockUtils { return false } + + fun rayTrace(start: LorenzVec, direction: LorenzVec, distance: Double = 50.0): LorenzVec? { + val help = direction.normalize().multiply(distance) + val target = start.add(help) + val result = Minecraft.getMinecraft().theWorld.rayTraceBlocks(start.toVec3(), target.toVec3()) + + return result?.blockPos?.toLorenzVec() + } + + fun getBlockLookingAt(duration: Double = 10.0) = rayTrace( + LocationUtils.playerEyeLocation(), + Minecraft.getMinecraft().thePlayer.lookVec.toLorenzVec(), + duration + ) }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt index efcc8e493..510f631b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import net.minecraft.client.Minecraft +import net.minecraft.entity.Entity object LocationUtils { @@ -12,6 +13,8 @@ object LocationUtils { fun LorenzVec.distanceToPlayer() = distance(playerLocation()) + fun Entity.distanceToPlayer() = getLorenzVec().distance(playerLocation()) + fun playerEyeLocation(): LorenzVec { val player = Minecraft.getMinecraft().thePlayer val vec = player.getLorenzVec() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index bc50ea0e6..c1309d573 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -20,6 +20,7 @@ import net.minecraft.event.ClickEvent import net.minecraft.event.HoverEvent import net.minecraft.util.ChatComponentText import org.lwjgl.input.Keyboard +import java.awt.Color import java.text.DecimalFormat import java.text.NumberFormat import java.text.SimpleDateFormat @@ -381,4 +382,7 @@ object LorenzUtils { @Suppress("UNCHECKED_CAST") this[item] = d as N } + + /** transfer string colors from the config to java.awt.Color */ + fun String.toChromaColor() = Color(SpecialColour.specialToChromaRGB(this), true) }
\ 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 5bce2d762..4b716964f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -64,6 +64,8 @@ data class LorenzVec( fun subtract(other: LorenzVec) = LorenzVec(x - other.x, y - other.y, z - other.z) + fun normalize() = length().let { LorenzVec(x / it, y / it, z / it) } + fun printWithAccuracy(accuracy: Int): String { val x = (round(x * accuracy) / accuracy) val y = (round(y * accuracy) / accuracy) @@ -89,6 +91,8 @@ data class LorenzVec( fun equalsIgnoreY(other: LorenzVec) = x == other.x && z == other.z + fun equals(other: LorenzVec) = x == other.x && y == other.y && z == other.z + fun round(decimals: Int) = LorenzVec(x.round(decimals), y.round(decimals), z.round(decimals)) companion object { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 07e1c9318..dc98f3a0a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -134,15 +134,11 @@ object NEUItems { .withKnownInternalName(internalName) .resolveToItemStack()?.copy() - fun getItemStack(internalName: String): ItemStack { - val stack = getItemStackOrNull(internalName) - if (stack == null) { - val error = "ItemResolutionQuery returns null for internalName '$internalName'" - LorenzUtils.error(error) - throw RuntimeException(error) - } - return stack - } + fun getItemStack(internalName: String): ItemStack = getItemStackOrNull(internalName) + ?: throw IllegalStateException( + "Could not find the Item '$internalName' in NEU Repo", + Error("ItemResolutionQuery returns null for internalName '$internalName'") + ) fun isVanillaItem(item: ItemStack) = manager.auctionManager.isVanillaItem(item.getInternalName()) |