Convert Extractor and Inserter to FaceDeviceBlocks
This commit is contained in:
parent
73cb991d21
commit
6e4d1e63a9
|
@ -3,13 +3,9 @@ package net.shadowfacts.phycon.block.extractor
|
|||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Material
|
||||
import net.minecraft.block.ShapeContext
|
||||
import net.minecraft.entity.LivingEntity
|
||||
import net.minecraft.item.ItemPlacementContext
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.sound.BlockSoundGroup
|
||||
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
|
||||
|
@ -17,16 +13,13 @@ import net.minecraft.util.shape.VoxelShape
|
|||
import net.minecraft.util.shape.VoxelShapes
|
||||
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.block.DeviceBlock
|
||||
import java.util.*
|
||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class ExtractorBlock: DeviceBlock<ExtractorBlockEntity>(
|
||||
class ExtractorBlock: FaceDeviceBlock<ExtractorBlockEntity>(
|
||||
Settings.of(Material.METAL)
|
||||
.strength(1.5f)
|
||||
.sounds(BlockSoundGroup.METAL)
|
||||
|
@ -34,7 +27,6 @@ class ExtractorBlock: DeviceBlock<ExtractorBlockEntity>(
|
|||
|
||||
companion object {
|
||||
val ID = Identifier(PhysicalConnectivity.MODID, "extractor")
|
||||
val FACING = Properties.FACING
|
||||
private val EXTRACTOR_SHAPES = mutableMapOf<Direction, VoxelShape>()
|
||||
|
||||
init {
|
||||
|
@ -42,7 +34,6 @@ class ExtractorBlock: DeviceBlock<ExtractorBlockEntity>(
|
|||
doubleArrayOf(0.0, 0.0, 0.0, 16.0, 2.0, 16.0),
|
||||
doubleArrayOf(2.0, 2.0, 2.0, 14.0, 4.0, 14.0),
|
||||
doubleArrayOf(4.0, 4.0, 4.0, 12.0, 6.0, 12.0),
|
||||
doubleArrayOf(6.0, 6.0, 6.0, 10.0, 16.0, 10.0)
|
||||
)
|
||||
val directions = arrayOf(
|
||||
Triple(Direction.DOWN, null, false),
|
||||
|
@ -73,34 +64,11 @@ class ExtractorBlock: DeviceBlock<ExtractorBlockEntity>(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getNetworkConnectedSides(state: BlockState, world: WorldAccess, pos: BlockPos): Collection<Direction> {
|
||||
return EnumSet.of(state[FACING].opposite)
|
||||
}
|
||||
|
||||
override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: WorldAccess, pos: BlockPos): Interface? {
|
||||
return if (side == state[FACING].opposite) {
|
||||
getBlockEntity(world, pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
|
||||
super.appendProperties(builder)
|
||||
builder.add(FACING)
|
||||
}
|
||||
override val faceThickness = 6.0
|
||||
override val faceShapes: Map<Direction, VoxelShape> = EXTRACTOR_SHAPES
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = ExtractorBlockEntity()
|
||||
|
||||
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
||||
val facing = if (context.player?.isSneaking == true) context.side.opposite else context.playerLookDirection.opposite
|
||||
return defaultState.with(FACING, facing)
|
||||
}
|
||||
|
||||
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: ShapeContext): VoxelShape {
|
||||
return EXTRACTOR_SHAPES[state[FACING]]!!
|
||||
}
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
||||
if (!world.isClient) {
|
||||
getBlockEntity(world, pos)!!.updateInventory()
|
||||
|
|
|
@ -5,13 +5,13 @@ import alexiil.mc.lib.attributes.Simulation
|
|||
import alexiil.mc.lib.attributes.item.FixedItemInv
|
||||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||
import alexiil.mc.lib.attributes.item.filter.ExactItemStackFilter
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||
import net.shadowfacts.phycon.component.ActivationController
|
||||
import net.shadowfacts.phycon.component.NetworkStackDispatcher
|
||||
import net.shadowfacts.phycon.component.finishTimedOutPendingInsertions
|
||||
|
@ -36,7 +36,7 @@ class ExtractorBlockEntity: DeviceBlockEntity(PhyBlockEntities.EXTRACTOR),
|
|||
}
|
||||
|
||||
private val facing: Direction
|
||||
get() = cachedState[ExtractorBlock.FACING]
|
||||
get() = cachedState[FaceDeviceBlock.FACING]
|
||||
|
||||
private var inventory: FixedItemInv? = null
|
||||
override val pendingInsertions = mutableListOf<PendingInsertion>()
|
||||
|
|
|
@ -4,19 +4,14 @@ import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
|||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Material
|
||||
import net.minecraft.block.ShapeContext
|
||||
import net.minecraft.entity.LivingEntity
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.item.ItemPlacementContext
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
import net.minecraft.sound.BlockSoundGroup
|
||||
import net.minecraft.state.StateManager
|
||||
import net.minecraft.state.property.Properties
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.ActionResult
|
||||
import net.minecraft.util.Hand
|
||||
import net.minecraft.util.Identifier
|
||||
|
@ -27,24 +22,20 @@ import net.minecraft.util.shape.VoxelShape
|
|||
import net.minecraft.util.shape.VoxelShapes
|
||||
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.block.DeviceBlock
|
||||
import net.shadowfacts.phycon.block.extractor.ExtractorBlock
|
||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class InserterBlock: DeviceBlock<InserterBlockEntity>(
|
||||
class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
||||
Settings.of(Material.METAL)
|
||||
.strength(1.5f)
|
||||
.sounds(BlockSoundGroup.METAL)
|
||||
) {
|
||||
companion object {
|
||||
val ID = Identifier(PhysicalConnectivity.MODID, "inserter")
|
||||
val FACING = Properties.FACING
|
||||
private val INSERTER_SHAPES = mutableMapOf<Direction, VoxelShape>()
|
||||
|
||||
init {
|
||||
|
@ -52,7 +43,6 @@ class InserterBlock: DeviceBlock<InserterBlockEntity>(
|
|||
doubleArrayOf(4.0, 0.0, 4.0, 12.0, 2.0, 12.0),
|
||||
doubleArrayOf(2.0, 2.0, 2.0, 14.0, 4.0, 14.0),
|
||||
doubleArrayOf(0.0, 4.0, 0.0, 16.0, 6.0, 16.0),
|
||||
doubleArrayOf(6.0, 6.0, 6.0, 10.0, 16.0, 10.0)
|
||||
)
|
||||
val directions = arrayOf(
|
||||
Triple(Direction.DOWN, null, false),
|
||||
|
@ -83,34 +73,11 @@ class InserterBlock: DeviceBlock<InserterBlockEntity>(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getNetworkConnectedSides(state: BlockState, world: WorldAccess, pos: BlockPos): Collection<Direction> {
|
||||
return EnumSet.of(state[FACING].opposite)
|
||||
}
|
||||
|
||||
override fun getNetworkInterfaceForSide(side: Direction, state: BlockState, world: WorldAccess, pos: BlockPos): Interface? {
|
||||
return if (side == state[FACING].opposite) {
|
||||
getBlockEntity(world, pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
|
||||
super.appendProperties(builder)
|
||||
builder.add(FACING)
|
||||
}
|
||||
override val faceThickness = 6.0
|
||||
override val faceShapes: Map<Direction, VoxelShape> = INSERTER_SHAPES
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = InserterBlockEntity()
|
||||
|
||||
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
||||
val facing = if (context.player?.isSneaking == true) context.side.opposite else context.playerLookDirection.opposite
|
||||
return defaultState.with(FACING, facing)
|
||||
}
|
||||
|
||||
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: ShapeContext): VoxelShape {
|
||||
return INSERTER_SHAPES[state[FACING]]!!
|
||||
}
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
||||
if (!world.isClient) {
|
||||
getBlockEntity(world, pos)!!.updateInventory()
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.nbt.CompoundTag
|
|||
import net.minecraft.util.math.Direction
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||
import net.shadowfacts.phycon.component.ActivationController
|
||||
import net.shadowfacts.phycon.component.ItemStackPacketHandler
|
||||
import net.shadowfacts.phycon.component.NetworkStackProvider
|
||||
|
@ -34,7 +35,7 @@ class InserterBlockEntity: DeviceBlockEntity(PhyBlockEntities.INSERTER),
|
|||
}
|
||||
|
||||
private val facing: Direction
|
||||
get() = cachedState[InserterBlock.FACING]
|
||||
get() = cachedState[FaceDeviceBlock.FACING]
|
||||
|
||||
private var inventory: ItemInsertable? = null
|
||||
private var currentRequest: PendingExtractRequest? = null
|
||||
|
|
|
@ -18,7 +18,6 @@ import net.minecraft.world.WorldAccess
|
|||
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||
import net.shadowfacts.phycon.api.Interface
|
||||
import net.shadowfacts.phycon.block.DeviceBlock
|
||||
import net.shadowfacts.phycon.block.extractor.ExtractorBlock
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -56,7 +55,7 @@ class MinerBlock: DeviceBlock<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)
|
||||
return defaultState.with(FACING, facing)
|
||||
}
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, itemStack: ItemStack) {
|
||||
|
|
|
@ -19,6 +19,10 @@ class PhyModelProvider(resourceManager: ResourceManager) : ModelResourceProvider
|
|||
val REDSTONE_CONTROLLER = Identifier(PhysicalConnectivity.MODID, "block/redstone_controller")
|
||||
val REDSTONE_EMITTER = Identifier(PhysicalConnectivity.MODID, "block/redstone_emitter")
|
||||
val REDSTONE_EMITTER_SIDE = Identifier(PhysicalConnectivity.MODID, "block/redstone_emitter_side")
|
||||
val EXTRACTOR = Identifier(PhysicalConnectivity.MODID, "block/extractor")
|
||||
val EXTRACTOR_SIDE = Identifier(PhysicalConnectivity.MODID, "block/extractor_side")
|
||||
val INSERTER = Identifier(PhysicalConnectivity.MODID, "block/inserter")
|
||||
val INSERTER_SIDE = Identifier(PhysicalConnectivity.MODID, "block/inserter_side")
|
||||
}
|
||||
|
||||
override fun loadModelResource(resourceId: Identifier, context: ModelProviderContext): UnbakedModel? {
|
||||
|
@ -26,6 +30,8 @@ class PhyModelProvider(resourceManager: ResourceManager) : ModelResourceProvider
|
|||
INTERFACE -> SimpleFaceDeviceModel(INTERFACE_SIDE)
|
||||
REDSTONE_CONTROLLER -> RedstoneControllerModel
|
||||
REDSTONE_EMITTER -> SimpleFaceDeviceModel(REDSTONE_EMITTER_SIDE)
|
||||
EXTRACTOR -> SimpleFaceDeviceModel(EXTRACTOR_SIDE)
|
||||
INSERTER -> SimpleFaceDeviceModel(INSERTER_SIDE)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"facing=down": {
|
||||
"model": "phycon:block/extractor"
|
||||
},
|
||||
"facing=up": {
|
||||
"model": "phycon:block/extractor",
|
||||
"x": 180
|
||||
},
|
||||
"facing=north": {
|
||||
"model": "phycon:block/extractor",
|
||||
"x": 270
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "phycon:block/extractor",
|
||||
"x": 90
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "phycon:block/extractor",
|
||||
"x": 90,
|
||||
"y": 90
|
||||
},
|
||||
"facing=east": {
|
||||
"model": "phycon:block/extractor",
|
||||
"x": 90,
|
||||
"y": 270
|
||||
"multipart": [
|
||||
{
|
||||
"apply": {"model": "phycon:block/extractor"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,29 +1,7 @@
|
|||
{
|
||||
"variants": {
|
||||
"facing=down": {
|
||||
"model": "phycon:block/inserter"
|
||||
},
|
||||
"facing=up": {
|
||||
"model": "phycon:block/inserter",
|
||||
"x": 180
|
||||
},
|
||||
"facing=north": {
|
||||
"model": "phycon:block/inserter",
|
||||
"x": 270
|
||||
},
|
||||
"facing=south": {
|
||||
"model": "phycon:block/inserter",
|
||||
"x": 90
|
||||
},
|
||||
"facing=west": {
|
||||
"model": "phycon:block/inserter",
|
||||
"x": 90,
|
||||
"y": 90
|
||||
},
|
||||
"facing=east": {
|
||||
"model": "phycon:block/inserter",
|
||||
"x": 90,
|
||||
"y": 270
|
||||
"multipart": [
|
||||
{
|
||||
"apply": {"model": "phycon:block/inserter"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
{
|
||||
"parent": "block/block",
|
||||
"textures": {
|
||||
"cable_side": "phycon:block/cable_straight",
|
||||
"cable_end": "phycon:block/cable_cap_end"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
|
@ -38,17 +36,6 @@
|
|||
"west": {"texture": "phycon:block/extractor_side"},
|
||||
"east": {"texture": "phycon:block/extractor_side"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [6, 6, 6],
|
||||
"to": [10, 16, 10],
|
||||
"faces": {
|
||||
"up": {"texture": "#cable_end", "cullface": "up"},
|
||||
"north": {"texture": "#cable_side"},
|
||||
"south": {"texture": "#cable_side"},
|
||||
"west": {"texture": "#cable_side"},
|
||||
"east": {"texture": "#cable_side"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
{
|
||||
"parent": "block/block",
|
||||
"textures": {
|
||||
"cable_side": "phycon:block/cable_straight",
|
||||
"cable_end": "phycon:block/cable_cap_end"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
|
@ -38,17 +36,6 @@
|
|||
"west": {"texture": "phycon:block/extractor_side"},
|
||||
"east": {"texture": "phycon:block/extractor_side"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [6, 6, 6],
|
||||
"to": [10, 16, 10],
|
||||
"faces": {
|
||||
"up": {"texture": "#cable_end", "cullface": "up"},
|
||||
"north": {"texture": "#cable_side"},
|
||||
"south": {"texture": "#cable_side"},
|
||||
"west": {"texture": "#cable_side"},
|
||||
"east": {"texture": "#cable_side"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue