Rename block rotation freedom to be more precise

This commit is contained in:
DBotThePony 2023-08-05 20:39:21 +07:00
parent 2b85e5754f
commit ecc89e992c
Signed by: DBot
GPG Key ID: DCC23B5715498507
33 changed files with 85 additions and 124 deletions

View File

@ -230,16 +230,16 @@ fun addDecorativeData(blockStateProvider: MatteryBlockStateProvider, itemModelPr
blockStateProvider.getVariantBuilder(MBlocks.LABORATORY_LAMP).forAllStates {
return@forAllStates ConfiguredModel.builder()
.modelFile(if (it[BlockStateProperties.LIT]) labLampOn!! else labLampOff!!)
.rotationX(it[BlockRotationFreedom.TWO.property].front.xRotationBlockstateNorth())
.rotationY(it[BlockRotationFreedom.TWO.property].front.yRotationBlockstateNorth())
.rotationX(it[BlockRotationFreedom.XZ_XY.property].front.xRotationBlockstateNorth())
.rotationY(it[BlockRotationFreedom.XZ_XY.property].front.yRotationBlockstateNorth())
.build()
}
blockStateProvider.getVariantBuilder(MBlocks.LABORATORY_LAMP_INVERTED).forAllStates {
return@forAllStates ConfiguredModel.builder()
.modelFile(if (it[BlockStateProperties.LIT]) labLampOn!! else labLampOff!!)
.rotationX(it[BlockRotationFreedom.TWO.property].front.xRotationBlockstateNorth())
.rotationY(it[BlockRotationFreedom.TWO.property].front.yRotationBlockstateNorth())
.rotationX(it[BlockRotationFreedom.XZ_XY.property].front.xRotationBlockstateNorth())
.rotationY(it[BlockRotationFreedom.XZ_XY.property].front.yRotationBlockstateNorth())
.build()
}
}

View File

@ -28,7 +28,7 @@ open class BatteryBankProvider(event: GatherDataEvent) : BlockStateProvider(even
forAllStates {
ConfiguredModel.builder()
.modelFile(models().getExistingFile(modLocation("block/$block")))
.rotationY(it[BlockRotationFreedom.ONE.property].front.yRotationBlockstateNorth())
.rotationY(it[BlockRotationFreedom.XZ.property].front.yRotationBlockstateNorth())
.build()
}
}

View File

