Skip to content

Commit

Permalink
Add world access helpers.
Browse files Browse the repository at this point in the history
Currently only has `BlockHitResult.blockStateBy` and `BlockHitResult.blockEntityBy`.
  • Loading branch information
alikindsys committed Jan 2, 2024
1 parent 778ceb1 commit 5df569c
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5df569c

Please sign in to comment.