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 import net.minecraft.world.BlockView import net.minecraft.world.World 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(Settings.of(Material.METAL)), NetworkComponentBlock, AttributeProvider { companion object { val ID = Identifier(PhysicalConnectivity.MODID, "switch") } override fun getNetworkConnectedSides(state: BlockState, world: World, pos: BlockPos): Collection { return EnumSet.allOf(Direction::class.java) } override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: World, 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)) } }