From 5df569cee119dadca7b3dcad0e89f0a27f8cb919 Mon Sep 17 00:00:00 2001 From: Alice Isabel Date: Mon, 1 Jan 2024 23:43:39 -0300 Subject: [PATCH] Add world access helpers. Currently only has `BlockHitResult.blockStateBy` and `BlockHitResult.blockEntityBy`. --- .../minecity/fabric/helpers/WorldAccess.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 platform/fabric/src/main/kotlin/br/com/gamemods/minecity/fabric/helpers/WorldAccess.kt diff --git a/platform/fabric/src/main/kotlin/br/com/gamemods/minecity/fabric/helpers/WorldAccess.kt b/platform/fabric/src/main/kotlin/br/com/gamemods/minecity/fabric/helpers/WorldAccess.kt new file mode 100644 index 0000000..aa9f2d3 --- /dev/null +++ b/platform/fabric/src/main/kotlin/br/com/gamemods/minecity/fabric/helpers/WorldAccess.kt @@ -0,0 +1,31 @@ +package br.com.gamemods.minecity.fabric.helpers + +import net.minecraft.block.BlockState +import net.minecraft.block.entity.BlockEntity +import net.minecraft.util.hit.BlockHitResult +import net.minecraft.world.World + +/** + * Gets a [BlockState] from a [BlockHitResult] by accessing a [World] + * + * You *should* have a reference to a world on which this [BlockHitResult] was queried. + * + * **Trivial**: This is a mere convenience extension function. + * @param world The world being queried. + * @author alikindsys + */ +fun BlockHitResult.blockStateBy(world: World) : BlockState { + return world.getBlockState(this.blockPos) +} + +/** + * Gets a [BlockEntity] from a [BlockHitResult] by accessing a [World] + * + * You *should* have a reference to a world on which this [BlockHitResult] was queried. + * + * **Trivial**: This is a mere convenience extension function. + * @param world The world being queried. + * @author alikindsys + */fun BlockHitResult.blockEntityBy(world: World) : BlockEntity? { + return world.getBlockEntity(this.blockPos) +} \ No newline at end of file