76 lines
2.5 KiB
Kotlin
76 lines
2.5 KiB
Kotlin
package net.shadowfacts.phycon.block.terminal
|
|
|
|
import alexiil.mc.lib.attributes.AttributeList
|
|
import alexiil.mc.lib.attributes.AttributeProvider
|
|
import net.minecraft.block.Block
|
|
import net.minecraft.block.BlockState
|
|
import net.minecraft.block.Material
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
import net.minecraft.item.ItemPlacementContext
|
|
import net.minecraft.sound.BlockSoundGroup
|
|
import net.minecraft.state.StateManager
|
|
import net.minecraft.state.property.Properties
|
|
import net.minecraft.util.ActionResult
|
|
import net.minecraft.util.Hand
|
|
import net.minecraft.util.Identifier
|
|
import net.minecraft.util.ItemScatterer
|
|
import net.minecraft.util.hit.BlockHitResult
|
|
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.NetworkComponentBlock
|
|
import net.shadowfacts.phycon.block.DeviceBlock
|
|
import java.util.EnumSet
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
abstract class AbstractTerminalBlock<T: AbstractTerminalBlockEntity>: DeviceBlock<T>(
|
|
Settings.of(Material.METAL)
|
|
.strength(1.5f)
|
|
.sounds(BlockSoundGroup.METAL)
|
|
),
|
|
NetworkComponentBlock,
|
|
AttributeProvider {
|
|
|
|
companion object {
|
|
val FACING = Properties.FACING
|
|
}
|
|
|
|
override fun getNetworkConnectedSides(state: BlockState, world: WorldAccess, pos: BlockPos): Collection<Direction> {
|
|
val set = EnumSet.allOf(Direction::class.java)
|
|
set.remove(state[FACING])
|
|
return set
|
|
}
|
|
|
|
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
|
|
super.appendProperties(builder)
|
|
builder.add(FACING)
|
|
}
|
|
|
|
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
|
return defaultState.with(FACING, context.playerLookDirection.opposite)
|
|
}
|
|
|
|
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult): ActionResult {
|
|
getBlockEntity(world, pos)!!.onActivate(player)
|
|
return ActionResult.SUCCESS
|
|
}
|
|
|
|
override fun onStateReplaced(state: BlockState, world: World, pos: BlockPos, newState: BlockState, moved: Boolean) {
|
|
if (!state.isOf(newState.block)) {
|
|
val be = getBlockEntity(world, pos)!!
|
|
be.dropItems()
|
|
|
|
super.onStateReplaced(state, world, pos, newState, moved)
|
|
}
|
|
}
|
|
|
|
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
|
to.offer(getBlockEntity(world, pos))
|
|
}
|
|
}
|