Implement rotate method of OTM blocks

This commit is contained in:
DBotThePony 2022-10-12 10:15:26 +07:00
parent 6b1b90a795
commit f737abd976
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -16,6 +16,7 @@ import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.Rotation
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.StateDefinition
import net.minecraft.world.level.block.state.properties.EnumProperty
@ -27,6 +28,7 @@ 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
import ru.dbotthepony.mc.otm.core.get
interface IDroppableContainer {
val droppableContainer: Container
@ -200,11 +202,12 @@ abstract class MatteryBlock @JvmOverloads constructor(
abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Properties = DEFAULT_PROPERTIES) : MatteryBlock(properties) {
init {
registerDefaultState(getStateDefinition().any().setValue(facingProperty(), Direction.SOUTH))
@Suppress("LeakingThis")
registerDefaultState(getStateDefinition().any().setValue(facingProperty, Direction.SOUTH))
}
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
builder.add(facingProperty())
builder.add(facingProperty)
}
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
@ -221,14 +224,19 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope
}
}
fun facingProperty() = if (hasFreeRotation) FACING_FULL else FACING
@Suppress("OVERRIDE_DEPRECATION")
override fun rotate(blockState: BlockState, rotation: Rotation): BlockState {
@Suppress("DEPRECATION")
return super.rotate(blockState, rotation).setValue(facingProperty, rotation.rotate(blockState[facingProperty]))
}
val facingProperty get() = if (hasFreeRotation) FACING_FULL else FACING
open val hasFreeRotation get() = false
open fun faceToPlayer(context: BlockPlaceContext): Boolean {
return true
}
open val hasFreeRotation get() = false
companion object {
val FACING: EnumProperty<Direction> = EnumProperty.create(
"facing",