ExtraHoppers/src/main/kotlin/net/shadowfacts/extrahoppers/block/base/BlockWithEntity.kt

18 lines
572 B
Kotlin

package net.shadowfacts.extrahoppers.block.base
import net.minecraft.block.Block
import net.minecraft.block.BlockEntityProvider
import net.minecraft.block.entity.BlockEntity
import net.minecraft.util.math.BlockPos
import net.minecraft.world.BlockView
abstract class BlockWithEntity<T: BlockEntity>(settings: Settings): Block(settings), BlockEntityProvider {
abstract override fun createBlockEntity(world: BlockView): T
fun getBlockEntity(world: BlockView, pos: BlockPos): T? {
val entity = world.getBlockEntity(pos)
return entity as? T
}
}