@ -36,54 +36,54 @@ fun addBlockStates(provider: MatteryBlockStateProvider) {
provider.exec {
with(provider.getMultipartBuilder(MBlocks.PHANTOM_ATTRACTOR)) {
for (dir in BlockRotationFreedom.ONE.possibleValues) {
for (dir in BlockRotationFreedom.XZ.possibleValues) {
part().modelFile(provider.models().getExistingFile(modLocation("block/${MNames.PHANTOM_ATTRACTOR}")))
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockStateProperties.DOUBLE_BLOCK_HALF, DoubleBlockHalf.LOWER)
.condition(BlockRotationFreedom.ONE.property, dir)
.condition(BlockRotationFreedom.XZ.property, dir)
.end()
}
}
with(provider.getMultipartBuilder(MBlocks.ANDROID_CHARGER)) {
for (dir in BlockRotationFreedom.ONE.possibleValues) {
for (dir in BlockRotationFreedom.XZ.possibleValues) {
for (part in AndroidChargerBlock.PART.possibleValues) {
part().modelFile(provider.models().getExistingFile(modLocation("block/${MNames.ANDROID_CHARGER}_${part.serializedName}")))
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(AndroidChargerBlock.PART, part)
.condition(BlockRotationFreedom.ONE.property, dir)
.condition(BlockRotationFreedom.XZ.property, dir)
.end()
}
}
}
with(provider.getMultipartBuilder(MBlocks.MATTER_BOTTLER)) {
for (dir in BlockRotationFreedom.ONE.possibleValues) {
for (dir in BlockRotationFreedom.XZ.possibleValues) {
for (enum in WorkerState.SEMI_WORKER_STATE.possibleValues) {
part().modelFile(provider.models().getExistingFile(modLocation("matter_bottler_${enum.name.lowercase()}")))
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.ONE.property, dir)
.condition(BlockRotationFreedom.XZ.property, dir)
.condition(WorkerState.WORKER_STATE, enum)
.end()
}
}
for (dir in BlockRotationFreedom.ONE.possibleValues) {
for (dir in BlockRotationFreedom.XZ.possibleValues) {
for (enum in MatterBottlerBlock.SLOT_PROPERTIES) {
part().modelFile(provider.models().getExistingFile(modLocation("matter_bottler_${enum.name}_open")))
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.ONE.property, dir)
.condition(BlockRotationFreedom.XZ.property, dir)
.condition(enum, false)
.end()
part().modelFile(provider.models().getExistingFile(modLocation("matter_bottler_${enum.name}_closed")))
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.ONE.property, dir)
.condition(BlockRotationFreedom.XZ.property, dir)
.condition(enum, true)
.end()
}
@ -116,19 +116,19 @@ fun addBlockStates(provider: MatteryBlockStateProvider) {
modLocation("${crate.registryName!!.path}_${if (it.getValue(
CargoCrateBlock.IS_OPEN)) "open" else "closed"}")
))
.rotationY(it.getValue(BlockRotationFreedom.ONE.property).front.yRotationBlockstateNorth())
.rotationY(it.getValue(BlockRotationFreedom.XZ.property).front.yRotationBlockstateNorth())
.buildLast()
)
}
}
with(provider.getMultipartBuilder(MBlocks.STORAGE_BUS)) {
for (dir in BlockRotationFreedom.TWO.possibleValues) {
for (dir in BlockRotationFreedom.XZ_XY.possibleValues) {
part().modelFile(provider.models().getExistingFile(modLocation("storage_bus")))
.rotationX(dir.front.xRotationBlockstateNorth())
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.TWO.property, dir)
.condition(BlockRotationFreedom.XZ_XY.property, dir)
.end()
part().modelFile(provider.models().getExistingFile(modLocation("storage_cable_connection")))
@ -144,12 +144,12 @@ fun addBlockStates(provider: MatteryBlockStateProvider) {
}
with(provider.getMultipartBuilder(MBlocks.STORAGE_IMPORTER)) {
for (dir in BlockRotationFreedom.TWO.possibleValues) {
for (dir in BlockRotationFreedom.XZ_XY.possibleValues) {
part().modelFile(provider.models().getExistingFile(modLocation("storage_importer")))
.rotationX(dir.front.xRotationBlockstateNorth())
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.TWO.property, dir)
.condition(BlockRotationFreedom.XZ_XY.property, dir)
.end()
part().modelFile(provider.models().getExistingFile(modLocation("storage_cable_connection")))
@ -165,12 +165,12 @@ fun addBlockStates(provider: MatteryBlockStateProvider) {
}
with(provider.getMultipartBuilder(MBlocks.STORAGE_EXPORTER)) {
for (dir in BlockRotationFreedom.TWO.possibleValues) {
for (dir in BlockRotationFreedom.XZ_XY.possibleValues) {
part().modelFile(provider.models().getExistingFile(modLocation("storage_exporter")))
.rotationX(dir.front.xRotationBlockstateNorth())
.rotationY(dir.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.TWO.property, dir)
.condition(BlockRotationFreedom.XZ_XY.property, dir)
.end()
part().modelFile(provider.models().getExistingFile(modLocation("storage_cable_connection")))

View File

@ -12,12 +12,12 @@ import ru.dbotthepony.mc.otm.registry.MBlocks
fun addComplexBlockStates(provider: MatteryBlockStateProvider) {
with(provider.getMultipartBuilder(MBlocks.DRIVE_VIEWER)) {
for (facing in BlockRotationFreedom.ONE.possibleValues) {
for (facing in BlockRotationFreedom.XZ.possibleValues) {
part()
.modelFile(provider.models().getExistingFile(modLocation("block/drive_viewer_drive_part")))
.rotationY(facing.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.ONE.property, facing)
.condition(BlockRotationFreedom.XZ.property, facing)
.condition(DriveViewerBlock.DRIVE_PRESENT, true)
for (workState in WorkerState.SEMI_WORKER_STATE.possibleValues) {
@ -26,25 +26,25 @@ fun addComplexBlockStates(provider: MatteryBlockStateProvider) {
.rotationY(facing.front.yRotationBlockstateNorth())
.addModel()
.condition(WorkerState.SEMI_WORKER_STATE, workState)
.condition(BlockRotationFreedom.ONE.property, facing)
.condition(BlockRotationFreedom.XZ.property, facing)
}
}
}
with(provider.getMultipartBuilder(MBlocks.PATTERN_STORAGE)) {
for (facing in BlockRotationFreedom.ONE.possibleValues) {
for (facing in BlockRotationFreedom.XZ.possibleValues) {
part()
.modelFile(provider.models().getExistingFile(modLocation("block/pattern_storage")))
.rotationY(facing.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.ONE.property, facing)
.condition(BlockRotationFreedom.XZ.property, facing)
for (i in 0 .. 7) {
part()
.modelFile(provider.models().getExistingFile(modLocation("block/pattern/model$i")))
.rotationY(facing.front.yRotationBlockstateNorth())
.addModel()
.condition(BlockRotationFreedom.ONE.property, facing)
.condition(BlockRotationFreedom.XZ.property, facing)
.condition(PatternStorageBlock.PATTERN_STORAGE_DISKS_PROPS[i], true)
}
}

View File

@ -21,16 +21,16 @@ private val EMPTY: BlockStateTransform = { _, _, _ -> null }
private fun initialTransform(it: BlockState, modelPath: String, builder: ConfiguredModel.Builder<*>): String {
@Suppress("NAME_SHADOWING") var modelPath = modelPath
it.getValueNullable(BlockRotationFreedom.ONE.property)?.let {
it.getValueNullable(BlockRotationFreedom.XZ.property)?.let {
builder.rotationY(it.front.yRotationBlockstateNorth())
}
it.getValueNullable(BlockRotationFreedom.TWO.property)?.let {
it.getValueNullable(BlockRotationFreedom.XZ_XY.property)?.let {
builder.rotationY(it.front.yRotationBlockstateNorth())
builder.rotationX(it.front.xRotationBlockstateNorth())
}
it.getValueNullable(BlockRotationFreedom.THREE.property)?.let {
it.getValueNullable(BlockRotationFreedom.XZ_XY_ZY.property)?.let {
builder.rotationY(it.front.yRotationBlockstateNorth() + it.top.yRotationBlockstateNorth())
builder.rotationX(it.front.xRotationBlockstateNorth())
}

View File

@ -115,9 +115,9 @@ abstract class MatteryBlock @JvmOverloads constructor(
val state = blockState.getOptionalValue(WorkerState.WORKER_STATE).or { blockState.getOptionalValue(WorkerState.SEMI_WORKER_STATE) }
if (state.isPresent && state.get() == WorkerState.WORKING) {
val state2 = blockState.getOptionalValue(BlockRotationFreedom.ONE.property)
.or { blockState.getOptionalValue(BlockRotationFreedom.TWO.property) }
.or { blockState.getOptionalValue(BlockRotationFreedom.THREE.property) }
val state2 = blockState.getOptionalValue(BlockRotationFreedom.XZ.property)
.or { blockState.getOptionalValue(BlockRotationFreedom.XZ_XY.property) }
.or { blockState.getOptionalValue(BlockRotationFreedom.XZ_XY_ZY.property) }
if (state2.isPresent) {
val direction = state2.get()

View File

@ -22,17 +22,17 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
return when (val freedom = rotationFreedom()) {
BlockRotationFreedom.ONE -> defaultBlockState().setValue(
BlockRotationFreedom.XZ -> defaultBlockState().setValue(
freedom.property,
freedom.of(if (faceToPlayer(context)) context.horizontalDirection.opposite else context.horizontalDirection)
)
BlockRotationFreedom.TWO -> defaultBlockState().setValue(
BlockRotationFreedom.XZ_XY -> defaultBlockState().setValue(
freedom.property,
freedom.of(if (faceToPlayer(context)) context.nearestLookingDirection.opposite else context.nearestLookingDirection)
)
BlockRotationFreedom.THREE -> {
BlockRotationFreedom.XZ_XY_ZY -> {
val primary = if (faceToPlayer(context)) context.nearestLookingDirection.opposite else context.nearestLookingDirection
var secondary = if (faceToPlayer(context)) context.horizontalDirection else context.horizontalDirection.opposite
@ -59,7 +59,7 @@ abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Prope
val rotationProperty get() = rotationFreedom().property
open fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.ONE
return BlockRotationFreedom.XZ
}
open fun faceToPlayer(context: BlockPlaceContext): Boolean {

View File

@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.block.decorative
import net.minecraft.ChatFormatting
import net.minecraft.core.BlockPos
import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
import net.minecraft.world.level.BlockGetter
@ -30,7 +29,7 @@ class EngineBlock : RotatableMatteryBlock(Properties.of().mapColor(MapColor.COLO
}
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
private val shapes = getShapeForEachState { BlockShapes.ENGINE.rotateFromNorth(it[rotationProperty]).computeShape() }

View File

@ -15,7 +15,7 @@ import ru.dbotthepony.mc.otm.shapes.BlockShapes
class HoloSignBlock : RotatableMatteryBlock(), EntityBlock {
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.THREE
return BlockRotationFreedom.XZ_XY_ZY
}
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {

View File

@ -23,11 +23,10 @@ import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.blockRotation
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.unaryMinus
import ru.dbotthepony.mc.otm.once
import ru.dbotthepony.mc.otm.registry.MBlocks
private val FACING_FULL = BlockRotationFreedom.TWO.property
private val FACING_FULL = BlockRotationFreedom.XZ_XY.property
class LaboratoryLampLight : Block(Properties.of().strength(-1.0F, 3600000.8F).noCollission().noLootTable().replaceable().lightLevel { 15 }) {
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {

View File

@ -122,8 +122,8 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter
if (isRemoved)
return
val front = blockPos + blockState.getValue(BlockRotationFreedom.TWO.property)
val storage = level?.getBlockEntity(front)?.getCapability(ForgeCapabilities.ITEM_HANDLER, -blockState.getValue(BlockRotationFreedom.TWO.property))?.let { if (it.isPresent) it else null }
val front = blockPos + blockState.getValue(BlockRotationFreedom.XZ_XY.property)
val storage = level?.getBlockEntity(front)?.getCapability(ForgeCapabilities.ITEM_HANDLER, -blockState.getValue(BlockRotationFreedom.XZ_XY.property))?.let { if (it.isPresent) it else null }
if (neighbour != storage) {
neighbour = storage

View File

@ -2,20 +2,19 @@ package ru.dbotthepony.mc.otm.block.entity.tech
import net.minecraft.core.BlockPos
import net.minecraft.core.SectionPos
import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.AABB
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.block.tech.BlockGravitationStabilizerLens
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
import ru.dbotthepony.mc.otm.block.tech.BlockGravitationStabilizer
import ru.dbotthepony.mc.otm.core.math.facingTwo
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.times
import ru.dbotthepony.mc.otm.registry.MBlockEntities
@ -27,7 +26,7 @@ class GravitationStabilizerBlockEntity(p_155229_: BlockPos, p_155230_: BlockStat
fun tick(level: Level) {
var findBlackHole: BlackHoleBlockEntity? = null
val dir = blockState.facingTwo.normal
val dir = blockState[BlockRotationFreedom.XZ_XY].normal
for (i in 2 .. RANGE) {
val pos = blockPos + dir * i

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.matter
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
@ -20,7 +19,6 @@ import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -4,7 +4,6 @@ import net.minecraft.MethodsReturnNonnullByDefault
import javax.annotation.ParametersAreNonnullByDefault
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.entity.BlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterDecomposerBlockEntity
@ -20,7 +19,6 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -13,9 +13,9 @@ import net.minecraft.world.level.BlockGetter
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.item.context.BlockPlaceContext
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotation
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.rotationTwo
class MatterPanelBlock : RotatableMatteryBlock(), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
@ -25,10 +25,10 @@ class MatterPanelBlock : RotatableMatteryBlock(), EntityBlock {
private val shapes: ImmutableMap<BlockState, VoxelShape>
init {
registerDefaultState(getStateDefinition().any().setValue(BlockRotationFreedom.TWO.property, BlockRotation.SOUTH))
registerDefaultState(getStateDefinition().any().setValue(BlockRotationFreedom.XZ_XY.property, BlockRotation.SOUTH))
shapes = getShapeForEachState {
when (it.rotationTwo.front) {
when (it[BlockRotationFreedom.XZ_XY.property].front) {
Direction.NORTH -> Shapes.box(
0.0,
0.0,
@ -91,10 +91,10 @@ class MatterPanelBlock : RotatableMatteryBlock(), EntityBlock {
}
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
return defaultBlockState().setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(context.clickedFace))
return defaultBlockState().setValue(BlockRotationFreedom.XZ_XY.property, BlockRotation.of(context.clickedFace))
}
}

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.matter
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
@ -18,7 +17,6 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.matter
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
@ -18,7 +17,6 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterReplicatorBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.matter
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
@ -18,7 +17,6 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterScannerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.storage
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.network.chat.Component
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
@ -20,7 +19,6 @@ import ru.dbotthepony.mc.otm.block.entity.storage.DriveRackBlockEntity
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.storage
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.network.chat.Component
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
@ -25,7 +24,6 @@ import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.storage
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.network.chat.Component
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
@ -20,7 +19,6 @@ import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorBlockEntity
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -27,8 +27,6 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotation
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.facingTwo
import ru.dbotthepony.mc.otm.core.math.rotationTwo
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.core.math.unaryMinus
@ -36,7 +34,7 @@ import ru.dbotthepony.mc.otm.oncePre
class StorageBusBlock : RotatableMatteryBlock(), EntityBlock {
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
init {
@ -54,7 +52,7 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock {
}
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(-context.clickedFace))
return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.XZ_XY.property, BlockRotation.of(-context.clickedFace))
}
override fun appendHoverText(

View File

@ -28,15 +28,13 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotation
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.facingTwo
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.core.math.unaryMinus
import ru.dbotthepony.mc.otm.oncePre
class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
@ -78,7 +76,7 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
}
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(-context.clickedFace))
return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.XZ_XY.property, BlockRotation.of(-context.clickedFace))
}
override fun appendHoverText(
@ -118,7 +116,7 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock {
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
@ -171,7 +169,7 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock {
}
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(-context.clickedFace))
return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.XZ_XY.property, BlockRotation.of(-context.clickedFace))
}
private val shapes = getShapeForEachState {

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.storage
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.network.chat.Component
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
@ -20,7 +19,6 @@ import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntit
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.tech
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.EntityBlock
@ -17,7 +16,6 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -26,8 +26,8 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.facingTwo
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.times
import ru.dbotthepony.mc.otm.oncePre
@ -55,7 +55,7 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock {
}
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
@ -68,7 +68,7 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock {
val blockPos = context.clickedPos
val level = context.level
for (face in BlockRotationFreedom.TWO.possibleValues) {
for (face in BlockRotationFreedom.XZ_XY.possibleValues) {
val dir = face.normal
for (i in 1 ..GravitationStabilizerBlockEntity.RANGE) {
@ -78,14 +78,14 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock {
if (!getState.isAir) {
if (chunk.getBlockEntity(pos) is BlackHoleBlockEntity) {
state = state.setValue(BlockRotationFreedom.TWO.property, face)
state = state.setValue(BlockRotationFreedom.XZ_XY.property, face)
break
}
}
}
}
val bbPos = blockPos + state.getValue(BlockRotationFreedom.TWO.property).normal
val bbPos = blockPos + state.getValue(BlockRotationFreedom.XZ_XY.property).normal
if (!context.level.isInWorldBounds(bbPos)) return null
if (!level.getBlockState(bbPos).canBeReplaced(context)) return null
@ -103,9 +103,9 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock {
super.setPlacedBy(level, blockPos, blockState, entity, itemStack)
if (!level.isClientSide) {
val bbPos = blockPos + blockState.getValue(BlockRotationFreedom.TWO.property).normal
val bbPos = blockPos + blockState.getValue(BlockRotationFreedom.XZ_XY.property).normal
val newState = MBlocks.GRAVITATION_STABILIZER_LENS.defaultBlockState()
.setValue(BlockRotationFreedom.TWO.property, blockState.getValue(BlockRotationFreedom.TWO.property))
.setValue(BlockRotationFreedom.XZ_XY.property, blockState.getValue(BlockRotationFreedom.XZ_XY.property))
level.setBlock(bbPos, newState, UPDATE_ALL)
}
@ -137,7 +137,7 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock {
p_60557_: BlockPos,
p_60558_: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingTwo.ordinal]
return SHAPES[p_60555_[BlockRotationFreedom.XZ_XY].ordinal]
}
companion object {
@ -155,14 +155,14 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock {
}
fun getBoundingBlockPos(blockState: BlockState, blockPos: BlockPos): BlockPos {
return blockPos + blockState.getValue(BlockRotationFreedom.TWO.property).normal
return blockPos + blockState.getValue(BlockRotationFreedom.XZ_XY.property).normal
}
}
}
class BlockGravitationStabilizerLens : RotatableMatteryBlock(props) {
override fun rotationFreedom(): BlockRotationFreedom {
return BlockRotationFreedom.TWO
return BlockRotationFreedom.XZ_XY
}
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
@ -196,7 +196,7 @@ class BlockGravitationStabilizerLens : RotatableMatteryBlock(props) {
p_60557_: BlockPos,
p_60558_: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingTwo.ordinal]
return SHAPES[p_60555_[BlockRotationFreedom.XZ_XY].front.ordinal]
}
companion object {
@ -205,7 +205,7 @@ class BlockGravitationStabilizerLens : RotatableMatteryBlock(props) {
}
fun getBoundingBlockPos(blockState: BlockState, blockPos: BlockPos): BlockPos {
return blockPos + blockState.getValue(BlockRotationFreedom.TWO.property).front.opposite.normal
return blockPos + blockState.getValue(BlockRotationFreedom.XZ_XY.property).front.opposite.normal
}
private val SHAPES = arrayOf(

View File

@ -24,15 +24,12 @@ import net.minecraft.world.level.material.MapColor
import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import net.minecraftforge.common.ForgeHooks
import net.minecraftforge.event.ForgeEventFactory
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.core.math.minus
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.rotationOne
import ru.dbotthepony.mc.otm.once
import ru.dbotthepony.mc.otm.registry.MBlocks
import ru.dbotthepony.mc.otm.shapes.BlockShapes

View File

@ -1,7 +1,6 @@
package ru.dbotthepony.mc.otm.block.tech
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.network.chat.Component
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
@ -22,8 +21,6 @@ import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.getShapeForEachState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
class PlatePressBlock(properties: Properties = DEFAULT_PROPERTIES, val isTwin: Boolean = false) : RotatableMatteryBlock(properties), EntityBlock {

View File

@ -23,7 +23,6 @@ import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.core.math.rotate
import ru.dbotthepony.mc.otm.core.math.rotateY
import ru.dbotthepony.mc.otm.nanoTime
@ -50,7 +49,7 @@ abstract class BankRenderer<T : MatteryDeviceBlockEntity>(private val context: B
stack.pushPose()
stack.translate(0.5f, 0.5f, 0.5f)
stack.rotate(blockEntity.blockState[BlockRotationFreedom.ONE.property].front)
stack.rotate(blockEntity.blockState[BlockRotationFreedom.XZ.property].front)
stack.translate(-0.5f, -0.5f, -0.5f)
for ((i, model) in models.withIndex()) {
@ -74,7 +73,7 @@ abstract class BankRenderer<T : MatteryDeviceBlockEntity>(private val context: B
stack.pushPose()
val facing = blockEntity.blockState.facingOne
val facing = blockEntity.blockState[BlockRotationFreedom.XZ].front
val rotateFacing = facing == Direction.NORTH || facing == Direction.SOUTH
if (rotateFacing) {

View File

@ -19,6 +19,7 @@ import ru.dbotthepony.mc.otm.client.ShiftPressedCond
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.VECTOR_DOWN
import ru.dbotthepony.mc.otm.core.math.VECTOR_FORWARD
@ -26,14 +27,12 @@ import ru.dbotthepony.mc.otm.core.math.VECTOR_RIGHT
import ru.dbotthepony.mc.otm.core.math.VECTOR_UP
import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.math.asAngle
import ru.dbotthepony.mc.otm.core.math.facingTwo
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.rotateAroundAxis
import ru.dbotthepony.mc.otm.core.math.times
import ru.dbotthepony.mc.otm.core.util.formatMatter
import kotlin.math.PI
@Suppress("PrivatePropertyName")
class GravitationStabilizerRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<GravitationStabilizerBlockEntity> {
override fun render(
tile: GravitationStabilizerBlockEntity,
@ -48,7 +47,7 @@ class GravitationStabilizerRenderer(private val context: BlockEntityRendererProv
var len = 64.0
var lenI = 64
val normal = tile.blockState.facingTwo.normal
val normal = tile.blockState[BlockRotationFreedom.XZ_XY].normal
val level = tile.level
var bhTile: BlackHoleBlockEntity? = null
@ -69,7 +68,7 @@ class GravitationStabilizerRenderer(private val context: BlockEntityRendererProv
poseStack.pushPose()
poseStack.translate(0.5, 0.5, 0.5)
val facing = tile.blockState.facingTwo
val facing = tile.blockState[BlockRotationFreedom.XZ_XY].front
val rotateZ: Double
val rotateY: Double

View File

@ -9,10 +9,10 @@ import ru.dbotthepony.mc.otm.client.font
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.render.draw
import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing
import ru.dbotthepony.mc.otm.core.math.rotationThree
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {
override fun render(
@ -27,7 +27,7 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context)
return
poseStack.pushPose()
poseStack.rotateWithBlockFacing(tile.blockState.rotationThree)
poseStack.rotateWithBlockFacing(tile.blockState[BlockRotationFreedom.XZ_XY_ZY])
poseStack.translate(0.5f, 0.5f, 0.5f)
poseStack.scale(0.01f, 0.01f, 0.01f)

View File

@ -38,6 +38,8 @@ import net.minecraftforge.items.IItemHandler
import net.minecraftforge.registries.ForgeRegistries
import net.minecraftforge.registries.ForgeRegistry
import net.minecraftforge.registries.IForgeRegistry
import ru.dbotthepony.mc.otm.core.math.BlockRotation
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.util.readInt
import ru.dbotthepony.mc.otm.core.util.readVarIntLE
@ -204,6 +206,10 @@ operator fun <T : Comparable<T>> StateHolder<*, *>.get(property: Property<T>): T
return getValue(property)
}
operator fun StateHolder<*, *>.get(property: BlockRotationFreedom): BlockRotation {
return getValue(property.property)
}
operator fun <S : StateHolder<*, *>, T : Comparable<T>> S.set(property: Property<T>, value: T): S {
setValue(property, value)
return this

View File

@ -1,30 +1,20 @@
package ru.dbotthepony.mc.otm.core.math
import net.minecraft.core.Direction
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.properties.EnumProperty
import ru.dbotthepony.mc.otm.core.get
import java.util.EnumMap
internal inline val BlockState.rotationOne: BlockRotation get() = this[BlockRotationFreedom.ONE.property]
internal inline val BlockState.rotationTwo: BlockRotation get() = this[BlockRotationFreedom.TWO.property]
internal inline val BlockState.rotationThree: BlockRotation get() = this[BlockRotationFreedom.THREE.property]
internal inline val BlockState.facingOne: Direction get() = this[BlockRotationFreedom.ONE.property].front
internal inline val BlockState.facingTwo: Direction get() = this[BlockRotationFreedom.TWO.property].front
internal inline val BlockState.facingThree: Direction get() = this[BlockRotationFreedom.THREE.property].front
/**
* Controls the rotational freedom of block in space, employing [property] and [of] to get valid value from set of possible values
*/
enum class BlockRotationFreedom(vararg values: BlockRotation) {
ONE(
XZ(
BlockRotation.NORTH,
BlockRotation.SOUTH,
BlockRotation.WEST,
BlockRotation.EAST,
),
TWO(
XZ_XY(
BlockRotation.DOWN,
BlockRotation.UP,
BlockRotation.NORTH,
@ -32,7 +22,7 @@ enum class BlockRotationFreedom(vararg values: BlockRotation) {
BlockRotation.WEST,
BlockRotation.EAST,
),
THREE(
XZ_XY_ZY(
BlockRotation.DOWN,
BlockRotation.UP,
BlockRotation.NORTH,