feat: facing and waterlogged state for RS block

This commit is contained in:
xtex 2023-07-28 10:02:30 +08:00
parent dfa5627ddd
commit 69449c8e66
Signed by: xtex
GPG Key ID: B918086ED8045B91
2 changed files with 55 additions and 8 deletions

View File

@ -47,9 +47,6 @@ object CABlock : HorizontalDirectionalBlock(
return super.defaultBlockState().setValue(FACING, context.horizontalDirection)
}
@Suppress("OVERRIDE_DEPRECATION")
override fun getRenderShape(state: BlockState) = RenderShape.MODEL
@Suppress("OVERRIDE_DEPRECATION")
override fun getShape(state: BlockState, level: BlockGetter, pos: BlockPos, context: CollisionContext) =
shapes[state]!!

View File

@ -2,12 +2,15 @@ package quaedam.misc.reality
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.HorizontalDirectionalBlock
import net.minecraft.world.level.block.SimpleWaterloggedBlock
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.Level
import net.minecraft.world.level.LevelAccessor
import net.minecraft.world.level.block.*
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.material.FluidState
import net.minecraft.world.level.material.Fluids
import net.minecraft.world.level.material.MapColor
object RSBlock : HorizontalDirectionalBlock(
@ -15,7 +18,7 @@ object RSBlock : HorizontalDirectionalBlock(
.noOcclusion()
.strength(3f)
.requiresCorrectToolForDrops()
.mapColor(MapColor.COLOR_CYAN)
.mapColor(MapColor.COLOR_BLUE)
), EntityBlock, SimpleWaterloggedBlock {
init {
@ -28,4 +31,51 @@ object RSBlock : HorizontalDirectionalBlock(
override fun newBlockEntity(pos: BlockPos, state: BlockState) = RSBlockEntity(pos, state)
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
super.createBlockStateDefinition(builder)
builder.add(FACING, BlockStateProperties.WATERLOGGED)
}
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
if (!context.level.getBlockState(context.clickedPos.below()).canOcclude()) return null
return super.defaultBlockState().setValue(FACING, context.horizontalDirection)
}
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
override fun updateShape(
state: BlockState,
direction: Direction,
neighborState: BlockState,
level: LevelAccessor,
pos: BlockPos,
neighborPos: BlockPos
): BlockState {
if (state.getValue(BlockStateProperties.WATERLOGGED)) {
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level))
}
return super.updateShape(state, direction, neighborState, level, pos, neighborPos)
}
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
override fun getFluidState(state: BlockState): FluidState = if (state.getValue(BlockStateProperties.WATERLOGGED)) {
Fluids.WATER.getSource(false)
} else {
super.getFluidState(state)
}
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
override fun neighborChanged(
state: BlockState,
level: Level,
pos: BlockPos,
neighborBlock: Block,
neighborPos: BlockPos,
movedByPiston: Boolean
) {
super.neighborChanged(state, level, pos, neighborBlock, neighborPos, movedByPiston)
if (!level.getBlockState(pos.below()).canOcclude()) {
level.destroyBlock(pos, true)
}
}
}