diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt index f6fd731ef..e02056fcb 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/DataGen.kt @@ -20,6 +20,7 @@ import net.minecraftforge.data.event.GatherDataEvent import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.android.AndroidResearchDataProvider import ru.dbotthepony.mc.otm.block.* +import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateNorth import ru.dbotthepony.mc.otm.core.util.WriteOnce import ru.dbotthepony.mc.otm.datagen.blocks.BatteryBankProvider import ru.dbotthepony.mc.otm.datagen.blocks.MatterBankProvider @@ -272,7 +273,7 @@ object DataGen { } } ).rotationY( - facing.toYRotBlockstate() - 90 + + facing.yRotationBlockstateNorth() - 90 + (if (open) when (hinge) { DoorHingeSide.LEFT -> 90 DoorHingeSide.RIGHT -> -90 @@ -322,7 +323,7 @@ object DataGen { Half.BOTTOM -> trapdoorBottom } ).rotationY( - facing.toYRotBlockstate() + facing.yRotationBlockstateNorth() ).addModel() .condition(TrapDoorBlock.FACING, facing) .condition(TrapDoorBlock.OPEN, open) 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 30a5aee55..d1e531f91 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,8 @@ import net.minecraftforge.client.model.generators.ModelFile import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom +import ru.dbotthepony.mc.otm.core.math.xRotationBlockstateNorth +import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateNorth 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 +218,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.toXRotBlockstate()) - .rotationY(it[BlockRotationFreedom.TWO.property].front.toYRotBlockstate()) + .rotationX(it[BlockRotationFreedom.TWO.property].front.xRotationBlockstateNorth()) + .rotationY(it[BlockRotationFreedom.TWO.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.toXRotBlockstate()) - .rotationY(it[BlockRotationFreedom.TWO.property].front.toYRotBlockstate()) + .rotationX(it[BlockRotationFreedom.TWO.property].front.xRotationBlockstateNorth()) + .rotationY(it[BlockRotationFreedom.TWO.property].front.yRotationBlockstateNorth()) .build() } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt deleted file mode 100644 index d4f102c3f..000000000 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/Ext.kt +++ /dev/null @@ -1,54 +0,0 @@ -package ru.dbotthepony.mc.otm.datagen - -import net.minecraft.core.Direction -import net.minecraft.world.level.block.state.BlockState -import net.minecraft.world.level.block.state.properties.Property - -fun Direction.toYRotBlockstate(): Int { - return when (this) { - Direction.DOWN, Direction.UP, Direction.NORTH -> 0 - Direction.SOUTH -> 180 - Direction.WEST -> -90 - Direction.EAST -> 90 - } -} - -fun Direction.toYRotBlockstateInv(): Int { - return when (this) { - Direction.DOWN, Direction.UP -> 0 - Direction.NORTH -> 180 - Direction.SOUTH -> 0 - Direction.WEST -> 90 - Direction.EAST -> -90 - } -} - -fun Direction.toXRotBlockstate(): Int { - return when (this) { - Direction.DOWN -> 90 - Direction.UP -> -90 - Direction.NORTH -> 0 - Direction.SOUTH -> 0 - Direction.WEST -> 0 - Direction.EAST -> 0 - } -} - -fun Direction.toXRotBlockstateInv(): Int { - return when (this) { - Direction.DOWN -> -90 - Direction.UP -> 90 - Direction.NORTH -> 0 - Direction.SOUTH -> 0 - Direction.WEST -> 0 - Direction.EAST -> 0 - } -} - -fun > BlockState.getValueNullable(prop: Property): T? { - if (hasProperty(prop)) { - return getValue(prop) - } - - return null -} 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 5e145d39b..20884bc5d 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 @@ -3,11 +3,12 @@ package ru.dbotthepony.mc.otm.datagen.blocks import net.minecraft.resources.ResourceLocation import net.minecraft.world.level.block.Block import net.minecraftforge.client.model.generators.BlockStateProvider +import net.minecraftforge.client.model.generators.ConfiguredModel import net.minecraftforge.data.event.GatherDataEvent -import ru.dbotthepony.mc.otm.block.tech.BatteryBankBlock +import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom +import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateNorth import ru.dbotthepony.mc.otm.datagen.DataGen -import ru.dbotthepony.mc.otm.datagen.toYRotBlockstate import ru.dbotthepony.mc.otm.registry.MBlocks private fun nothingOrNumber(input: Int): String { @@ -23,20 +24,12 @@ open class BatteryBankProvider(event: GatherDataEvent) : BlockStateProvider(even protected var registry: Block = MBlocks.BATTERY_BANK override fun registerStatesAndModels() { - with(getMultipartBuilder(registry)) { - val battery_bank = models().getExistingFile(ResourceLocation("overdrive_that_matters:block/$block")) - - BlockRotationFreedom.ONE.possibleValues.forEach { - part().modelFile(battery_bank).rotationY(it.front.toYRotBlockstate()).addModel().condition( - BlockRotationFreedom.ONE.property, it) - - for (i in 0 .. 11) { - part().modelFile( - models().getExistingFile(ResourceLocation("overdrive_that_matters:$batteryPath$i")) - ).rotationY(it.front.toYRotBlockstate()).addModel() - .condition(BlockRotationFreedom.ONE.property, it) - .condition(BatteryBankBlock.BATTERY_SLOTS_PROPS[i], true) - } + with(getVariantBuilder(registry)) { + forAllStates { + ConfiguredModel.builder() + .modelFile(models().getExistingFile(ResourceLocation("overdrive_that_matters:block/$block"))) + .rotationY(it[BlockRotationFreedom.ONE.property].front.yRotationBlockstateNorth()) + .build() } } } 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 10ce4ef91..1d7daaded 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,12 +10,12 @@ import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock 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.math.xRotationBlockstateNorth +import ru.dbotthepony.mc.otm.core.math.xRotationBlockstateSouth +import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateNorth +import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateSouth import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.datagen.modLocation -import ru.dbotthepony.mc.otm.datagen.toXRotBlockstate -import ru.dbotthepony.mc.otm.datagen.toXRotBlockstateInv -import ru.dbotthepony.mc.otm.datagen.toYRotBlockstate -import ru.dbotthepony.mc.otm.datagen.toYRotBlockstateInv import ru.dbotthepony.mc.otm.registry.MBlocks import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.registry.MRegistry @@ -38,7 +38,7 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { with(provider.getMultipartBuilder(MBlocks.PHANTOM_ATTRACTOR)) { for (dir in BlockRotationFreedom.ONE.possibleValues) { part().modelFile(provider.models().getExistingFile(modLocation("block/${MNames.PHANTOM_ATTRACTOR}"))) - .rotationY(dir.front.toYRotBlockstate()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .condition(BlockStateProperties.DOUBLE_BLOCK_HALF, DoubleBlockHalf.LOWER) .condition(BlockRotationFreedom.ONE.property, dir) @@ -50,7 +50,7 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { 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.front.toYRotBlockstate()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.ONE.property, dir) .condition(WorkerState.WORKER_STATE, enum) @@ -61,14 +61,14 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { 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.front.toYRotBlockstate()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .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.front.toYRotBlockstate()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.ONE.property, dir) .condition(enum, true) @@ -98,7 +98,7 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { OverdriveThatMatters.MOD_ID, "${crate.registryName!!.path}_${if (it.getValue( CargoCrateBlock.IS_OPEN)) "open" else "closed"}") )) - .rotationY(it.getValue(BlockRotationFreedom.ONE.property).front.toYRotBlockstate()) + .rotationY(it.getValue(BlockRotationFreedom.ONE.property).front.yRotationBlockstateNorth()) .buildLast() ) } @@ -107,15 +107,15 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { with(provider.getMultipartBuilder(MBlocks.STORAGE_BUS)) { for (dir in BlockRotationFreedom.TWO.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_bus"))) - .rotationX(dir.front.toXRotBlockstate()) - .rotationY(dir.front.toYRotBlockstate()) + .rotationX(dir.front.xRotationBlockstateNorth()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.TWO.property, dir) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_cable_connection"))) - .rotationX(dir.front.toXRotBlockstateInv()) - .rotationY(dir.front.toYRotBlockstateInv()) + .rotationX(dir.front.xRotationBlockstateSouth()) + .rotationY(dir.front.yRotationBlockstateSouth()) .addModel() .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.front]!!, true) .end() @@ -128,15 +128,15 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { with(provider.getMultipartBuilder(MBlocks.STORAGE_IMPORTER)) { for (dir in BlockRotationFreedom.TWO.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_importer"))) - .rotationX(dir.front.toXRotBlockstate()) - .rotationY(dir.front.toYRotBlockstate()) + .rotationX(dir.front.xRotationBlockstateNorth()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.TWO.property, dir) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_cable_connection"))) - .rotationX(dir.front.toXRotBlockstateInv()) - .rotationY(dir.front.toYRotBlockstateInv()) + .rotationX(dir.front.xRotationBlockstateSouth()) + .rotationY(dir.front.yRotationBlockstateSouth()) .addModel() .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.front]!!, true) .end() @@ -149,15 +149,15 @@ fun addBlockStates(provider: MatteryBlockStateProvider) { with(provider.getMultipartBuilder(MBlocks.STORAGE_EXPORTER)) { for (dir in BlockRotationFreedom.TWO.possibleValues) { part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_exporter"))) - .rotationX(dir.front.toXRotBlockstate()) - .rotationY(dir.front.toYRotBlockstate()) + .rotationX(dir.front.xRotationBlockstateNorth()) + .rotationY(dir.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.TWO.property, dir) .end() part().modelFile(provider.models().getExistingFile(ResourceLocation(OverdriveThatMatters.MOD_ID, "storage_cable_connection"))) - .rotationX(dir.front.toXRotBlockstateInv()) - .rotationY(dir.front.toYRotBlockstateInv()) + .rotationX(dir.front.xRotationBlockstateSouth()) + .rotationY(dir.front.yRotationBlockstateSouth()) .addModel() .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.front]!!, 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 714934982..16711d918 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,8 +7,8 @@ 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.core.math.yRotationBlockstateNorth 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) { @@ -16,7 +16,7 @@ fun addComplexBlockStates(provider: MatteryBlockStateProvider) { for (facing in BlockRotationFreedom.ONE.possibleValues) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/drive_viewer_drive_part"))) - .rotationY(facing.front.toYRotBlockstate()) + .rotationY(facing.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.ONE.property, facing) .condition(DriveViewerBlock.DRIVE_PRESENT, true) @@ -24,7 +24,7 @@ fun addComplexBlockStates(provider: MatteryBlockStateProvider) { for (workState in WorkerState.SEMI_WORKER_STATE.possibleValues) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/drive_viewer_${workState.name.lowercase()}"))) - .rotationY(facing.front.toYRotBlockstate()) + .rotationY(facing.front.yRotationBlockstateNorth()) .addModel() .condition(WorkerState.SEMI_WORKER_STATE, workState) .condition(BlockRotationFreedom.ONE.property, facing) @@ -36,14 +36,14 @@ fun addComplexBlockStates(provider: MatteryBlockStateProvider) { for (facing in BlockRotationFreedom.ONE.possibleValues) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/pattern_storage"))) - .rotationY(facing.front.toYRotBlockstate()) + .rotationY(facing.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.ONE.property, facing) for (i in 0 .. 7) { part() .modelFile(provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/pattern/model$i"))) - .rotationY(facing.front.toYRotBlockstate()) + .rotationY(facing.front.yRotationBlockstateNorth()) .addModel() .condition(BlockRotationFreedom.ONE.property, facing) .condition(PatternStorageBlock.PATTERN_STORAGE_DISKS_PROPS[i], true) @@ -69,8 +69,8 @@ fun addComplexBlockStates(provider: MatteryBlockStateProvider) { val southWest = provider.models().getExistingFile(ResourceLocation(MOD_ID, "block/energy_counter_south_west")) for (dir in arrayOf(Direction.EAST, Direction.WEST, Direction.SOUTH, Direction.NORTH)) { - part().modelFile(down).rotationY(dir.toYRotBlockstate()).addModel().condition(EnergyCounterBlock.INPUT_DIRECTION, Direction.UP).condition(EnergyCounterBlock.IF_DIRECTION, dir) - part().modelFile(up).rotationY(dir.toYRotBlockstate()).addModel().condition(EnergyCounterBlock.INPUT_DIRECTION, Direction.DOWN).condition(EnergyCounterBlock.IF_DIRECTION, dir) + part().modelFile(down).rotationY(dir.yRotationBlockstateNorth()).addModel().condition(EnergyCounterBlock.INPUT_DIRECTION, Direction.UP).condition(EnergyCounterBlock.IF_DIRECTION, dir) + part().modelFile(up).rotationY(dir.yRotationBlockstateNorth()).addModel().condition(EnergyCounterBlock.INPUT_DIRECTION, Direction.DOWN).condition(EnergyCounterBlock.IF_DIRECTION, dir) } // низкий поклон за полностью рабочий поворот вокруг оси Z 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 01a084807..90babe7c9 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 @@ -7,11 +7,11 @@ import net.minecraftforge.client.model.generators.BlockStateProvider import net.minecraftforge.client.model.generators.ConfiguredModel import net.minecraftforge.data.event.GatherDataEvent import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.core.getValueNullable import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom +import ru.dbotthepony.mc.otm.core.math.xRotationBlockstateNorth +import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateNorth import ru.dbotthepony.mc.otm.datagen.DataGen -import ru.dbotthepony.mc.otm.datagen.getValueNullable -import ru.dbotthepony.mc.otm.datagen.toXRotBlockstate -import ru.dbotthepony.mc.otm.datagen.toYRotBlockstate import ru.dbotthepony.mc.otm.core.registryName import java.util.LinkedList @@ -22,17 +22,17 @@ private fun initialTransform(it: BlockState, modelPath: String, builder: Configu @Suppress("NAME_SHADOWING") var modelPath = modelPath it.getValueNullable(BlockRotationFreedom.ONE.property)?.let { - builder.rotationY(it.front.toYRotBlockstate()) + builder.rotationY(it.front.yRotationBlockstateNorth()) } it.getValueNullable(BlockRotationFreedom.TWO.property)?.let { - builder.rotationY(it.front.toYRotBlockstate()) - builder.rotationX(it.front.toXRotBlockstate()) + builder.rotationY(it.front.yRotationBlockstateNorth()) + builder.rotationX(it.front.xRotationBlockstateNorth()) } it.getValueNullable(BlockRotationFreedom.THREE.property)?.let { - builder.rotationY(it.front.toYRotBlockstate() + it.top.toYRotBlockstate()) - builder.rotationX(it.front.toXRotBlockstate()) + builder.rotationY(it.front.yRotationBlockstateNorth() + it.top.yRotationBlockstateNorth()) + builder.rotationX(it.front.xRotationBlockstateNorth()) } it.getValueNullable(WorkerState.WORKER_STATE)?.let { diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 9fc842ee9..0d7fab0ca 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -31,6 +31,8 @@ import ru.dbotthepony.mc.otm.client.model.ExosuitModel; import ru.dbotthepony.mc.otm.client.model.GravitationStabilizerModel; import ru.dbotthepony.mc.otm.client.model.TritaniumArmorModel; import ru.dbotthepony.mc.otm.client.render.ShockwaveRenderer; +import ru.dbotthepony.mc.otm.client.render.blockentity.BatteryBankRenderer; +import ru.dbotthepony.mc.otm.client.render.blockentity.MatterBatteryBankRenderer; import ru.dbotthepony.mc.otm.compat.mekanism.QIOKt; import ru.dbotthepony.mc.otm.compat.mekanism.TooltipsKt; import ru.dbotthepony.mc.otm.core.math.Decimal; @@ -113,7 +115,10 @@ public final class OverdriveThatMatters { modBus.addListener(EventPriority.NORMAL, AndroidAbilityKeyMapping.INSTANCE::register); modBus.addListener(EventPriority.NORMAL, TritaniumArmorModel::register); modBus.addListener(EventPriority.NORMAL, GravitationStabilizerModel::register); - modBus.addListener(EventPriority.NORMAL, MCreativeTabs.INSTANCE::register$overdrive_that_matters); + modBus.addListener(EventPriority.NORMAL, MCreativeTabs.INSTANCE::register); + + modBus.addListener(EventPriority.NORMAL, BatteryBankRenderer.Companion::onRegisterAdditionalModels); + modBus.addListener(EventPriority.NORMAL, MatterBatteryBankRenderer.Companion::onRegisterAdditionalModels); }); ClientConfig.INSTANCE.register(); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt index a12a8c866..a8e9e404b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterCapacitorBankBlockEntity.kt @@ -19,10 +19,12 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.block.tech.BatteryBankBlock import ru.dbotthepony.mc.otm.block.IDroppableContainer import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.core.ImmutableList import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.graph.Graph6Node @@ -135,30 +137,18 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) private var resolver = LazyOptional.of { this } - val container = object : MatteryContainer(this::setChangedLight, 6 * 2) { + val container = object : MatteryContainer(this::setChangedLight, BatteryBankBlockEntity.CAPACITY) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) - val level = level - - if (level != null) { - var state = blockState - - for (i in BatteryBankBlock.BATTERY_SLOTS_PROPS.indices) { - state = state.setValue( - BatteryBankBlock.BATTERY_SLOTS_PROPS[i], - getItem(i).getCapability(MatteryCapability.MATTER).isPresent - ) - } - - if (state !== blockState) { - level.setBlock(blockPos, state, Block.UPDATE_CLIENTS) - } - } - + capacitorStatus[slot].value = new.getCapability(MatteryCapability.MATTER).isPresent gaugeLevel = (storedMatter / maxStoredMatter).toFloat() } } + val capacitorStatus = ImmutableList(BatteryBankBlockEntity.CAPACITY) { + synchronizer.bool(false, name = "capacitor$it") + } + override val droppableContainer: Container get() = container override val defaultDisplayName: Component 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 a04973c44..a4dec5cfe 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 @@ -44,24 +44,15 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte val container: MatteryContainer = object : MatteryContainer(this::setChanged, CAPACITY) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { super.setChanged(slot, new, old) - - val level = level - if (level != null) { - var state = blockState - - for (i in BatteryBankBlock.BATTERY_SLOTS_PROPS.indices) { - state = state.setValue(BatteryBankBlock.BATTERY_SLOTS_PROPS[i], getItem(i).getCapability(ForgeCapabilities.ENERGY).isPresent) - } - - if (state !== blockState) { - level.setBlock(blockPos, state, Block.UPDATE_CLIENTS) - } - } - + batteryStatus[slot].value = new.getCapability(ForgeCapabilities.ENERGY).isPresent gaugeLevel = (energy.batteryLevel / energy.maxBatteryLevel).toFloat() } } + val batteryStatus = ImmutableList(CAPACITY) { + synchronizer.bool(false, name = "battery$it") + } + override val droppableContainer: Container get() = container private val itemHandler = container.handler( 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 62439912a..99ff2d94a 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 @@ -23,21 +23,7 @@ class MatterCapacitorBankBlock : RotatableMatteryBlock(), EntityBlock { return MatterCapacitorBankBlockEntity(blockPos, blockState) } - override fun getStateForPlacement(context: BlockPlaceContext): BlockState? { - var state = super.getStateForPlacement(context) ?: return null - - for (prop in BatteryBankBlock.BATTERY_SLOTS_PROPS) - state = state.setValue(prop, false) - - return state - } - - override fun createBlockStateDefinition(builder: StateDefinition.Builder) { - BatteryBankBlock.BATTERY_SLOTS_PROPS.forEach(builder::add) - super.createBlockStateDefinition(builder) - } - - private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.MATTER_CAPACITOR_BANK.rotateFromSouth(it[rotationProperty]).computeShape() } + private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.MATTER_CAPACITOR_BANK.rotateFromNorth(it[rotationProperty]).computeShape() } @Suppress("override_deprecation") override fun getShape( 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 5c6fb49e6..f84edddf7 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 @@ -28,15 +28,6 @@ import ru.dbotthepony.mc.otm.shapes.BlockShapes @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock { - override fun getStateForPlacement(context: BlockPlaceContext): BlockState { - var state = super.getStateForPlacement(context)!! - - for (prop in BATTERY_SLOTS_PROPS) - state = state.setValue(prop, false) - - return state - } - override fun getTicker( level: Level, p_153213_: BlockState, @@ -48,16 +39,11 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock { return BlockEntityTicker { _, _, _, tile -> if (tile is BatteryBankBlockEntity) tile.tick() } } - override fun createBlockStateDefinition(builder: StateDefinition.Builder) { - BATTERY_SLOTS_PROPS.forEach(builder::add) - super.createBlockStateDefinition(builder) - } - - override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity? { + override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity { return BatteryBankBlockEntity(blockPos, blockState) } - private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.BATTERY_BANK.rotateFromSouth(it[rotationProperty]).computeShape() } + private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.BATTERY_BANK.rotateFromNorth(it[rotationProperty]).computeShape() } @Suppress("override_deprecation") override fun getShape( @@ -85,21 +71,4 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock { val blockEntity = level.getBlockEntity(pos) as? BatteryBankBlockEntity ?: return level.oncePre { blockEntity.checkSurroundings() } } - - companion object { - val BATTERY_SLOTS_PROPS: ImmutableList = ImmutableList.of( - BooleanProperty.create("battery_0") as BooleanProperty, - BooleanProperty.create("battery_1") as BooleanProperty, - BooleanProperty.create("battery_2") as BooleanProperty, - BooleanProperty.create("battery_3") as BooleanProperty, - BooleanProperty.create("battery_4") as BooleanProperty, - BooleanProperty.create("battery_5") as BooleanProperty, - BooleanProperty.create("battery_6") as BooleanProperty, - BooleanProperty.create("battery_7") as BooleanProperty, - BooleanProperty.create("battery_8") as BooleanProperty, - BooleanProperty.create("battery_9") as BooleanProperty, - BooleanProperty.create("battery_10") as BooleanProperty, - BooleanProperty.create("battery_11") as BooleanProperty, - ) - } } 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 2d67ee17a..5d62e3ff0 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 @@ -2,25 +2,43 @@ package ru.dbotthepony.mc.otm.client.render.blockentity import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.renderer.MultiBufferSource +import net.minecraft.client.renderer.RenderType import net.minecraft.client.renderer.blockentity.BlockEntityRenderer import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider +import net.minecraft.client.resources.model.BakedModel import net.minecraft.core.Direction -import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock -import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.level.levelgen.XoroshiroRandomSource +import net.minecraftforge.client.event.ModelEvent +import org.joml.AxisAngle4f +import org.joml.Quaternionf +import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity +import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity +import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite 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.ImmutableList import ru.dbotthepony.mc.otm.core.get +import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom +import ru.dbotthepony.mc.otm.core.math.PIf 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 +import java.util.function.Supplier import kotlin.math.PI abstract class BankRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer { protected abstract fun gaugeLevel(entity: T): Float protected abstract val texture: AbstractMatterySprite + protected abstract val models: List + protected abstract fun status(entity: T): List> + + private val random = XoroshiroRandomSource(nanoTime) override fun render( blockEntity: T, @@ -30,6 +48,26 @@ abstract class BankRenderer(private val context: BlockEn p_112311_: Int, p_112312_: Int ) { + val status = status(blockEntity) + + stack.pushPose() + stack.translate(0.5f, 0.5f, 0.5f) + stack.rotate(blockEntity.blockState[BlockRotationFreedom.ONE.property].front) + stack.translate(-0.5f, -0.5f, -0.5f) + + for ((i, model) in models.withIndex()) { + if (!status[i].get()) { + continue + } + + val buffer = DynamicBufferSource.WORLD.getBuffer(RenderType.solid()) + + for (quad in model.getQuads(null, null, random)) + buffer.putBulkData(stack.last(), quad, 1f, 1f, 1f, p_112311_, p_112312_) + } + + stack.popPose() + val plainLevel = gaugeLevel(blockEntity) if (plainLevel <= 0f) { @@ -81,20 +119,56 @@ abstract class BankRenderer(private val context: BlockEn } class BatteryBankRenderer(context: BlockEntityRendererProvider.Context) : BankRenderer(context) { + override val models: List by lazy { + ImmutableList(12) { + minecraft.modelManager.modelBakery.bakedTopLevelModels[ResourceLocation(OverdriveThatMatters.MOD_ID, "block/battery/battery$it")]!! + } + } + + override fun status(entity: BatteryBankBlockEntity): List> { + return entity.batteryStatus + } + override fun gaugeLevel(entity: BatteryBankBlockEntity): Float { return entity.gaugeLevel } override val texture: AbstractMatterySprite get() = PowerGaugePanel.GAUGE_FOREGROUND + + companion object { + fun onRegisterAdditionalModels(event: ModelEvent.RegisterAdditional) { + for (i in 0 .. 11) { + event.register(ResourceLocation(OverdriveThatMatters.MOD_ID, "block/battery/battery$i")) + } + } + } } class MatterBatteryBankRenderer(context: BlockEntityRendererProvider.Context) : BankRenderer(context) { + override val models: List by lazy { + ImmutableList(12) { + minecraft.modelManager.modelBakery.bakedTopLevelModels[ResourceLocation(OverdriveThatMatters.MOD_ID, "block/battery/matter_capacitor$it")]!! + } + } + + override fun status(entity: MatterCapacitorBankBlockEntity): List> { + return entity.capacitorStatus + } + override fun gaugeLevel(entity: MatterCapacitorBankBlockEntity): Float { return entity.gaugeLevel } override val texture: AbstractMatterySprite get() = MatterGaugePanel.GAUGE_FOREGROUND + + companion object { + fun onRegisterAdditionalModels(event: ModelEvent.RegisterAdditional) { + for (i in 0 .. 11) { + event.register(ResourceLocation(OverdriveThatMatters.MOD_ID, "block/battery/matter_capacitor$i")) + } + } + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt index 68b54d5f7..f744436af 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Ext.kt @@ -112,7 +112,7 @@ fun > T.prev(values: Array): T { return values[next] } -inline fun ImmutableList(size: Int, initializer: (index: Int) -> T): ImmutableList { +inline fun ImmutableList(size: Int, initializer: (index: Int) -> T): ImmutableList { require(size >= 0) { "Invalid list size $size" } return when (size) { @@ -253,3 +253,11 @@ inline fun MutableList>.forValidRefs(fn: (T) -> Unit) { val ComponentContents.key: String get() = (this as? TranslatableContents ?: throw ClassCastException("$this is not a TranslatableContents"))?.key + +fun > BlockState.getValueNullable(prop: Property): T? { + if (hasProperty(prop)) { + return getValue(prop) + } + + return null +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/EuclidMath.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/EuclidMath.kt index 86045f6f4..440d4a6f1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/EuclidMath.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/EuclidMath.kt @@ -561,6 +561,15 @@ fun PoseStack.rotateZ(rotation: Float): PoseStack { return this } +fun PoseStack.rotate(rotation: Direction): PoseStack { + return rotateY(rotation.yRotationNorth()).rotateX(rotation.xRotationNorth()) +} + +fun PoseStack.rotateSouth(rotation: Direction): PoseStack { + return rotateY(rotation.yRotationSouth()).rotateX(rotation.xRotationSouth()) +} +// /1.19.3 stuff + const val PIf = 3.1415927f /** @@ -666,3 +675,71 @@ fun PoseStack.rotateZDegrees(rotation: Float): PoseStack { return this } +fun Direction.yRotationBlockstateNorth(): Int { + return when (this) { + Direction.DOWN, Direction.UP, Direction.NORTH -> 0 + Direction.SOUTH -> 180 + Direction.WEST -> -90 + Direction.EAST -> 90 + } +} + +fun Direction.yRotationBlockstateSouth(): Int { + return when (this) { + Direction.DOWN, Direction.UP, Direction.SOUTH -> 0 + Direction.NORTH -> 180 + Direction.WEST -> 90 + Direction.EAST -> -90 + } +} + +fun Direction.xRotationBlockstateNorth(): Int { + return when (this) { + Direction.DOWN -> 90 + Direction.UP -> -90 + else -> 0 + } +} + +fun Direction.xRotationBlockstateSouth(): Int { + return when (this) { + Direction.DOWN -> -90 + Direction.UP -> 90 + else -> 0 + } +} + +fun Direction.yRotationNorth(): Float { + return when (this) { + Direction.DOWN, Direction.UP, Direction.NORTH -> 0f + Direction.SOUTH -> PIf + Direction.WEST -> -PIf / 2f + Direction.EAST -> PIf / 2f + } +} + +fun Direction.yRotationSouth(): Float { + return when (this) { + Direction.DOWN, Direction.UP, Direction.SOUTH -> 0f + Direction.NORTH -> PIf + Direction.WEST -> PIf / 2f + Direction.EAST -> -PIf / 2f + } +} + +fun Direction.xRotationNorth(): Float { + return when (this) { + Direction.DOWN -> PIf / 2f + Direction.UP -> -PIf / 2f + else -> 0f + } +} + +fun Direction.xRotationSouth(): Float { + return when (this) { + Direction.DOWN -> -PIf / 2f + Direction.UP -> PIf / 2f + else -> 0f + } +} + diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MCreativeTabs.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MCreativeTabs.kt index 4cfc8c9c3..415c331dc 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MCreativeTabs.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MCreativeTabs.kt @@ -15,7 +15,7 @@ object MCreativeTabs { var DECORATIVE by WriteOnce() private set - internal fun register(event: CreativeModeTabEvent.Register) { + fun register(event: CreativeModeTabEvent.Register) { MAIN = event.registerCreativeModeTab(ResourceLocation(OverdriveThatMatters.MOD_ID, "main")) { it.icon { ItemStack(BATTERY_CREATIVE, 1) } it.title(TranslatableComponent("itemGroup.otm"))