From e2791add3bdb295ba82e89370b77b6999ac77f9e Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 30 Jan 2023 11:10:14 +0700 Subject: [PATCH] Add BlockRotationFreedom and BlockRotation without changing any logic --- .../mc/otm/datagen/DecorativeData.kt | 9 +- .../mc/otm/datagen/blocks/Banks.kt | 11 +- .../mc/otm/datagen/blocks/BlockStates.kt | 67 ++++----- .../otm/datagen/blocks/ComplexBlockStates.kt | 21 +-- .../blocks/MatteryBlockStateProvider.kt | 11 +- .../ru/dbotthepony/mc/otm/block/Cables.kt | 22 ++- .../mc/otm/block/IDroppableContainer.kt | 21 +++ .../dbotthepony/mc/otm/block/MatteryBlock.kt | 100 +------------ .../mc/otm/block/RotatableMatteryBlock.kt | 51 +++++++ .../mc/otm/block/decorative/EngineBlock.kt | 8 +- .../mc/otm/block/decorative/HoloSignBlock.kt | 10 +- .../mc/otm/block/decorative/LaboratoryLamp.kt | 23 +-- .../dbotthepony/mc/otm/block/entity/Cables.kt | 8 +- .../entity/storage/StorageBusBlockEntity.kt | 12 +- .../block/entity/storage/StorageInterfaces.kt | 12 +- .../entity/tech/BatteryBankBlockEntity.kt | 10 +- .../tech/ChemicalGeneratorBlockEntity.kt | 3 +- .../tech/GravitationStabilizerBlockEntity.kt | 3 +- .../mc/otm/block/matter/MatterBottlerBlock.kt | 3 +- .../block/matter/MatterCapacitorBankBlock.kt | 3 +- .../otm/block/matter/MatterDecomposerBlock.kt | 5 +- .../mc/otm/block/matter/MatterPanelBlock.kt | 14 +- .../otm/block/matter/MatterRecyclerBlock.kt | 3 +- .../otm/block/matter/MatterReplicatorBlock.kt | 5 +- .../mc/otm/block/matter/MatterScannerBlock.kt | 5 +- .../otm/block/matter/PatternStorageBlock.kt | 5 +- .../mc/otm/block/storage/DriveRackBlock.kt | 3 +- .../mc/otm/block/storage/DriveViewerBlock.kt | 3 +- .../mc/otm/block/storage/ItemMonitorBlock.kt | 3 +- .../mc/otm/block/storage/StorageBusBlock.kt | 11 +- .../mc/otm/block/storage/StorageInterfaces.kt | 19 ++- .../storage/StoragePowerSupplierBlock.kt | 3 +- .../mc/otm/block/tech/BatteryBankBlock.kt | 3 +- .../otm/block/tech/ChemicalGeneratorBlock.kt | 3 +- .../mc/otm/block/tech/EnergyServoBlock.kt | 3 +- .../block/tech/GravitationStabilizerBlock.kt | 28 ++-- .../otm/block/tech/PhantomAttractorBlock.kt | 3 +- .../mc/otm/block/tech/PlatePressBlock.kt | 3 +- .../client/render/blockentity/BankRenderer.kt | 3 +- .../GravitationStabilizerRenderer.kt | 5 +- .../render/blockentity/HoloSignRenderer.kt | 3 +- .../mc/otm/core/math/BlockRotation.kt | 137 ++++++++++++++++++ .../mc/otm/core/math/BlockRotationFreedom.kt | 50 +++++++ 43 files changed, 480 insertions(+), 248 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/block/IDroppableContainer.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/block/RotatableMatteryBlock.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotation.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotationFreedom.kt diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DecorativeData.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DecorativeData.kt index d574dc669..fe4d252be 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DecorativeData.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DecorativeData.kt @@ -11,6 +11,7 @@ import net.minecraftforge.client.model.generators.ModelFile import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.core.get +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.datagen.blocks.MatteryBlockStateProvider import ru.dbotthepony.mc.otm.datagen.items.MatteryItemModelProvider @@ -216,16 +217,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[RotatableMatteryBlock.FACING_FULL].toXRotBlockstate()) - .rotationY(it[RotatableMatteryBlock.FACING_FULL].toYRotBlockstate()) + .rotationX(it[BlockRotationFreedom.TWO.property].primary.toXRotBlockstate()) + .rotationY(it[BlockRotationFreedom.TWO.property].primary.toYRotBlockstate()) .build() } blockStateProvider.getVariantBuilder(MBlocks.LABORATORY_LAMP_INVERTED).forAllStates { return@forAllStates ConfiguredModel.builder() .modelFile(if (it[BlockStateProperties.LIT]) labLampOn!! else labLampOff!!) - .rotationX(it[RotatableMatteryBlock.FACING_FULL].toXRotBlockstate()) - .rotationY(it[RotatableMatteryBlock.FACING_FULL].toYRotBlockstate()) + .rotationX(it[BlockRotationFreedom.TWO.property].primary.toXRotBlockstate()) + .rotationY(it[BlockRotationFreedom.TWO.property].primary.toYRotBlockstate()) .build() } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/Banks.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/Banks.kt index b17567cde..8fe6a9ede 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/Banks.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/Banks.kt @@ -6,6 +6,7 @@ import net.minecraftforge.client.model.generators.BlockStateProvider import net.minecraftforge.data.event.GatherDataEvent import ru.dbotthepony.mc.otm.block.tech.BatteryBankBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.datagen.DataGen import ru.dbotthepony.mc.otm.datagen.toYRotBlockstate import ru.dbotthepony.mc.otm.registry.MBlocks @@ -26,15 +27,15 @@ open class BatteryBankProvider(event: GatherDataEvent) : BlockStateProvider(even with(getMultipartBuilder(registry)) { val battery_bank = models().getExistingFile(ResourceLocation("overdrive_that_matters:block/$block")) - RotatableMatteryBlock.FACING.possibleValues.forEach { - part().modelFile(battery_bank).rotationY(it.toYRotBlockstate()).addModel().condition( - RotatableMatteryBlock.FACING, it) + BlockRotationFreedom.ONE.possibleValues.forEach { + part().modelFile(battery_bank).rotationY(it.primary.toYRotBlockstate()).addModel().condition( + BlockRotationFreedom.ONE.property, it) for (i in 0 .. 11) { part().modelFile( models().getExistingFile(ResourceLocation("overdrive_that_matters:$batteryPath$i")) - ).rotationY(it.toYRotBlockstate()).addModel() - .condition(RotatableMatteryBlock.FACING, it) + ).rotationY(it.primary.toYRotBlockstate()).addModel() + .condition(BlockRotationFreedom.ONE.property, it) .condition(BatteryBankBlock.BATTERY_SLOTS_PROPS[i], true) } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/BlockStates.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/BlockStates.kt index 6869638f6..e83b8671b 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/BlockStates.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/BlockStates.kt @@ -10,6 +10,7 @@ import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.datagen.modLocation import ru.dbotthepony.mc.otm.datagen.toXRotBlockstate @@ -36,41 +37,41 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { provider.exec { with(provider.getMultipartBuilder(MBlocks.PHANTOM_ATTRACTOR)) { - for (dir in RotatableMatteryBlock.FACING.possibleValues) { + for (dir in BlockRotationFreedom.ONE.possibleValues) { part().modelFile(provider.models().getExistingFile(modLocation("block/${MNames.PHANTOM_ATTRACTOR}"))) - .rotationY(dir.toYRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() .condition(BlockStateProperties.DOUBLE_BLOCK_HALF, DoubleBlockHalf.LOWER) - .condition(RotatableMatteryBlock.FACING, dir) + .condition(BlockRotationFreedom.ONE.property, dir) .end() } } with(provider.getMultipartBuilder(MBlocks.MATTER_BOTTLER)) { - for (dir in RotatableMatteryBlock.FACING.possibleValues) { + for (dir in BlockRotationFreedom.ONE.possibleValues) { for (enum in WorkerState.SEMI_WORKER_STATE.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_bottler_${enum.name.lowercase()}"))) - .rotationY(dir.toYRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING, dir) + .condition(BlockRotationFreedom.ONE.property, dir) .condition(WorkerState.WORKER_STATE, enum) .end() } } - for (dir in RotatableMatteryBlock.FACING.possibleValues) { + for (dir in BlockRotationFreedom.ONE.possibleValues) { for (enum in MatterBottlerBlock.SLOT_PROPERTIES) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_bottler_${enum.name}_open"))) - .rotationY(dir.toYRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING, dir) + .condition(BlockRotationFreedom.ONE.property, dir) .condition(enum, false) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "matter_bottler_${enum.name}_closed"))) - .rotationY(dir.toYRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING, dir) + .condition(BlockRotationFreedom.ONE.property, dir) .condition(enum, true) .end() } @@ -98,26 +99,26 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { OverdriveThatMatters.MOD_ID, "${crate.registryName!!.path}_${if (it.getValue( CargoCrateBlock.IS_OPEN)) "open" else "closed"}") )) - .rotationY(it.getValue(RotatableMatteryBlock.FACING).toYRotBlockstate()) + .rotationY(it.getValue(BlockRotationFreedom.ONE.property).primary.toYRotBlockstate()) .buildLast() ) } } with(provider.getMultipartBuilder(MBlocks.STORAGE_BUS)) { - for (dir in net.minecraft.core.Direction.values()) { + for (dir in BlockRotationFreedom.TWO.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_bus"))) - .rotationX(dir.toXRotBlockstate()) - .rotationY(dir.toYRotBlockstate()) + .rotationX(dir.primary.toXRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING_FULL, dir) + .condition(BlockRotationFreedom.TWO.property, dir) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_cable_connection"))) - .rotationX(dir.toXRotBlockstateInv()) - .rotationY(dir.toYRotBlockstateInv()) + .rotationX(dir.primary.toXRotBlockstateInv()) + .rotationY(dir.primary.toYRotBlockstateInv()) .addModel() - .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.ordinal], true) + .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.primary]!!, true) .end() } @@ -126,19 +127,19 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { } with(provider.getMultipartBuilder(MBlocks.STORAGE_IMPORTER)) { - for (dir in net.minecraft.core.Direction.values()) { + for (dir in BlockRotationFreedom.TWO.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_importer"))) - .rotationX(dir.toXRotBlockstate()) - .rotationY(dir.toYRotBlockstate()) + .rotationX(dir.primary.toXRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING_FULL, dir) + .condition(BlockRotationFreedom.TWO.property, dir) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_cable_connection"))) - .rotationX(dir.toXRotBlockstateInv()) - .rotationY(dir.toYRotBlockstateInv()) + .rotationX(dir.primary.toXRotBlockstateInv()) + .rotationY(dir.primary.toYRotBlockstateInv()) .addModel() - .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.ordinal], true) + .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.primary]!!, true) .end() } @@ -147,19 +148,19 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { } with(provider.getMultipartBuilder(MBlocks.STORAGE_EXPORTER)) { - for (dir in net.minecraft.core.Direction.values()) { + for (dir in BlockRotationFreedom.TWO.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_exporter"))) - .rotationX(dir.toXRotBlockstate()) - .rotationY(dir.toYRotBlockstate()) + .rotationX(dir.primary.toXRotBlockstate()) + .rotationY(dir.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING_FULL, dir) + .condition(BlockRotationFreedom.TWO.property, dir) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_cable_connection"))) - .rotationX(dir.toXRotBlockstateInv()) - .rotationY(dir.toYRotBlockstateInv()) + .rotationX(dir.primary.toXRotBlockstateInv()) + .rotationY(dir.primary.toYRotBlockstateInv()) .addModel() - .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.ordinal], true) + .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.primary]!!, true) .end() } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/ComplexBlockStates.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/ComplexBlockStates.kt index 352e4cf28..4deeb9760 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/ComplexBlockStates.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/ComplexBlockStates.kt @@ -7,45 +7,46 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.block.matter.PatternStorageBlock import ru.dbotthepony.mc.otm.block.storage.DriveViewerBlock +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.datagen.DataGen.MOD_ID import ru.dbotthepony.mc.otm.datagen.toYRotBlockstate import ru.dbotthepony.mc.otm.registry.MBlocks fun addComplexBlockStates(provider: MatteryBlockStateProvider) { with(provider.getMultipartBuilder(MBlocks.DRIVE_VIEWER)) { - for (facing in RotatableMatteryBlock.FACING.possibleValues) { + for (facing in BlockRotationFreedom.ONE.possibleValues) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/drive_viewer_drive_part"))) - .rotationY(facing.toYRotBlockstate()) + .rotationY(facing.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING, facing) + .condition(BlockRotationFreedom.ONE.property, facing) .condition(DriveViewerBlock.DRIVE_PRESENT, true) for (workState in WorkerState.SEMI_WORKER_STATE.possibleValues) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/drive_viewer_${workState.name.lowercase()}"))) - .rotationY(facing.toYRotBlockstate()) + .rotationY(facing.primary.toYRotBlockstate()) .addModel() .condition(WorkerState.SEMI_WORKER_STATE, workState) - .condition(RotatableMatteryBlock.FACING, facing) + .condition(BlockRotationFreedom.ONE.property, facing) } } } with(provider.getMultipartBuilder(MBlocks.PATTERN_STORAGE)) { - for (facing in RotatableMatteryBlock.FACING.possibleValues) { + for (facing in BlockRotationFreedom.ONE.possibleValues) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/pattern_storage"))) - .rotationY(facing.toYRotBlockstate()) + .rotationY(facing.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING, facing) + .condition(BlockRotationFreedom.ONE.property, facing) for (i in 0 .. 7) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/pattern/model$i"))) - .rotationY(facing.toYRotBlockstate()) + .rotationY(facing.primary.toYRotBlockstate()) .addModel() - .condition(RotatableMatteryBlock.FACING, facing) + .condition(BlockRotationFreedom.ONE.property, facing) .condition(PatternStorageBlock.PATTERN_STORAGE_DISKS_PROPS[i], true) } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/MatteryBlockStateProvider.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/MatteryBlockStateProvider.kt index ffd7cf4ed..e41abe868 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/MatteryBlockStateProvider.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/blocks/MatteryBlockStateProvider.kt @@ -8,6 +8,7 @@ import net.minecraftforge.client.model.generators.ConfiguredModel import net.minecraftforge.data.event.GatherDataEvent import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.datagen.DataGen import ru.dbotthepony.mc.otm.datagen.getValueNullable import ru.dbotthepony.mc.otm.datagen.toXRotBlockstate @@ -21,13 +22,13 @@ private val EMPTY: BlockStateTransform = { _, _, _ -> null } private fun initialTransform(it: BlockState, modelPath: String, builder: ConfiguredModel.Builder<*>): String { @Suppress("NAME_SHADOWING") var modelPath = modelPath - it.getValueNullable(RotatableMatteryBlock.FACING)?.let { - builder.rotationY(it.toYRotBlockstate()) + it.getValueNullable(BlockRotationFreedom.ONE.property)?.let { + builder.rotationY(it.primary.toYRotBlockstate()) } - it.getValueNullable(RotatableMatteryBlock.FACING_FULL)?.let { - builder.rotationY(it.toYRotBlockstate()) - builder.rotationX(it.toXRotBlockstate()) + it.getValueNullable(BlockRotationFreedom.TWO.property)?.let { + builder.rotationY(it.primary.toYRotBlockstate()) + builder.rotationX(it.primary.toXRotBlockstate()) } it.getValueNullable(WorkerState.WORKER_STATE)?.let { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt index d48726a54..ad9f67f30 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt @@ -4,6 +4,7 @@ package ru.dbotthepony.mc.otm.block import net.minecraft.core.BlockPos +import net.minecraft.core.Direction import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.EntityBlock @@ -19,6 +20,9 @@ import net.minecraft.world.phys.shapes.Shapes import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.entity.MatterCableBlockEntity import ru.dbotthepony.mc.otm.block.entity.StorageCableBlockEntity +import ru.dbotthepony.mc.otm.core.math.BlockRotation +import java.util.Collections +import java.util.EnumMap abstract class CableBlock(properties: Properties) : Block(properties) { init { @@ -52,14 +56,16 @@ abstract class CableBlock(properties: Properties) : Block(properties) { val CONNECTION_UP: BooleanProperty = BooleanProperty.create("connect_up") val CONNECTION_DOWN: BooleanProperty = BooleanProperty.create("connect_down") - val MAPPING_CONNECTION_PROP = listOf( - CONNECTION_DOWN, - CONNECTION_UP, - CONNECTION_NORTH, - CONNECTION_SOUTH, - CONNECTION_WEST, - CONNECTION_EAST - ) + val MAPPING_CONNECTION_PROP: Map = EnumMap(Direction::class.java) + .let { + it[Direction.DOWN] = CONNECTION_DOWN + it[Direction.UP] = CONNECTION_UP + it[Direction.NORTH] = CONNECTION_NORTH + it[Direction.SOUTH] = CONNECTION_SOUTH + it[Direction.WEST] = CONNECTION_WEST + it[Direction.EAST] = CONNECTION_EAST + Collections.unmodifiableMap(it) + } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/IDroppableContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/IDroppableContainer.kt new file mode 100644 index 000000000..e542b303f --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/IDroppableContainer.kt @@ -0,0 +1,21 @@ +package ru.dbotthepony.mc.otm.block + +import net.minecraft.core.BlockPos +import net.minecraft.world.Container +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.state.BlockState + +interface IDroppableContainer { + val droppableContainer: Container + + fun beforeDroppingItems( + oldBlockState: BlockState, + level: Level, + blockPos: BlockPos, + newBlockState: BlockState, + movedByPiston: Boolean + ) {} + + fun beforeDestroyedByPlayer(level: Level, blockPos: BlockPos, blockState: BlockState, player: Player) {} +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt index b8e854b1d..892393764 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/MatteryBlock.kt @@ -4,7 +4,6 @@ import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.core.particles.DustParticleOptions import net.minecraft.util.RandomSource -import net.minecraft.world.Container import net.minecraft.world.Containers import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionResult @@ -12,38 +11,20 @@ import net.minecraft.world.MenuProvider import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.player.Player import net.minecraft.world.item.ItemStack -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 import net.minecraft.world.level.material.Material import net.minecraft.world.level.material.MaterialColor import net.minecraft.world.phys.BlockHitResult import ru.dbotthepony.mc.otm.block.entity.IRedstoneControlProvider import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.math.component1 import ru.dbotthepony.mc.otm.core.math.component2 import ru.dbotthepony.mc.otm.core.math.component3 -import ru.dbotthepony.mc.otm.core.get - -interface IDroppableContainer { - val droppableContainer: Container - - fun beforeDroppingItems( - oldBlockState: BlockState, - level: Level, - blockPos: BlockPos, - newBlockState: BlockState, - movedByPiston: Boolean - ) {} - - fun beforeDestroyedByPlayer(level: Level, blockPos: BlockPos, blockState: BlockState, player: Player) {} -} abstract class MatteryBlock @JvmOverloads constructor( properties: Properties = DEFAULT_PROPERTIES @@ -94,7 +75,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(RotatableMatteryBlock.FACING).or { blockState.getOptionalValue(RotatableMatteryBlock.FACING_FULL) } + val state2 = blockState.getOptionalValue(BlockRotationFreedom.ONE.property) + .or { blockState.getOptionalValue(BlockRotationFreedom.TWO.property) } + .or { blockState.getOptionalValue(BlockRotationFreedom.THREE.property) } if (state2.isPresent) { val direction = state2.get() @@ -109,7 +92,7 @@ abstract class MatteryBlock @JvmOverloads constructor( yd += ny * 0.5 zd += nz * 0.5 - when (direction) { + when (direction.primary) { Direction.DOWN, Direction.UP -> { xd += random.nextDouble() - 0.5 zd += random.nextDouble() - 0.5 @@ -201,76 +184,3 @@ abstract class MatteryBlock @JvmOverloads constructor( } } -abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Properties = DEFAULT_PROPERTIES) : MatteryBlock(properties) { - init { - @Suppress("LeakingThis") - registerDefaultState(getStateDefinition().any().setValue(facingProperty, Direction.SOUTH)) - } - - override fun createBlockStateDefinition(builder: StateDefinition.Builder) { - builder.add(facingProperty) - } - - override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - if (hasFreeRotation) { - return defaultBlockState().setValue( - FACING_FULL, - if (faceToPlayer(context)) context.nearestLookingDirection.opposite else context.nearestLookingDirection - ) - } else { - return defaultBlockState().setValue( - FACING, - if (faceToPlayer(context)) context.horizontalDirection.opposite else context.horizontalDirection - ) - } - } - - @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 - } - - companion object { - /** - * Allows to instance [RotatableMatteryBlock] directly - */ - fun make(properties: Properties, hasFreeRotation: Boolean = false, faceToPlayer: Boolean = true): RotatableMatteryBlock { - if (hasFreeRotation) { // can't have one class for two cases - superclass (both in OTM and in Minecraft) are leaking "this" - return object : RotatableMatteryBlock(properties) { - override val hasFreeRotation get() = true // this is accessed from superclass constructor - - override fun faceToPlayer(context: BlockPlaceContext): Boolean { - return faceToPlayer - } - } - } else { - return object : RotatableMatteryBlock(properties) { - override val hasFreeRotation get() = false // this is accessed from superclass constructor - - override fun faceToPlayer(context: BlockPlaceContext): Boolean { - return faceToPlayer - } - } - } - } - - val FACING: EnumProperty = EnumProperty.create( - "facing", - Direction::class.java, - Direction.SOUTH, - Direction.WEST, - Direction.NORTH, - Direction.EAST - ) - - val FACING_FULL: EnumProperty = EnumProperty.create("facing", Direction::class.java) - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/RotatableMatteryBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/RotatableMatteryBlock.kt new file mode 100644 index 000000000..248123fbf --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/RotatableMatteryBlock.kt @@ -0,0 +1,51 @@ +package ru.dbotthepony.mc.otm.block + +import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Rotation +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.StateDefinition +import ru.dbotthepony.mc.otm.core.get +import ru.dbotthepony.mc.otm.core.math.BlockRotation +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom + +abstract class RotatableMatteryBlock @JvmOverloads constructor(properties: Properties = DEFAULT_PROPERTIES) : MatteryBlock(properties) { + init { + @Suppress("LeakingThis") + registerDefaultState(getStateDefinition().any().setValue(rotationProperty, BlockRotation.SOUTH)) + } + + override fun createBlockStateDefinition(builder: StateDefinition.Builder) { + builder.add(rotationProperty) + } + + override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { + if (rotationFreedom() == BlockRotationFreedom.ONE) { + return defaultBlockState().setValue( + rotationProperty, + BlockRotation.of(if (faceToPlayer(context)) context.horizontalDirection.opposite else context.horizontalDirection) + ) + } else { + return defaultBlockState().setValue( + rotationProperty, + BlockRotation.of(if (faceToPlayer(context)) context.nearestLookingDirection.opposite else context.nearestLookingDirection) + ) + } + } + + @Suppress("OVERRIDE_DEPRECATION") + override fun rotate(blockState: BlockState, rotation: Rotation): BlockState { + @Suppress("DEPRECATION") + return super.rotate(blockState, rotation).setValue(rotationProperty, blockState[rotationProperty].rotate(rotation)) + } + + val rotationProperty get() = rotationFreedom().property + + open fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.ONE + } + + open fun faceToPlayer(context: BlockPlaceContext): Boolean { + return true + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/EngineBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/EngineBlock.kt index d7a569582..c3103284c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/EngineBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/EngineBlock.kt @@ -9,14 +9,16 @@ import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.core.get +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.shapes.BlockShapes class EngineBlock : RotatableMatteryBlock(Properties.of(Material.METAL, DyeColor.ORANGE).explosionResistance(14f).destroyTime(2.5f).requiresCorrectToolForDrops()) { - override val hasFreeRotation: Boolean - get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } private val shapes = getShapeForEachState { - BlockShapes.ENGINE.rotateInv(it[FACING_FULL]).computeShape() + BlockShapes.ENGINE.rotateInv(it[rotationProperty].primary).computeShape() } override fun getShape( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/HoloSignBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/HoloSignBlock.kt index b47d15211..80c0b51db 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/HoloSignBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/HoloSignBlock.kt @@ -2,8 +2,6 @@ package ru.dbotthepony.mc.otm.block.decorative import net.minecraft.core.BlockPos import net.minecraft.world.level.BlockGetter -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.entity.BlockEntity import net.minecraft.world.level.block.state.BlockState @@ -12,18 +10,20 @@ import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity import ru.dbotthepony.mc.otm.core.get +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.shapes.BlockShapes class HoloSignBlock : RotatableMatteryBlock(), EntityBlock { - override val hasFreeRotation: Boolean - get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity { return HoloSignBlockEntity(p_153215_, p_153216_) } private val shapes = getShapeForEachState { - BlockShapes.HOLO_SIGN.rotateInv(it[FACING_FULL]).computeShape() + BlockShapes.HOLO_SIGN.rotateInv(it[rotationProperty].primary).computeShape() } override fun getShape( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/LaboratoryLamp.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/LaboratoryLamp.kt index bd83db1d6..42afb0f0d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/LaboratoryLamp.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/decorative/LaboratoryLamp.kt @@ -21,19 +21,20 @@ import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.Shapes import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.ServerConfig -import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.core.TranslatableComponent 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.times -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 + class LaboratoryLampLight : Block(Properties.of(Material.AIR).strength(-1.0F, 3600000.8F).noLootTable().noOcclusion().lightLevel { 15 }) { override fun createBlockStateDefinition(builder: StateDefinition.Builder) { super.createBlockStateDefinition(builder) - builder.add(RotatableMatteryBlock.FACING_FULL) + builder.add(FACING_FULL) } override fun hasDynamicShape(): Boolean { @@ -53,7 +54,7 @@ class LaboratoryLampLight : Block(Properties.of(Material.AIR).strength(-1.0F, 36 @Suppress("OVERRIDE_DEPRECATION") override fun rotate(blockState: BlockState, rotation: Rotation): BlockState { @Suppress("DEPRECATION") - return super.rotate(blockState, rotation).setValue(RotatableMatteryBlock.FACING_FULL, rotation.rotate(blockState[RotatableMatteryBlock.FACING_FULL])) + return super.rotate(blockState, rotation).setValue(FACING_FULL, blockState[FACING_FULL].rotate(rotation)) } @Suppress("OVERRIDE_DEPRECATION") @@ -80,7 +81,7 @@ class LaboratoryLampLight : Block(Properties.of(Material.AIR).strength(-1.0F, 36 if (level.getBlockState(pos) != state) return@once - val facing = state[RotatableMatteryBlock.FACING_FULL] + val facing = state[FACING_FULL] var hit = false @@ -111,14 +112,14 @@ class LaboratoryLamp(val invertRedstone: Boolean) : Block(Properties.of(Material override fun createBlockStateDefinition(builder: StateDefinition.Builder) { super.createBlockStateDefinition(builder) - builder.add(RotatableMatteryBlock.FACING_FULL) + builder.add(FACING_FULL) builder.add(BlockStateProperties.LIT) } override fun getStateForPlacement(context: BlockPlaceContext): BlockState { return super.getStateForPlacement(context)!! .setValue(BlockStateProperties.LIT, !invertRedstone) - .setValue(RotatableMatteryBlock.FACING_FULL, -context.nearestLookingDirection) + .setValue(FACING_FULL, -context.nearestLookingDirection.blockRotation) } override fun appendHoverText( @@ -147,7 +148,7 @@ class LaboratoryLamp(val invertRedstone: Boolean) : Block(Properties.of(Material @Suppress("OVERRIDE_DEPRECATION") override fun rotate(blockState: BlockState, rotation: Rotation): BlockState { @Suppress("DEPRECATION") - return super.rotate(blockState, rotation).setValue(RotatableMatteryBlock.FACING_FULL, rotation.rotate(blockState[RotatableMatteryBlock.FACING_FULL])) + return super.rotate(blockState, rotation).setValue(FACING_FULL, blockState[FACING_FULL].rotate(rotation)) } fun doTick( @@ -172,7 +173,7 @@ class LaboratoryLamp(val invertRedstone: Boolean) : Block(Properties.of(Material level.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.LIT, shouldBeLit)) } - val facing = state[RotatableMatteryBlock.FACING_FULL] + val facing = state[FACING_FULL] for (i in 1 .. ServerConfig.LABORATORY_LAMP_LIGHT_LENGTH) { val target = pos + facing * i @@ -185,7 +186,7 @@ class LaboratoryLamp(val invertRedstone: Boolean) : Block(Properties.of(Material if (shouldBeLit) { if (targetState.isAir && targetState.block != MBlocks.LABORATORY_LAMP_LIGHT) { level.setBlockAndUpdate(target, MBlocks.LABORATORY_LAMP_LIGHT.defaultBlockState().setValue( - RotatableMatteryBlock.FACING_FULL, -facing)) + FACING_FULL, -facing)) } } else { if (targetState.block == MBlocks.LABORATORY_LAMP_LIGHT) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/Cables.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/Cables.kt index f086c6229..7b091594c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/Cables.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/Cables.kt @@ -54,14 +54,14 @@ class MatterCableBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } override fun onNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], true) + val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, true) if (newState !== blockState && SERVER_IS_LIVE) level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) } override fun onUnNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], false) + val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, false) if (newState !== blockState && SERVER_IS_LIVE) level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) @@ -110,14 +110,14 @@ class StorageCableBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } override fun onNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], true) + val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, true) if (newState !== blockState && SERVER_IS_LIVE) level!!.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) } override fun onUnNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], false) + val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, false) if (newState !== blockState && SERVER_IS_LIVE) level!!.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt index d85cdd401..4ac58d7b3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageBusBlockEntity.kt @@ -27,6 +27,8 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.container.ItemFilter import ru.dbotthepony.mc.otm.core.* +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom +import ru.dbotthepony.mc.otm.core.math.getCapability import ru.dbotthepony.mc.otm.core.math.isPositive import ru.dbotthepony.mc.otm.core.math.isZero import ru.dbotthepony.mc.otm.core.math.plus @@ -79,14 +81,14 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter val cell: BasicStorageGraphNode = object : BasicStorageGraphNode(energy), GraphNodeListener { override fun onNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = this@StorageBusBlockEntity.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], true) + val newState = this@StorageBusBlockEntity.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, true) if (newState !== this@StorageBusBlockEntity.blockState && SERVER_IS_LIVE) level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) } override fun onUnNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = this@StorageBusBlockEntity.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], false) + val newState = this@StorageBusBlockEntity.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, false) if (newState !== this@StorageBusBlockEntity.blockState && SERVER_IS_LIVE) level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) @@ -111,7 +113,7 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter private var valid = true override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - return if (valid && cap === MatteryCapability.STORAGE_NODE && side != blockState.getValue(RotatableMatteryBlock.FACING_FULL)) { + return if (valid && cap === MatteryCapability.STORAGE_NODE && side != blockState.getValue(BlockRotationFreedom.TWO.property).primary) { cell.get().cast() } else super.getCapability(cap, side) } @@ -157,8 +159,8 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter if (isRemoved) return - val front = blockPos + blockState.getValue(RotatableMatteryBlock.FACING_FULL) - val storage = level?.getBlockEntity(front)?.getCapability(ForgeCapabilities.ITEM_HANDLER, -blockState.getValue(RotatableMatteryBlock.FACING_FULL))?.let { if (it.isPresent) it else null } + 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 } if (neighbour != storage) { neighbour = storage diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt index 80c059349..c06fda606 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt @@ -26,7 +26,9 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact import ru.dbotthepony.mc.otm.container.ItemFilter import ru.dbotthepony.mc.otm.core.* +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.math.Decimal +import ru.dbotthepony.mc.otm.core.math.rotationTwo import ru.dbotthepony.mc.otm.core.math.toIntSafe import ru.dbotthepony.mc.otm.core.math.unaryMinus import ru.dbotthepony.mc.otm.core.nbt.map @@ -56,14 +58,14 @@ abstract class AbstractStorageImportExport( val cell: BasicStorageGraphNode = object : BasicStorageGraphNode(energy), GraphNodeListener { override fun onNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], true) + val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, true) if (newState !== this@AbstractStorageImportExport.blockState && SERVER_IS_LIVE) level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) } override fun onUnNeighbour(node: Graph6Node<*>, direction: Direction) { - val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction.ordinal], false) + val newState = this@AbstractStorageImportExport.blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[direction]!!, false) if (newState !== this@AbstractStorageImportExport.blockState && SERVER_IS_LIVE) level?.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) @@ -73,7 +75,7 @@ abstract class AbstractStorageImportExport( private var valid = true override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - return if (valid && cap === MatteryCapability.STORAGE_NODE && side != blockState.getValue(RotatableMatteryBlock.FACING_FULL)) { + return if (valid && cap === MatteryCapability.STORAGE_NODE && side != blockState.getValue(BlockRotationFreedom.TWO.property).primary) { cell.get().cast() } else super.getCapability(cap, side) } @@ -112,7 +114,7 @@ abstract class AbstractStorageImportExport( protected val target by lazy { object : BESubscribeList(this@AbstractStorageImportExport, targetCapability) { override fun test(t: Direction): Boolean { - return t == -this@AbstractStorageImportExport.blockState.getValue(RotatableMatteryBlock.FACING_FULL) + return t == -this@AbstractStorageImportExport.blockState.getValue(BlockRotationFreedom.TWO.property).primary } } } @@ -177,7 +179,7 @@ class StorageImporterBlockEntity(blockPos: BlockPos, blockState: BlockState) } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - if (valid && cap == ForgeCapabilities.ITEM_HANDLER && side == blockState.getValue(RotatableMatteryBlock.FACING_FULL)) { + if (valid && cap == ForgeCapabilities.ITEM_HANDLER && side == blockState.rotationTwo.primary) { return resolverItemHandler.cast() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt index 8020ecfa6..a04973c44 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt @@ -28,6 +28,8 @@ import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainerHooks import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.core.math.Decimal +import ru.dbotthepony.mc.otm.core.math.facingOne +import ru.dbotthepony.mc.otm.core.math.rotationOne import ru.dbotthepony.mc.otm.core.math.unaryMinus import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.util.BESubscribeList @@ -271,7 +273,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte if (cap == MatteryCapability.ENERGY || cap == ForgeCapabilities.ENERGY) { if (side == null) return resolverEnergy.cast() - if (side == blockState.getValue(RotatableMatteryBlock.FACING)) + if (side == blockState.facingOne) return resolverEnergyExtractor.cast() else return resolverEnergyReceiver.cast() @@ -280,7 +282,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte if (cap == MatteryCapability.MEKANISM_ENERGY) { if (side == null) return mekanismResolverEnergy.cast() - if (side == blockState.getValue(RotatableMatteryBlock.FACING)) + if (side == blockState.facingOne) return mekanismResolverEnergyExtractor.cast() else return mekanismResolverEnergyReceiver.cast() @@ -296,11 +298,11 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte private val consumers = object : BESubscribeList(this@BatteryBankBlockEntity, ForgeCapabilities.ENERGY) { override fun test(t: Direction): Boolean { - return -blockState.getValue(RotatableMatteryBlock.FACING) == t + return -blockState.facingOne == t } } - fun checkSurroundings() = consumers.update((-blockState.getValue(RotatableMatteryBlock.FACING))::equals) + fun checkSurroundings() = consumers.update((-blockState.facingOne)::equals) fun tick() { if (redstoneControl.isBlockedByRedstone) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt index 40c368eb6..73e6e6cc1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt @@ -34,6 +34,7 @@ import ru.dbotthepony.mc.otm.core.util.WriteOnce import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.defineDecimal +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.util.BESubscribeList @@ -62,7 +63,7 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryBl } override fun getCapability(cap: Capability, side: Direction?): LazyOptional { - if (valid && (cap == MatteryCapability.ENERGY || cap == ForgeCapabilities.ENERGY) && side !== blockState.getValue(RotatableMatteryBlock.FACING)) + if (valid && (cap == MatteryCapability.ENERGY || cap == ForgeCapabilities.ENERGY) && side !== blockState.facingOne) return energy.resolver.cast() if (valid && cap == ForgeCapabilities.ITEM_HANDLER) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/GravitationStabilizerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/GravitationStabilizerBlockEntity.kt index 7fb8defd9..0ae35a55c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/GravitationStabilizerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/GravitationStabilizerBlockEntity.kt @@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity 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.math.plus import ru.dbotthepony.mc.otm.core.math.times import ru.dbotthepony.mc.otm.registry.MBlockEntities @@ -32,7 +33,7 @@ class GravitationStabilizerBlockEntity(p_155229_: BlockPos, p_155230_: BlockStat fun tick(level: Level) { var findBlackHole: BlackHoleBlockEntity? = null - val dir = blockState.getValue(RotatableMatteryBlock.FACING_FULL).normal + val dir = blockState.facingTwo.normal for (i in 2 .. RANGE) { val pos = blockPos + dir * i diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt index d81a21840..dcf6e2cd6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterBottlerBlock.kt @@ -18,6 +18,7 @@ import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -56,7 +57,7 @@ class MatterBottlerBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterCapacitorBankBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterCapacitorBankBlock.kt index 853fa5849..323b3f199 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterCapacitorBankBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterCapacitorBankBlock.kt @@ -14,6 +14,7 @@ import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.tech.BatteryBankBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.shapes.BlockShapes class MatterCapacitorBankBlock : RotatableMatteryBlock(), EntityBlock { @@ -41,7 +42,7 @@ class MatterCapacitorBankBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterDecomposerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterDecomposerBlock.kt index faf3065c4..3adfc867f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterDecomposerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterDecomposerBlock.kt @@ -18,6 +18,7 @@ import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -50,7 +51,7 @@ class MatterDecomposerBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { @@ -65,4 +66,4 @@ class MatterDecomposerBlock : RotatableMatteryBlock(), EntityBlock { BlockShapes.MATTER_DECOMPOSER.rotate(Direction.EAST).computeShape() ) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterPanelBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterPanelBlock.kt index d23b5bcd5..4a8076269 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterPanelBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterPanelBlock.kt @@ -17,6 +17,9 @@ import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.state.properties.EnumProperty import ru.dbotthepony.mc.otm.block.MatteryBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock +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 { @@ -26,10 +29,10 @@ class MatterPanelBlock : RotatableMatteryBlock(), EntityBlock { private val shapes: ImmutableMap init { - registerDefaultState(getStateDefinition().any().setValue(FACING_FULL, Direction.SOUTH)) + registerDefaultState(getStateDefinition().any().setValue(BlockRotationFreedom.TWO.property, BlockRotation.SOUTH)) shapes = getShapeForEachState { - when (it.getValue(FACING_FULL)) { + when (it.rotationTwo.primary) { Direction.NORTH -> Shapes.box( 0.0, 0.0, @@ -91,10 +94,11 @@ class MatterPanelBlock : RotatableMatteryBlock(), EntityBlock { return shapes[p_60555_]!! } - override val hasFreeRotation: Boolean - get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - return defaultBlockState().setValue(FACING_FULL, context.clickedFace) + return defaultBlockState().setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(context.clickedFace)) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterRecyclerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterRecyclerBlock.kt index d8c99395a..34d471188 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterRecyclerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterRecyclerBlock.kt @@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -46,7 +47,7 @@ class MatterRecyclerBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterReplicatorBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterReplicatorBlock.kt index 1d15fbbc6..c90943d5d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterReplicatorBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterReplicatorBlock.kt @@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.matter.MatterReplicatorBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -46,7 +47,7 @@ class MatterReplicatorBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { @@ -65,4 +66,4 @@ class MatterReplicatorBlock : RotatableMatteryBlock(), EntityBlock { ) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterScannerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterScannerBlock.kt index 51b3a72c3..a7efee532 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterScannerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/MatterScannerBlock.kt @@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.matter.MatterScannerBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -46,7 +47,7 @@ class MatterScannerBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { @@ -65,4 +66,4 @@ class MatterScannerBlock : RotatableMatteryBlock(), EntityBlock { ) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt index 5bdcb39ea..30813617f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/matter/PatternStorageBlock.kt @@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.matter.PatternStorageBlockEntity +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.shapes.BlockShapes class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock { @@ -62,7 +63,7 @@ class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { @@ -92,4 +93,4 @@ class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock { ) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveRackBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveRackBlock.kt index df085a37d..f88f67b5e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveRackBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveRackBlock.kt @@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.DriveRackBlockEntity import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -54,7 +55,7 @@ class DriveRackBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveViewerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveViewerBlock.kt index 1de05d726..45fe6a2bd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveViewerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/DriveViewerBlock.kt @@ -23,6 +23,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.DriveViewerBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -69,7 +70,7 @@ class DriveViewerBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/ItemMonitorBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/ItemMonitorBlock.kt index f53497785..95dfe2786 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/ItemMonitorBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/ItemMonitorBlock.kt @@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorBlockEntity import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -54,7 +55,7 @@ class ItemMonitorBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageBusBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageBusBlock.kt index d0f5d2867..544f5d006 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageBusBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageBusBlock.kt @@ -24,13 +24,18 @@ import ru.dbotthepony.mc.otm.block.StorageCableBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.StorageBusBlockEntity import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage +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 StorageBusBlock : RotatableMatteryBlock(), EntityBlock { - override val hasFreeRotation: Boolean get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } init { registerDefaultState(defaultBlockState() @@ -47,7 +52,7 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock { } override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) + return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(-context.clickedFace)) } override fun appendHoverText( @@ -93,7 +98,7 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock { finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) } - finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_BUS.rotateInv(it.getValue(FACING_FULL)).computeShape(), BooleanOp.OR) + finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_BUS.rotateInv(it.facingTwo).computeShape(), BooleanOp.OR) return@getShapeForEachState finalShape } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageInterfaces.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageInterfaces.kt index 1ae920297..0b8fb51f3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageInterfaces.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StorageInterfaces.kt @@ -25,13 +25,18 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.StorageExporterBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.StorageImporterBlockEntity import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage +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 val hasFreeRotation: Boolean get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity { return StorageImporterBlockEntity(p_153215_, p_153216_) @@ -72,7 +77,7 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock { } override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) + return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(-context.clickedFace)) } override fun appendHoverText( @@ -94,7 +99,7 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock { finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) } - finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_IMPORTER.rotateInv(it.getValue(FACING_FULL)).computeShape(), BooleanOp.OR) + finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_IMPORTER.rotateInv(it.facingTwo).computeShape(), BooleanOp.OR) return@getShapeForEachState finalShape } @@ -133,7 +138,9 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock { } class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock { - override val hasFreeRotation: Boolean get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity { return StorageExporterBlockEntity(p_153215_, p_153216_) @@ -185,7 +192,7 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock { } override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) + return super.getStateForPlacement(context)?.setValue(BlockRotationFreedom.TWO.property, BlockRotation.of(-context.clickedFace)) } private val shapes = getShapeForEachState { @@ -196,7 +203,7 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock { finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) } - finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_EXPORTER.rotateInv(it.getValue(FACING_FULL)).computeShape(), BooleanOp.OR) + finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_EXPORTER.rotateInv(it.facingTwo).computeShape(), BooleanOp.OR) return@getShapeForEachState finalShape } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StoragePowerSupplierBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StoragePowerSupplierBlock.kt index 5d8a23712..e4d59f655 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StoragePowerSupplierBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/storage/StoragePowerSupplierBlock.kt @@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -54,7 +55,7 @@ class StoragePowerSupplierBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/BatteryBankBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/BatteryBankBlock.kt index 7e2fb9fa5..79496afe2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/BatteryBankBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/BatteryBankBlock.kt @@ -19,6 +19,7 @@ import net.minecraft.world.level.block.Block import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.oncePre import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -61,7 +62,7 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } override fun faceToPlayer(context: BlockPlaceContext): Boolean { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/ChemicalGeneratorBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/ChemicalGeneratorBlock.kt index f46063df1..473d0c605 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/ChemicalGeneratorBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/ChemicalGeneratorBlock.kt @@ -27,6 +27,7 @@ import ru.dbotthepony.mc.otm.capability.energy.GeneratorEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.core.TranslatableComponent +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.oncePre import ru.dbotthepony.mc.otm.registry.MBlockEntities @@ -100,7 +101,7 @@ class ChemicalGeneratorBlock : RotatableMatteryBlock(), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/EnergyServoBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/EnergyServoBlock.kt index 3fc8b7c37..ecb5e7ecc 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/EnergyServoBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/EnergyServoBlock.kt @@ -15,6 +15,7 @@ import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -41,7 +42,7 @@ class EnergyServoBlock : RotatableMatteryBlock(Properties.of(Material.METAL, Mat p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/GravitationStabilizerBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/GravitationStabilizerBlock.kt index 146af6a17..f7a82cbd6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/GravitationStabilizerBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/GravitationStabilizerBlock.kt @@ -26,6 +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.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 @@ -52,7 +54,9 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock { return BlockEntityTicker { level, _, _, tile -> if (tile is GravitationStabilizerBlockEntity) tile.tick(level) } } - override val hasFreeRotation: Boolean get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } override fun createBlockStateDefinition(builder: StateDefinition.Builder) { super.createBlockStateDefinition(builder) @@ -64,7 +68,7 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock { val blockPos = context.clickedPos val level = context.level - for (face in FACING_FULL.possibleValues) { + for (face in BlockRotationFreedom.TWO.possibleValues) { val dir = face.normal for (i in 1 ..GravitationStabilizerBlockEntity.RANGE) { @@ -74,14 +78,14 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock { if (!getState.isAir) { if (chunk.getBlockEntity(pos) is BlackHoleBlockEntity) { - state = state.setValue(FACING_FULL, face) + state = state.setValue(BlockRotationFreedom.TWO.property, face) break } } } } - val bbPos = blockPos + state.getValue(FACING_FULL).normal + val bbPos = blockPos + state.getValue(BlockRotationFreedom.TWO.property).normal if (!context.level.isInWorldBounds(bbPos)) return null if (!level.getBlockState(bbPos).canBeReplaced(context)) return null @@ -99,9 +103,9 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock { super.setPlacedBy(level, blockPos, blockState, entity, itemStack) if (!level.isClientSide) { - val bbPos = blockPos + blockState.getValue(FACING_FULL).normal + val bbPos = blockPos + blockState.getValue(BlockRotationFreedom.TWO.property).normal val newState = MBlocks.GRAVITATION_STABILIZER_LENS.defaultBlockState() - .setValue(FACING_FULL, blockState.getValue(FACING_FULL)) + .setValue(BlockRotationFreedom.TWO.property, blockState.getValue(BlockRotationFreedom.TWO.property)) level.setBlock(bbPos, newState, UPDATE_ALL) } @@ -137,7 +141,7 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING_FULL).ordinal] + return SHAPES[p_60555_.facingTwo.ordinal] } companion object { @@ -155,13 +159,15 @@ class BlockGravitationStabilizer : RotatableMatteryBlock(props), EntityBlock { } fun getBoundingBlockPos(blockState: BlockState, blockPos: BlockPos): BlockPos { - return blockPos + blockState.getValue(FACING_FULL).normal + return blockPos + blockState.getValue(BlockRotationFreedom.TWO.property).normal } } } class BlockGravitationStabilizerLens : RotatableMatteryBlock(props) { - override val hasFreeRotation: Boolean get() = true + override fun rotationFreedom(): BlockRotationFreedom { + return BlockRotationFreedom.TWO + } override fun createBlockStateDefinition(builder: StateDefinition.Builder) { super.createBlockStateDefinition(builder) @@ -198,7 +204,7 @@ class BlockGravitationStabilizerLens : RotatableMatteryBlock(props) { p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING_FULL).ordinal] + return SHAPES[p_60555_.facingTwo.ordinal] } companion object { @@ -207,7 +213,7 @@ class BlockGravitationStabilizerLens : RotatableMatteryBlock(props) { } fun getBoundingBlockPos(blockState: BlockState, blockPos: BlockPos): BlockPos { - return blockPos + blockState.getValue(FACING_FULL).opposite.normal + return blockPos + blockState.getValue(BlockRotationFreedom.TWO.property).opposite.normal } private val SHAPES = arrayOf( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PhantomAttractorBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PhantomAttractorBlock.kt index deada4a16..b50ce41d4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PhantomAttractorBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PhantomAttractorBlock.kt @@ -27,6 +27,7 @@ import net.minecraft.world.phys.shapes.VoxelShape import net.minecraftforge.common.ForgeHooks import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock 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.once @@ -92,7 +93,7 @@ class PhantomAttractorBlock : RotatableMatteryBlock(Properties.of(Material.METAL DoubleBlockHalf.LOWER -> BlockShapes.PHANTOM_ATTRACTOR_BOTTOM } - shape.rotate(it[FACING]!!).computeShape() + shape.rotate(it.facingOne).computeShape() } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt index ef0b6e008..4c788677a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt @@ -20,6 +20,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -60,7 +61,7 @@ class PlatePressBlock(properties: Properties = DEFAULT_PROPERTIES) : RotatableMa p_60557_: BlockPos, p_60558_: CollisionContext ): VoxelShape { - return SHAPES[p_60555_.getValue(FACING).ordinal] + return SHAPES[p_60555_.facingOne.ordinal] } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/BankRenderer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/BankRenderer.kt index 08a96b8bb..2d67ee17a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/BankRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/BankRenderer.kt @@ -14,6 +14,7 @@ import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel import ru.dbotthepony.mc.otm.core.get +import ru.dbotthepony.mc.otm.core.math.facingOne import ru.dbotthepony.mc.otm.core.math.rotateY import kotlin.math.PI @@ -37,7 +38,7 @@ abstract class BankRenderer(private val context: BlockEn stack.pushPose() - val facing = blockEntity.blockState[RotatableMatteryBlock.FACING] + val facing = blockEntity.blockState.facingOne val rotateFacing = facing == Direction.NORTH || facing == Direction.SOUTH if (rotateFacing) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/GravitationStabilizerRenderer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/GravitationStabilizerRenderer.kt index c0f0819c9..5e240253b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/GravitationStabilizerRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/GravitationStabilizerRenderer.kt @@ -26,6 +26,7 @@ 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 @@ -47,7 +48,7 @@ class GravitationStabilizerRenderer(private val context: BlockEntityRendererProv var len = 64.0 var lenI = 64 - val normal = tile.blockState.getValue(RotatableMatteryBlock.FACING_FULL).normal + val normal = tile.blockState.facingTwo.normal val level = tile.level var bhTile: BlackHoleBlockEntity? = null @@ -68,7 +69,7 @@ class GravitationStabilizerRenderer(private val context: BlockEntityRendererProv poseStack.pushPose() poseStack.translate(0.5, 0.5, 0.5) - val facing: Direction = tile.blockState.getValue(RotatableMatteryBlock.FACING_FULL) + val facing = tile.blockState.facingTwo val rotateZ: Double val rotateY: Double diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt index a79e423fd..1c89e54de 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/render/blockentity/HoloSignRenderer.kt @@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.client.render.TextAlign import ru.dbotthepony.mc.otm.client.render.drawAligned import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.math.RGBAColor +import ru.dbotthepony.mc.otm.core.math.facingTwo import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer { @@ -28,7 +29,7 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) return poseStack.pushPose() - poseStack.rotateWithBlockFacing(tile.blockState[RotatableMatteryBlock.FACING_FULL]) + poseStack.rotateWithBlockFacing(tile.blockState.facingTwo) poseStack.translate(0.5f, 0.5f, 0.6f) poseStack.scale(0.01f, 0.01f, 0.01f) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotation.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotation.kt new file mode 100644 index 000000000..b67604aa2 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotation.kt @@ -0,0 +1,137 @@ +package ru.dbotthepony.mc.otm.core.math + +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.core.Vec3i +import net.minecraft.util.StringRepresentable +import net.minecraft.world.level.block.Rotation +import net.minecraftforge.common.capabilities.Capability +import net.minecraftforge.common.capabilities.ICapabilityProvider +import net.minecraftforge.common.util.LazyOptional + +internal inline val Direction.blockRotation + get() = BlockRotation.of(this) + +fun ICapabilityProvider.getCapability(capability: Capability, side: BlockRotation?): LazyOptional { + return getCapability(capability, side?.primary) +} + +operator fun Vec3i.plus(other: BlockRotation): Vec3i { + return this + other.normal +} + +operator fun BlockPos.plus(other: BlockRotation): BlockPos { + return this + other.normal +} + +enum class BlockRotation(val primary: Direction, val secondary: Direction?) : StringRepresentable { + DOWN(Direction.DOWN, null), + UP(Direction.UP, null), + NORTH(Direction.NORTH, null), + SOUTH(Direction.SOUTH, null), + WEST(Direction.WEST, null), + EAST(Direction.EAST, null), + + DOWN_NORTH(Direction.DOWN, Direction.NORTH), + DOWN_SOUTH(Direction.DOWN, Direction.SOUTH), + DOWN_WEST(Direction.DOWN, Direction.WEST), + DOWN_EAST(Direction.DOWN, Direction.EAST), + + UP_NORTH(Direction.UP, Direction.NORTH), + UP_SOUTH(Direction.UP, Direction.SOUTH), + UP_WEST(Direction.UP, Direction.WEST), + UP_EAST(Direction.UP, Direction.EAST); + + val lowercaseName = name.lowercase() + + override fun getSerializedName(): String { + return lowercaseName + } + + fun rotate(by: Rotation): BlockRotation { + return of(by.rotate(primary), secondary) + } + + operator fun times(other: Int): Vec3i { + return normal * other + } + + operator fun plus(other: Vec3i): Vec3i { + return normal + other + } + + operator fun plus(other: Direction): Vec3i { + return normal + other + } + + operator fun plus(other: BlockRotation): Vec3i { + return normal + other.normal + } + + operator fun unaryMinus() = opposite + + // more performant + val opposite by lazy { of(primary.opposite, secondary?.opposite) } + val normal: Vec3i get() = primary.normal + + companion object { + @JvmStatic + fun of(direction: Direction): BlockRotation { + return when (direction) { + Direction.DOWN -> DOWN + Direction.UP -> UP + Direction.NORTH -> NORTH + Direction.SOUTH -> SOUTH + Direction.WEST -> WEST + Direction.EAST -> EAST + } + } + + @JvmStatic + fun of(primary: Direction, secondary: Direction?): BlockRotation { + return when (primary) { + Direction.NORTH -> { + require(secondary == null) { "Impossible direction: $primary - $secondary" } + NORTH + } + + Direction.SOUTH -> { + require(secondary == null) { "Impossible direction: $primary - $secondary" } + SOUTH + } + + Direction.WEST -> { + require(secondary == null) { "Impossible direction: $primary - $secondary" } + WEST + } + + Direction.EAST -> { + require(secondary == null) { "Impossible direction: $primary - $secondary" } + EAST + } + + Direction.UP -> { + when (secondary) { + null -> UP + Direction.NORTH -> UP_NORTH + Direction.SOUTH -> UP_SOUTH + Direction.WEST -> UP_WEST + Direction.EAST -> UP_EAST + else -> throw IllegalArgumentException("Impossible direction: $primary - $secondary") + } + } + + Direction.DOWN -> { + when (secondary) { + null -> DOWN + Direction.NORTH -> DOWN_NORTH + Direction.SOUTH -> DOWN_SOUTH + Direction.WEST -> DOWN_WEST + Direction.EAST -> DOWN_EAST + else -> throw IllegalArgumentException("Impossible direction: $primary - $secondary") + } + } + } + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotationFreedom.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotationFreedom.kt new file mode 100644 index 000000000..fc0dd01fb --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/BlockRotationFreedom.kt @@ -0,0 +1,50 @@ +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 + +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].primary +internal inline val BlockState.facingTwo: Direction get() = this[BlockRotationFreedom.TWO.property].primary +internal inline val BlockState.facingThree: Direction get() = this[BlockRotationFreedom.THREE.property].primary + +enum class BlockRotationFreedom(vararg values: BlockRotation) { + ONE( + BlockRotation.NORTH, + BlockRotation.SOUTH, + BlockRotation.WEST, + BlockRotation.EAST, + ), + TWO( + BlockRotation.DOWN, + BlockRotation.UP, + BlockRotation.NORTH, + BlockRotation.SOUTH, + BlockRotation.WEST, + BlockRotation.EAST, + ), + THREE( + BlockRotation.DOWN, + BlockRotation.UP, + BlockRotation.NORTH, + BlockRotation.SOUTH, + BlockRotation.WEST, + BlockRotation.EAST, + BlockRotation.DOWN_NORTH, + BlockRotation.DOWN_SOUTH, + BlockRotation.DOWN_WEST, + BlockRotation.DOWN_EAST, + BlockRotation.UP_NORTH, + BlockRotation.UP_SOUTH, + BlockRotation.UP_WEST, + BlockRotation.UP_EAST, + ); + + val possibleValues: Collection get() = property.possibleValues + val property: EnumProperty = EnumProperty.create("facing", BlockRotation::class.java, *values) +}