2021-02-15 04:42:19 +00:00
|
|
|
package net.shadowfacts.phycon.network.block.miner
|
|
|
|
|
|
|
|
import net.minecraft.block.Block
|
|
|
|
import net.minecraft.block.BlockState
|
|
|
|
import net.minecraft.block.Material
|
|
|
|
import net.minecraft.entity.LivingEntity
|
|
|
|
import net.minecraft.item.ItemPlacementContext
|
|
|
|
import net.minecraft.item.ItemStack
|
|
|
|
import net.minecraft.state.StateManager
|
|
|
|
import net.minecraft.state.property.Properties
|
|
|
|
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
|
2021-02-18 03:29:18 +00:00
|
|
|
import net.minecraft.world.WorldAccess
|
2021-02-15 04:42:19 +00:00
|
|
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
|
|
import net.shadowfacts.phycon.api.Interface
|
|
|
|
import net.shadowfacts.phycon.network.DeviceBlock
|
|
|
|
import net.shadowfacts.phycon.network.block.extractor.ExtractorBlock
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class MinerBlock: DeviceBlock<MinerBlockEntity>(Settings.of(Material.METAL)) {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
val ID = Identifier(PhysicalConnectivity.MODID, "miner")
|
|
|
|
val FACING = Properties.FACING
|
|
|
|
}
|
|
|
|
|
2021-02-18 03:29:18 +00:00
|
|
|
override fun getNetworkConnectedSides(state: BlockState, world: WorldAccess, pos: BlockPos): Collection<Direction> {
|
2021-02-15 04:42:19 +00:00
|
|
|
return EnumSet.of(state[FACING].opposite)
|
|
|
|
}
|
|
|
|
|
2021-02-18 03:29:18 +00:00
|
|
|
override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: WorldAccess, pos: BlockPos): Interface? {
|
2021-02-15 04:42:19 +00:00
|
|
|
return if (side == state[FACING]) {
|
|
|
|
null
|
|
|
|
} else {
|
|
|
|
getBlockEntity(world, pos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
|
|
|
|
super.appendProperties(builder)
|
|
|
|
builder.add(FACING)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun createBlockEntity(world: BlockView) = MinerBlockEntity()
|
|
|
|
|
|
|
|
override fun getPlacementState(context: ItemPlacementContext): BlockState? {
|
|
|
|
val facing = if (context.player?.isSneaking == true) context.side.opposite else context.playerFacing.opposite
|
|
|
|
return defaultState.with(ExtractorBlock.FACING, facing)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, itemStack: ItemStack) {
|
|
|
|
if (!world.isClient) {
|
|
|
|
// getBlockEntity(world, pos)!!.updateBlockToMine()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun neighborUpdate(state: BlockState, world: World, pos: BlockPos, neighbor: Block, neighborPos: BlockPos, bl: Boolean) {
|
|
|
|
if (!world.isClient) {
|
|
|
|
// getBlockEntity(world, pos)!!.updateBlockToMine()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|