PhysicalConnectivity/src/main/kotlin/net/shadowfacts/phycon/network/block/netswitch/SwitchBlock.kt

43 lines
1.4 KiB
Kotlin
Raw Normal View History

2019-10-27 03:13:26 +00:00
package net.shadowfacts.phycon.network.block.netswitch
import alexiil.mc.lib.attributes.AttributeList
import alexiil.mc.lib.attributes.AttributeProvider
import net.minecraft.block.BlockState
import net.minecraft.block.Material
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
2019-10-27 03:13:26 +00:00
import net.minecraft.world.BlockView
import net.minecraft.world.World
import net.shadowfacts.phycon.PhysicalConnectivity
2021-02-13 23:24:36 +00:00
import net.shadowfacts.phycon.api.Interface
import net.shadowfacts.phycon.api.NetworkComponentBlock
2019-10-27 03:13:26 +00:00
import net.shadowfacts.phycon.block.BlockWithEntity
import java.util.*
2019-10-27 03:13:26 +00:00
/**
* @author shadowfacts
*/
2021-02-13 23:24:36 +00:00
class SwitchBlock: BlockWithEntity<SwitchBlockEntity>(Settings.of(Material.METAL)),
NetworkComponentBlock,
AttributeProvider {
2019-10-27 03:13:26 +00:00
companion object {
val ID = Identifier(PhysicalConnectivity.MODID, "switch")
}
override fun getNetworkConnectedSides(state: BlockState, world: World, pos: BlockPos): Collection<Direction> {
return EnumSet.allOf(Direction::class.java)
}
2021-02-13 23:24:36 +00:00
override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: World, pos: BlockPos): Interface? {
return getBlockEntity(world, pos)?.interfaces?.find { it.side == side }
}
2019-10-27 03:13:26 +00:00
override fun createBlockEntity(world: BlockView) = SwitchBlockEntity()
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
to.offer(getBlockEntity(world, pos))
}
}