Use powered property for Redstone Controller instead of lit

This commit is contained in:
Shadowfacts 2021-03-01 21:30:36 -05:00
parent e2fa31b680
commit 4fe6391e69
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 18 additions and 19 deletions

View File

@ -26,10 +26,9 @@ class RedstoneControllerBlock: FaceDeviceBlock<RedstoneControllerBlockEntity>(
companion object { companion object {
val ID = Identifier(PhysicalConnectivity.MODID, "redstone_controller") val ID = Identifier(PhysicalConnectivity.MODID, "redstone_controller")
val LIT = Properties.LIT val POWERED = Properties.POWERED
} }
// todo: don't just copy this from the Interface block
override val faceThickness = 3.0 override val faceThickness = 3.0
override val faceShapes = mapOf( override val faceShapes = mapOf(
Direction.DOWN to createCuboidShape(0.0, 0.0, 0.0, 16.0, 3.0, 16.0), Direction.DOWN to createCuboidShape(0.0, 0.0, 0.0, 16.0, 3.0, 16.0),
@ -42,20 +41,20 @@ class RedstoneControllerBlock: FaceDeviceBlock<RedstoneControllerBlockEntity>(
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) { override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
super.appendProperties(builder) super.appendProperties(builder)
builder.add(LIT) builder.add(POWERED)
} }
override fun createBlockEntity(world: BlockView) = RedstoneControllerBlockEntity() override fun createBlockEntity(world: BlockView) = RedstoneControllerBlockEntity()
override fun getPlacementState(context: ItemPlacementContext): BlockState { override fun getPlacementState(context: ItemPlacementContext): BlockState {
val state = super.getPlacementState(context) val state = super.getPlacementState(context)
return state.with(LIT, isPowered(context.world, context.blockPos, state[FACING])) return state.with(POWERED, isPowered(context.world, context.blockPos, state[FACING]))
} }
override fun neighborUpdate(state: BlockState, world: World, pos: BlockPos, neighborBlock: Block, neighborPos: BlockPos, bl: Boolean) { override fun neighborUpdate(state: BlockState, world: World, pos: BlockPos, neighborBlock: Block, neighborPos: BlockPos, bl: Boolean) {
// this can't be done in getStateForNeighborUpdate because getEmittedRedstonePower is defined in World not WorldAccess // this can't be done in getStateForNeighborUpdate because getEmittedRedstonePower is defined in World not WorldAccess
if (!world.isClient) { if (!world.isClient) {
val wasLit = state[LIT] val wasLit = state[POWERED]
val isLit = isPowered(world, pos, state[FACING]) val isLit = isPowered(world, pos, state[FACING])
if (wasLit != isLit) { if (wasLit != isLit) {
toggleLit(state, world, pos) toggleLit(state, world, pos)
@ -69,7 +68,7 @@ class RedstoneControllerBlock: FaceDeviceBlock<RedstoneControllerBlockEntity>(
} }
private fun toggleLit(state: BlockState, world: World, pos: BlockPos) { private fun toggleLit(state: BlockState, world: World, pos: BlockPos) {
world.setBlockState(pos, state.cycle(LIT), 2) world.setBlockState(pos, state.cycle(POWERED), 2)
getBlockEntity(world, pos)!!.redstoneStateChanged() getBlockEntity(world, pos)!!.redstoneStateChanged()
} }

View File

@ -24,7 +24,7 @@ class RedstoneControllerBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE
fun redstoneStateChanged() { fun redstoneStateChanged() {
val oldPowered = redstonePowered val oldPowered = redstonePowered
redstonePowered = cachedState[RedstoneControllerBlock.LIT] redstonePowered = cachedState[RedstoneControllerBlock.POWERED]
val mode: RemoteActivationPacket.Mode? = when (redstoneMode) { val mode: RemoteActivationPacket.Mode? = when (redstoneMode) {
RedstoneMode.TOGGLE -> if (oldPowered != redstonePowered) RemoteActivationPacket.Mode.SINGLE else null RedstoneMode.TOGGLE -> if (oldPowered != redstonePowered) RemoteActivationPacket.Mode.SINGLE else null

View File

@ -4,51 +4,51 @@
"apply": { "model": "phycon:block/cable_center" } "apply": { "model": "phycon:block/cable_center" }
}, },
{ {
"when": { "facing": "down", "lit": "false" }, "when": { "facing": "down", "powered": "false" },
"apply": { "model": "phycon:block/redstone_controller_side_off" } "apply": { "model": "phycon:block/redstone_controller_side_off" }
}, },
{ {
"when": { "facing": "up", "lit": "false" }, "when": { "facing": "up", "powered": "false" },
"apply": { "model": "phycon:block/redstone_controller_side_off", "x": 180 } "apply": { "model": "phycon:block/redstone_controller_side_off", "x": 180 }
}, },
{ {
"when": { "facing": "north", "lit": "false" }, "when": { "facing": "north", "powered": "false" },
"apply": { "model": "phycon:block/redstone_controller_side_off", "x": 270 } "apply": { "model": "phycon:block/redstone_controller_side_off", "x": 270 }
}, },
{ {
"when": { "facing": "south", "lit": "false" }, "when": { "facing": "south", "powered": "false" },
"apply": { "model": "phycon:block/redstone_controller_side_off", "x": 90 } "apply": { "model": "phycon:block/redstone_controller_side_off", "x": 90 }
}, },
{ {
"when": { "facing": "west", "lit": "false" }, "when": { "facing": "west", "powered": "false" },
"apply": { "model": "phycon:block/redstone_controller_side_off", "x": 90, "y": 90 } "apply": { "model": "phycon:block/redstone_controller_side_off", "x": 90, "y": 90 }
}, },
{ {
"when": { "facing": "east", "lit": "false" }, "when": { "facing": "east", "powered": "false" },
"apply": { "model": "phycon:block/redstone_controller_side_off", "x": 90, "y": 270 } "apply": { "model": "phycon:block/redstone_controller_side_off", "x": 90, "y": 270 }
}, },
{ {
"when": { "facing": "down", "lit": "true" }, "when": { "facing": "down", "powered": "true" },
"apply": { "model": "phycon:block/redstone_controller_side_on" } "apply": { "model": "phycon:block/redstone_controller_side_on" }
}, },
{ {
"when": { "facing": "up", "lit": "true" }, "when": { "facing": "up", "powered": "true" },
"apply": { "model": "phycon:block/redstone_controller_side_on", "x": 180 } "apply": { "model": "phycon:block/redstone_controller_side_on", "x": 180 }
}, },
{ {
"when": { "facing": "north", "lit": "true" }, "when": { "facing": "north", "powered": "true" },
"apply": { "model": "phycon:block/redstone_controller_side_on", "x": 270 } "apply": { "model": "phycon:block/redstone_controller_side_on", "x": 270 }
}, },
{ {
"when": { "facing": "south", "lit": "true" }, "when": { "facing": "south", "powered": "true" },
"apply": { "model": "phycon:block/redstone_controller_side_on", "x": 90 } "apply": { "model": "phycon:block/redstone_controller_side_on", "x": 90 }
}, },
{ {
"when": { "facing": "west", "lit": "true" }, "when": { "facing": "west", "powered": "true" },
"apply": { "model": "phycon:block/redstone_controller_side_on", "x": 90, "y": 90 } "apply": { "model": "phycon:block/redstone_controller_side_on", "x": 90, "y": 90 }
}, },
{ {
"when": { "facing": "east", "lit": "true" }, "when": { "facing": "east", "powered": "true" },
"apply": { "model": "phycon:block/redstone_controller_side_on", "x": 90, "y": 270 } "apply": { "model": "phycon:block/redstone_controller_side_on", "x": 90, "y": 270 }
}, },