2019-10-27 01:36:31 +00:00
|
|
|
package net.shadowfacts.phycon.network.block.networkinterface
|
|
|
|
|
|
|
|
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.LivingEntity
|
|
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
|
|
import net.minecraft.item.ItemPlacementContext
|
|
|
|
import net.minecraft.item.ItemStack
|
|
|
|
import net.minecraft.state.StateFactory
|
|
|
|
import net.minecraft.state.property.Properties
|
|
|
|
import net.minecraft.util.Hand
|
|
|
|
import net.minecraft.util.Identifier
|
|
|
|
import net.minecraft.util.hit.BlockHitResult
|
|
|
|
import net.minecraft.util.math.BlockPos
|
|
|
|
import net.minecraft.world.BlockView
|
|
|
|
import net.minecraft.world.World
|
|
|
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
|
|
import net.shadowfacts.phycon.block.BlockWithEntity
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class NetworkInterfaceBlock: BlockWithEntity<NetworkInterfaceBlockEntity>(Settings.of(Material.METAL)), AttributeProvider {
|
|
|
|
companion object {
|
|
|
|
val ID = Identifier(PhysicalConnectivity.MODID, "network_interface")
|
|
|
|
val FACING = Properties.FACING
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun appendProperties(builder: StateFactory.Builder<Block, BlockState>) {
|
|
|
|
super.appendProperties(builder)
|
|
|
|
builder.add(FACING)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun createBlockEntity(world: BlockView) = NetworkInterfaceBlockEntity()
|
|
|
|
|
|
|
|
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
|
|
|
val facing = if (context.player?.isSneaking == true) context.playerFacing else context.playerFacing.opposite
|
|
|
|
return defaultState.with(FACING, facing)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, stack: ItemStack) {
|
|
|
|
if (!world.isClient) {
|
|
|
|
getBlockEntity(world, pos)!!.updateInventory()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun neighborUpdate(state: BlockState, world: World, pos: BlockPos, neighborBlock: Block, neighborPos: BlockPos, boolean_1: Boolean) {
|
|
|
|
if (!world.isClient) {
|
|
|
|
getBlockEntity(world, pos)!!.updateInventory()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
|
|
|
to.offer(getBlockEntity(world, pos))
|
|
|
|
}
|
|
|
|
|
2019-10-27 02:10:48 +00:00
|
|
|
}
|