summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-23 23:45:24 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-23 23:45:24 +0200
commitf43bac23acf79325f9f4de060b69c5c0b1d870eb (patch)
treef05971f36500a18091762a4b29f0b0415c25558f /src/main/java/at/hannibal2/skyhanni/utils
parenta21c3298d2ae7790b3d3770ee4a135c1817f3018 (diff)
downloadskyhanni-f43bac23acf79325f9f4de060b69c5c0b1d870eb.tar.gz
skyhanni-f43bac23acf79325f9f4de060b69c5c0b1d870eb.tar.bz2
skyhanni-f43bac23acf79325f9f4de060b69c5c0b1d870eb.zip
Using EntityUtils.getEntities everywhere
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
index fcdfb5cc4..59f3f26b2 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture
import at.hannibal2.skyhanni.utils.LocationUtils.distanceTo
import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth
+import net.minecraft.block.state.IBlockState
import net.minecraft.client.Minecraft
import net.minecraft.client.multiplayer.WorldClient
import net.minecraft.entity.Entity
@@ -131,7 +132,7 @@ object EntityUtils {
getEntitiesNearby(LocationUtils.playerLocation(), radius)
inline fun <reified T : Entity> getEntitiesNearby(location: LorenzVec, radius: Double): List<T> =
- getLoadedEntityList().filterIsInstance<T>().filter { it.distanceTo(location) < radius }
+ getEntities().filterIsInstance<T>().filter { it.distanceTo(location) < radius }
fun EntityLivingBase.isAtFullHealth() = baseMaxHealth == health.toInt()
@@ -155,9 +156,13 @@ object EntityUtils {
fun EntityLivingBase.getArmorInventory(): Array<ItemStack?>? =
if (this is EntityPlayer) inventory.armorInventory else null
- fun EntityEnderman.getBlockInHand() = heldBlockState
+ fun EntityEnderman.getBlockInHand(): IBlockState? = heldBlockState
- inline fun <reified R: Entity> getEntities(): List<R> = getLoadedEntityList().filterIsInstance<R>()
+ inline fun <reified R: Entity> getAllEntities(): List<R> = getEntities().filterIsInstance<R>()
- fun getLoadedEntityList(): List<Entity> = Minecraft.getMinecraft().theWorld.getLoadedEntityList()
+ inline fun <reified R: Entity> getEntitiesOrNull(): List<R>? = getAllEntitiesOrNull()?.filterIsInstance<R>()
+
+ fun getEntities(): List<Entity> = getAllEntitiesOrNull() ?: error("minecraft.world.loadedEntityList is null.")
+
+ fun getAllEntitiesOrNull(): List<Entity>? = Minecraft.getMinecraft()?.theWorld?.loadedEntityList?.toMutableList()
} \ No newline at end of file