49 lines
1.6 KiB
Kotlin
49 lines
1.6 KiB
Kotlin
package net.shadowfacts.phycon.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.sound.BlockSoundGroup
|
|
import net.minecraft.util.Identifier
|
|
import net.minecraft.util.math.BlockPos
|
|
import net.minecraft.util.math.Direction
|
|
import net.minecraft.world.BlockView
|
|
import net.minecraft.world.World
|
|
import net.minecraft.world.WorldAccess
|
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
import net.shadowfacts.phycon.api.Interface
|
|
import net.shadowfacts.phycon.api.NetworkComponentBlock
|
|
import net.shadowfacts.phycon.block.BlockWithEntity
|
|
import java.util.*
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class SwitchBlock: BlockWithEntity<SwitchBlockEntity>(
|
|
Settings.of(Material.METAL)
|
|
.strength(1.5f)
|
|
.sounds(BlockSoundGroup.METAL)
|
|
),
|
|
NetworkComponentBlock,
|
|
AttributeProvider {
|
|
|
|
companion object {
|
|
val ID = Identifier(PhysicalConnectivity.MODID, "switch")
|
|
}
|
|
|
|
override fun getNetworkConnectedSides(state: BlockState, world: WorldAccess, pos: BlockPos): Collection<Direction> {
|
|
return EnumSet.allOf(Direction::class.java)
|
|
}
|
|
|
|
override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: WorldAccess, pos: BlockPos): Interface? {
|
|
return getBlockEntity(world, pos)?.interfaces?.find { it.side == side }
|
|
}
|
|
|
|
override fun createBlockEntity(world: BlockView) = SwitchBlockEntity()
|
|
|
|
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
|
to.offer(getBlockEntity(world, pos))
|
|
}
|
|
}
|