22 lines
617 B
Kotlin
22 lines
617 B
Kotlin
|
package net.shadowfacts.phycon.block
|
||
|
|
||
|
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
|
||
|
|
||
|
/**
|
||
|
* @author shadowfacts
|
||
|
*/
|
||
|
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 if (entity != null) {
|
||
|
entity as? T
|
||
|
} else {
|
||
|
null
|
||
|
}
|
||
|
}
|
||
|
}
|