From e64424199de4d27fcd7dc52aa16bbf660e6efa66 Mon Sep 17 00:00:00 2001 From: whatsy Date: Wed, 2 Dec 2026 17:11:40 -0500 Subject: [PATCH] documentation + some changes to TypePlateMechanic --- .../cobblemon/mod/common/CobblemonBlocks.kt | 37 ++++++------ .../common/block/typeplate/TypePlateBlock.kt | 60 ++++++++++++++++++- .../block/typeplate/TypePlateMechanic.kt | 6 ++ .../block/typeplate/WaterPlateMechanic.kt | 25 ++------ 4 files changed, 87 insertions(+), 41 deletions(-) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonBlocks.kt b/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonBlocks.kt index a69b1660aa..fa0af52774 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonBlocks.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/CobblemonBlocks.kt @@ -478,126 +478,127 @@ object CobblemonBlocks : PlatformRegistry, ResourceKey = RecordCodecBuilder.mapCodec { instance -> @@ -41,6 +50,7 @@ class TypePlateBlock(properties: Properties, val type: ElementalType) : Directio val ACTIVATED = BooleanProperty.create("activated") val ROTATION = IntegerProperty.create("rotation", 0, 3) + val FACING = DirectionalBlock.FACING private val SHAPES = mapOf( Direction.UP to Shapes.box(3.0 / 16.0, 0.0, 2.0 / 16.0, 13.0 / 16.0, 3.0 / 16.0, 14.0 / 16.0), @@ -80,6 +90,12 @@ class TypePlateBlock(properties: Properties, val type: ElementalType) : Directio ) } + /** + * Get the [TypePlateMechanic] for the given [ElementalType] + * + * @param type The [ElementalType] to check. + * @return The [TypePlateMechanic], if existing. + */ fun getPlateMechanic(type: ElementalType): TypePlateMechanic? { return typeToMechanicMap[type] } @@ -98,7 +114,7 @@ class TypePlateBlock(properties: Properties, val type: ElementalType) : Directio .setValue(FACING, Direction.UP) .setValue(ROTATION, 0) .setValue(ACTIVATED, false) - .setValue(BlockStateProperties.WATERLOGGED, false) + .setValue(WATERLOGGED, false) ) } @@ -145,5 +161,43 @@ class TypePlateBlock(properties: Properties, val type: ElementalType) : Directio return if (state.getValue(BlockStateProperties.WATERLOGGED)) Fluids.WATER.getSource(false) else super.getFluidState(state) } - override fun codec(): MapCodec = CODEC + override fun getLightBlock(state: BlockState, level: BlockGetter, pos: BlockPos): Int { + return 0 + } + + override fun onRemove( + state: BlockState, + level: Level, + pos: BlockPos, + newState: BlockState, + movedByPiston: Boolean + ) { + getPlateMechanic(type)?.onRemove(state, level, pos, newState, movedByPiston, this) + super.onRemove(state, level, pos, newState, movedByPiston) + } + + override fun codec(): MapCodec = CODEC + + override fun updateShape( + state: BlockState, + direction: Direction, + neighborState: BlockState, + level: LevelAccessor, + pos: BlockPos, + neighborPos: BlockPos + ): BlockState? { + if (state.getValue(WATERLOGGED)) { + level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)) + } + return if (!state.canSurvive(level, pos)) { + Blocks.AIR.defaultBlockState() + } else super.updateShape(state, direction, neighborState, level, pos, neighborPos) + } + + override fun getRenderShape(state: BlockState) = RenderShape.MODEL + + override fun canSurvive(state: BlockState, level: LevelReader, pos: BlockPos): Boolean { + getPlateMechanic(type)?.canSurvive(state, level, pos, this)?.let { return it } + return level.getBlockState(pos.relative(state.getValue(FACING).opposite)).isSolid + } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/TypePlateMechanic.kt b/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/TypePlateMechanic.kt index 3c32d8c883..ad7797db45 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/TypePlateMechanic.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/TypePlateMechanic.kt @@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos import net.minecraft.server.level.ServerLevel import net.minecraft.util.RandomSource import net.minecraft.world.level.Level +import net.minecraft.world.level.LevelReader import net.minecraft.world.level.block.state.BlockState /** @@ -11,8 +12,13 @@ import net.minecraft.world.level.block.state.BlockState * Methods are automatically called from the base class. * Add new mechanics to [TypePlateBlock.typeToMechanicMap] * Add more methods as necessary. + * + * @author whatsy + * @since December 2nd, 2026 */ interface TypePlateMechanic { fun onPlace(state: BlockState, level: Level, pos: BlockPos, oldState: BlockState, movedByPiston: Boolean, block: TypePlateBlock) {} fun tick(state: BlockState, level: ServerLevel, pos: BlockPos, random: RandomSource, block: TypePlateBlock) {} + fun onRemove(state: BlockState, level: Level, pos: BlockPos, newState: BlockState, movedByPiston: Boolean, block: TypePlateBlock) {} + fun canSurvive(state: BlockState, level: LevelReader, pos: BlockPos, block: TypePlateBlock): Boolean? { return null } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/WaterPlateMechanic.kt b/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/WaterPlateMechanic.kt index 933b591b80..22b055b3da 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/WaterPlateMechanic.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/block/typeplate/WaterPlateMechanic.kt @@ -14,8 +14,11 @@ import net.minecraft.world.level.block.state.BlockState /** * Handles spawning Manaphy. + * + * @author whatsy + * @since December 2nd, 2026 */ -class WaterPlateMechanic() : TypePlateMechanic { +class WaterPlateMechanic : TypePlateMechanic { override fun onPlace( state: BlockState, @@ -27,24 +30,6 @@ class WaterPlateMechanic() : TypePlateMechanic { ) { if (level.isClientSide) return - val conduitBlock = level.getBlockEntity(pos.above()) as? ConduitBlockEntity ?: return - if (conduitBlock.isActive && state.getValue(DirectionalBlock.FACING) == Direction.UP) { - level.setBlockAndUpdate(pos, state.setValue(TypePlateBlock.ACTIVATED, true)) - level.playSound(null, pos, SoundEvents.ENCHANTMENT_TABLE_USE, SoundSource.BLOCKS) - // IF YOU'RE TWEAKING THE EFFECT, THE NUMBER HERE IS THE DELAY BETWEEN START AND END OF ACTION EFFECT - level.scheduleTick(pos, block, 100) - } - } - - override fun tick( - state: BlockState, - level: ServerLevel, - pos: BlockPos, - random: RandomSource, - block: TypePlateBlock - ) { - level.setBlockAndUpdate(pos.above(), CobblemonBlocks.FLAME_ORB.defaultBlockState()) - level.setBlockAndUpdate(pos, state.setValue(TypePlateBlock.ACTIVATED, false)) - level.playSound(null, pos, SoundEvents.BEACON_ACTIVATE, SoundSource.BLOCKS) + // TODO action effect } } \ No newline at end of file