Skip to content

Commit

Permalink
Added redstone control #10
Browse files Browse the repository at this point in the history
  • Loading branch information
syorito-hatsuki committed Jul 14, 2023
1 parent bdacbbc commit 2e679d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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(
Expand Down Expand Up @@ -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<Block, BlockState>) {
builder.add(*arrayOf<Property<*>>(AbstractFurnaceBlock.FACING, AbstractFurnaceBlock.LIT))
builder.add(*arrayOf<Property<*>>(FACING, ENABLED))
}

/* Block Entity */
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2e679d2

Please sign in to comment.