documentation + some changes to TypePlateMechanic

This commit is contained in:
whatsy committed 2026-12-02 17:11:40 -05:00
1 parent b1cc052763
commit e64424199d
4 files changed
+87 -41

No files matched your search

@@ -478,126 +478,127 @@ object CobblemonBlocks : PlatformRegistry<Registry<Block>, ResourceKey<Registry<
@JvmField
val BLANK_PLATE = this.create("blank_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops().noOcclusion()
.lightLevel { if (it.getValue(TypePlateBlock.ACTIVATED)) 6 else 0 },
ElementalTypes.NORMAL
)
)
@JvmField
val FLAME_PLATE = this.create("flame_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.FIRE
)
)
@JvmField
val SPLASH_PLATE = this.create("splash_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.WATER
)
)
@JvmField
val ZAP_PLATE = this.create("zap_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.ELECTRIC
)
)
@JvmField
val MEADOW_PLATE = this.create("meadow_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.GRASS
)
)
@JvmField
val ICICLE_PLATE = this.create("icicle_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.ICE
)
)
@JvmField
val FIST_PLATE = this.create("fist_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.FIGHTING
)
)
@JvmField
val TOXIC_PLATE = this.create("toxic_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.POISON
)
)
@JvmField
val EARTH_PLATE = this.create("earth_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.GROUND
)
)
@JvmField
val SKY_PLATE = this.create("sky_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.FLYING
)
)
@JvmField
val MIND_PLATE = this.create("mind_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.PSYCHIC
)
)
@JvmField
val INSECT_PLATE = this.create("insect_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.BUG
)
)
@JvmField
val STONE_PLATE = this.create("stone_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.ROCK
)
)
@JvmField
val SPOOKY_PLATE = this.create("spooky_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.GHOST
)
)
@JvmField
val DRACO_PLATE = this.create("draco_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.DRAGON
)
)
@JvmField
val DREAD_PLATE = this.create("dread_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.DARK
)
)
@JvmField
val IRON_PLATE = this.create("iron_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.STEEL
)
)
@JvmField
val PIXIE_PLATE = this.create("pixie_plate",
TypePlateBlock(
BlockBehaviour.Properties.of().strength(1.0F).sound(SoundType.METAL).requiresCorrectToolForDrops(),
BlockBehaviour.Properties.ofFullCopy(BLANK_PLATE),
ElementalTypes.FAIRY
)
)
@@ -12,12 +12,17 @@ import net.minecraft.util.RandomSource
import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.LevelAccessor
import net.minecraft.world.level.LevelReader
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.DirectionalBlock
import net.minecraft.world.level.block.RenderShape
import net.minecraft.world.level.block.SimpleWaterloggedBlock
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.StateDefinition
import net.minecraft.world.level.block.state.properties.BlockStateProperties
import net.minecraft.world.level.block.state.properties.BlockStateProperties.WATERLOGGED
import net.minecraft.world.level.block.state.properties.BooleanProperty
import net.minecraft.world.level.block.state.properties.IntegerProperty
import net.minecraft.world.level.material.FluidState
@@ -27,9 +32,13 @@ import net.minecraft.world.phys.shapes.Shapes
import net.minecraft.world.phys.shapes.VoxelShape
/**
* A type plate block (wow)
* Logic should be diverted to a [TypePlateMechanic] class whenever possible.
*
* @author whatsy
* @since December 2nd, 2026
*/
class TypePlateBlock(properties: Properties, val type: ElementalType) : DirectionalBlock(properties.noOcclusion()), SimpleWaterloggedBlock {
class TypePlateBlock(properties: Properties, val type: ElementalType) : DirectionalBlock(properties), SimpleWaterloggedBlock {
companion object {
val CODEC: MapCodec<TypePlateBlock> = 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<out DirectionalBlock> = 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<out TypePlateBlock> = 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
}
}
@@ -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 }
}
@@ -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
}
}