Implement rotate method of OTM blocks
This commit is contained in:
parent
6b1b90a795
commit
f737abd976
@ -16,6 +16,7 @@ import net.minecraft.world.item.context.BlockPlaceContext
|
|||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.Block
|
import net.minecraft.world.level.block.Block
|
||||||
import net.minecraft.world.level.block.EntityBlock
|
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.BlockState
|
||||||
import net.minecraft.world.level.block.state.StateDefinition
|
import net.minecraft.world.level.block.state.StateDefinition
|
||||||
import net.minecraft.world.level.block.state.properties.EnumProperty
|
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.component1
|
||||||
import ru.dbotthepony.mc.otm.core.component2
|
import ru.dbotthepony.mc.otm.core.component2
|
||||||
import ru.dbotthepony.mc.otm.core.component3
|
import ru.dbotthepony.mc.otm.core.component3
|
||||||
|
import ru.dbotthepony.mc.otm.core.get
|
||||||
|
|
||||||
interface IDroppableContainer {
|
interface IDroppableContainer {
|
||||||
val droppableContainer: Container
|
val droppableContainer: Container
|
||||||
@ -200,11 +202,12 @@ abstract class MatteryBlock @JvmOverloads constructor(
|
|||||||
|
|
||||||
abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Properties = DEFAULT_PROPERTIES) : MatteryBlock(properties) {
|
abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Properties = DEFAULT_PROPERTIES) : MatteryBlock(properties) {
|
||||||
init {
|
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>) {
|
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
||||||
builder.add(facingProperty())
|
builder.add(facingProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
|
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 {
|
open fun faceToPlayer(context: BlockPlaceContext): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
open val hasFreeRotation get() = false
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val FACING: EnumProperty<Direction> = EnumProperty.create(
|
val FACING: EnumProperty<Direction> = EnumProperty.create(
|
||||||
"facing",
|
"facing",
|
||||||
|
Loading…
Reference in New Issue
Block a user