PhysicalConnectivity/src/main/kotlin/net/shadowfacts/phycon/block/BlockWithEntity.kt

28 lines
808 B
Kotlin
Raw Normal View History

2019-10-27 01:36:31 +00:00
package net.shadowfacts.phycon.block
import net.minecraft.block.Block
import net.minecraft.block.BlockEntityProvider
2021-12-22 23:59:51 +00:00
import net.minecraft.block.BlockState
2019-10-27 01:36:31 +00:00
import net.minecraft.block.entity.BlockEntity
2021-12-22 23:59:51 +00:00
import net.minecraft.block.entity.BlockEntityTicker
import net.minecraft.block.entity.BlockEntityType
2019-10-27 01:36:31 +00:00
import net.minecraft.util.math.BlockPos
import net.minecraft.world.BlockView
2021-12-22 23:59:51 +00:00
import net.minecraft.world.World
2019-10-27 01:36:31 +00:00
/**
* @author shadowfacts
*/
abstract class BlockWithEntity<T: BlockEntity>(settings: Settings): Block(settings), BlockEntityProvider {
2021-12-22 23:59:51 +00:00
abstract override fun createBlockEntity(pos: BlockPos, state: BlockState): T?
2019-10-27 01:36:31 +00:00
fun getBlockEntity(world: BlockView, pos: BlockPos): T? {
val entity = world.getBlockEntity(pos)
return if (entity != null) {
entity as? T
} else {
null
}
}
2021-12-22 23:59:51 +00:00
}