diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt index b75ff5ec0..19cd87725 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt @@ -2,6 +2,8 @@ package ru.dbotthepony.mc.otm.block import net.minecraft.core.BlockPos import net.minecraft.core.Direction +import net.minecraft.core.particles.DustParticleOptions +import net.minecraft.util.RandomSource import net.minecraft.world.Container import net.minecraft.world.Containers import net.minecraft.world.InteractionHand @@ -21,6 +23,10 @@ import net.minecraft.world.level.material.Material import net.minecraft.world.level.material.MaterialColor import net.minecraft.world.phys.BlockHitResult import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.component1 +import ru.dbotthepony.mc.otm.core.component2 +import ru.dbotthepony.mc.otm.core.component3 interface IDroppableContainer { val droppableContainer: Container @@ -70,6 +76,49 @@ abstract class MatteryBlock @JvmOverloads constructor( return super.use(blockState, level, blockPos, ply, hand, blockHitResult) } + override fun animateTick(blockState: BlockState, level: Level, blockPos: BlockPos, random: RandomSource) { + if (this is EntityBlock) { + val state = blockState.getOptionalValue(WorkerState.WORKER_STATE).or { blockState.getOptionalValue(WorkerState.SEMI_WORKER_STATE) } + + if (state.isPresent && state.get() == WorkerState.WORKING) { + val state2 = blockState.getOptionalValue(RotatableMatteryBlock.FACING).or { blockState.getOptionalValue(RotatableMatteryBlock.FACING_FULL) } + + if (state2.isPresent) { + val direction = state2.get() + + val (x, y, z) = blockPos + var xd = x + 0.5 + var yd = y + 0.5 + var zd = z + 0.5 + + val (nx, ny, nz) = direction.normal + xd += nx * 0.5 + yd += ny * 0.5 + zd += nz * 0.5 + + when (direction) { + Direction.DOWN, Direction.UP -> { + xd += random.nextDouble() - 0.5 + zd += random.nextDouble() - 0.5 + } + + Direction.NORTH, Direction.SOUTH -> { + xd += random.nextDouble() - 0.5 + yd += random.nextDouble() - 0.5 + } + + Direction.WEST, Direction.EAST -> { + yd += random.nextDouble() - 0.5 + zd += random.nextDouble() - 0.5 + } + } + + level.addParticle(DustParticleOptions.REDSTONE, xd, yd, zd, 0.0, 0.0, 0.0) + } + } + } + } + @Suppress("OVERRIDE_DEPRECATION") override fun getMenuProvider(blockState: BlockState, level: Level, blockPos: BlockPos): MenuProvider? { if (this is EntityBlock) {