From 2e679d28db4efd1c34ac26168e423df9732e0486 Mon Sep 17 00:00:00 2001 From: syorito-hatsuki Date: Sat, 15 Jul 2023 02:08:38 +0300 Subject: [PATCH] Added redstone control #10 --- gradle.properties | 2 +- .../yacg/common/block/GeneratorBlock.kt | 25 ++++++++++++++++--- .../block/entity/GeneratorBlockEntity.kt | 3 +++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 12462a0..aee2bb4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loaderVersion=0.14.21 fabricVersion=0.83.0+1.20 loomVersion=1.2-SNAPSHOT # Mod Properties -modVersion=2023.7.2 +modVersion=2023.7.3 mavenGroup=dev.syoritohatsuki archivesBaseName=yacg # Kotlin diff --git a/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/GeneratorBlock.kt b/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/GeneratorBlock.kt index 6efcdbd..7e08996 100644 --- a/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/GeneratorBlock.kt +++ b/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/GeneratorBlock.kt @@ -20,7 +20,9 @@ import net.minecraft.item.ItemPlacementContext import net.minecraft.item.ItemStack import net.minecraft.item.Items import net.minecraft.state.StateManager +import net.minecraft.state.property.BooleanProperty import net.minecraft.state.property.DirectionProperty +import net.minecraft.state.property.Properties import net.minecraft.state.property.Property import net.minecraft.text.Text import net.minecraft.util.* @@ -37,11 +39,14 @@ open class GeneratorBlock(internal val type: String) : BlockEntityProvider { companion object { + val ENABLED: BooleanProperty = Properties.ENABLED val FACING: DirectionProperty = HorizontalFacingBlock.FACING } init { - defaultState = (stateManager.defaultState as BlockState).with(FACING, Direction.NORTH) as BlockState + defaultState = ((stateManager.defaultState as BlockState) + .with(FACING, Direction.NORTH) as BlockState) + .with(ENABLED, true) as BlockState } override fun appendTooltip( @@ -71,10 +76,10 @@ open class GeneratorBlock(internal val type: String) : ) as BlockState override fun mirror(state: BlockState, mirror: BlockMirror): BlockState = - state.rotate(mirror.getRotation(state.get(AbstractFurnaceBlock.FACING) as Direction)) + state.rotate(mirror.getRotation(state.get(FACING) as Direction)) override fun appendProperties(builder: StateManager.Builder) { - builder.add(*arrayOf>(AbstractFurnaceBlock.FACING, AbstractFurnaceBlock.LIT)) + builder.add(*arrayOf>(FACING, ENABLED)) } /* Block Entity */ @@ -97,6 +102,20 @@ open class GeneratorBlock(internal val type: String) : } } + override fun neighborUpdate( + state: BlockState, + world: World, + pos: BlockPos, + sourceBlock: Block, + sourcePos: BlockPos, + notify: Boolean + ) { + val bl: Boolean = !world.isReceivingRedstonePower(pos) + if (bl != state.get(ENABLED)) world.setBlockState( + pos, state.with(HopperBlock.ENABLED, bl) as BlockState, 4 + ) + } + override fun onBreak(world: World, pos: BlockPos, state: BlockState, player: PlayerEntity) { super.onBreak(world, pos, state, player) val x = player.x diff --git a/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/entity/GeneratorBlockEntity.kt b/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/entity/GeneratorBlockEntity.kt index d79c80b..4dfa66b 100644 --- a/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/entity/GeneratorBlockEntity.kt +++ b/src/main/kotlin/dev/syoritohatsuki/yacg/common/block/entity/GeneratorBlockEntity.kt @@ -1,6 +1,7 @@ package dev.syoritohatsuki.yacg.common.block.entity import dev.syoritohatsuki.yacg.YetAnotherCobblestoneGenerator.logger +import dev.syoritohatsuki.yacg.common.block.GeneratorBlock import dev.syoritohatsuki.yacg.common.item.UpgradeItem.UpgradesTypes import dev.syoritohatsuki.yacg.config.GeneratorsConfig import dev.syoritohatsuki.yacg.config.UpgradesConfig @@ -45,6 +46,8 @@ class GeneratorBlockEntity( if (entity.progress == (entity.maxProcess / entity.speedDivider).toByte()) { + if (!blockState.get(GeneratorBlock.ENABLED)) return + val randomBlock = getRandomBlock( entity.type, GeneratorsConfig.getBlocks(entity.type) ?: return,