powered energy cables blockstate, БАГНУТАЯ ХУЙНЯ!!!!!!!!!!!!

This commit is contained in:
YuRaNnNzZZ 2025-01-10 15:05:28 +03:00
parent b2ee766194
commit d8744841d9
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D
7 changed files with 98 additions and 7 deletions

View File

@ -10,10 +10,10 @@ fun addBlockModels(provider: MatteryBlockModelProvider) {
resourceCubeAll(MBlocks.DEEPSLATE_TRITANIUM_ORE) resourceCubeAll(MBlocks.DEEPSLATE_TRITANIUM_ORE)
resourceCubeAll(MBlocks.TRITANIUM_INGOT_BLOCK) resourceCubeAll(MBlocks.TRITANIUM_INGOT_BLOCK)
cable("crude_energy_cable", "block/power_cable_0") cable("crude_energy_cable", "block/power_cable_0", powered = true)
cable("regular_energy_cable", "block/power_cable_1") cable("regular_energy_cable", "block/power_cable_1", powered = true)
cable("advanced_energy_cable", "block/power_cable_2") cable("advanced_energy_cable", "block/power_cable_2", powered = true)
cable("superconductor_energy_cable", "block/power_cable_3") cable("superconductor_energy_cable", "block/power_cable_3", powered = true)
cable("matter_cable", "block/matter_cable", thin = true) cable("matter_cable", "block/matter_cable", thin = true)
cable("storage_cable", "block/storage_cable") cable("storage_cable", "block/storage_cable")

View File

@ -250,11 +250,22 @@ fun addBlockStates(provider: MatteryBlockStateProvider) {
.rotationY(dir.front.yRotationBlockstateSouth()) .rotationY(dir.front.yRotationBlockstateSouth())
.addModel() .addModel()
.condition(CableBlock.MAPPING_CONNECTION_PROP[dir.front]!!, true) .condition(CableBlock.MAPPING_CONNECTION_PROP[dir.front]!!, true)
.condition(BlockStateProperties.POWERED, false)
.end()
part().modelFile(provider.models().getExistingFile(modLocation("${block.value.registryName!!.path}_connection_powered")))
.rotationX(dir.front.xRotationBlockstateSouth())
.rotationY(dir.front.yRotationBlockstateSouth())
.addModel()
.condition(CableBlock.MAPPING_CONNECTION_PROP[dir.front]!!, true)
.condition(BlockStateProperties.POWERED, true)
.end() .end()
} }
part().modelFile(provider.models().getExistingFile(modLocation("${block.value.registryName!!.path}_core"))) part().modelFile(provider.models().getExistingFile(modLocation("${block.value.registryName!!.path}_core")))
.addModel().end() .addModel().condition(BlockStateProperties.POWERED, false).end()
part().modelFile(provider.models().getExistingFile(modLocation("${block.value.registryName!!.path}_core_powered")))
.addModel().condition(BlockStateProperties.POWERED, true).end()
} }
} }

View File

@ -143,7 +143,7 @@ class MatteryBlockModelProvider(event: GatherDataEvent) : BlockModelProvider(eve
} }
} }
fun cable(modelName: String, textureName: String, thin: Boolean = false) { fun cable(modelName: String, textureName: String, thin: Boolean = false, powered: Boolean = false) {
val baseName = if (thin) "base_cable_thin" else "base_cable" val baseName = if (thin) "base_cable_thin" else "base_cable"
exec { exec {
@ -156,5 +156,15 @@ class MatteryBlockModelProvider(event: GatherDataEvent) : BlockModelProvider(eve
withExistingParent("item/${modelName}", modLocation("item/${baseName}")) withExistingParent("item/${modelName}", modLocation("item/${baseName}"))
.texture("0", textureName) .texture("0", textureName)
} }
if (powered && !thin) {
exec {
withExistingParent("block/${modelName}_core_powered", modLocation("block/${baseName}_core_powered"))
.texture("0", textureName)
withExistingParent("block/${modelName}_connection_powered", modLocation("block/${baseName}_connection_powered"))
.texture("0", textureName)
}
}
} }
} }

View File

@ -17,6 +17,7 @@ import net.minecraft.world.level.block.SoundType
import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.block.state.StateDefinition
import net.minecraft.world.level.block.state.properties.BlockStateProperties
import net.minecraft.world.level.block.state.properties.BooleanProperty import net.minecraft.world.level.block.state.properties.BooleanProperty
import net.minecraft.world.level.material.MapColor import net.minecraft.world.level.material.MapColor
import net.minecraft.world.level.material.PushReaction import net.minecraft.world.level.material.PushReaction
@ -142,6 +143,16 @@ class StorageCableBlock : CableBlock(Properties.of().mapColor(MapColor.METAL).re
class EnergyCableBlock(val factory: (blockPos: BlockPos, blockState: BlockState) -> BlockEntity) : CableBlock(Properties.of().mapColor(MapColor.METAL).pushReaction(PushReaction.DESTROY).requiresCorrectToolForDrops().sound(SoundType.METAL).strength(1.0f, 6.0f)), EntityBlock { class EnergyCableBlock(val factory: (blockPos: BlockPos, blockState: BlockState) -> BlockEntity) : CableBlock(Properties.of().mapColor(MapColor.METAL).pushReaction(PushReaction.DESTROY).requiresCorrectToolForDrops().sound(SoundType.METAL).strength(1.0f, 6.0f)), EntityBlock {
private val shapes = generateShapes(0.185) private val shapes = generateShapes(0.185)
init {
registerDefaultState(defaultBlockState().setValue(BlockStateProperties.POWERED, false))
}
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
super.createBlockStateDefinition(builder)
builder.add(BlockStateProperties.POWERED)
}
@Suppress("OVERRIDE_DEPRECATION") @Suppress("OVERRIDE_DEPRECATION")
override fun getShape(blockState: BlockState, accessor: BlockGetter, pos: BlockPos, context: CollisionContext): VoxelShape { override fun getShape(blockState: BlockState, accessor: BlockGetter, pos: BlockPos, context: CollisionContext): VoxelShape {
return shapes[blockState] ?: Shapes.block() return shapes[blockState] ?: Shapes.block()

View File

@ -6,6 +6,7 @@ import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.properties.BlockStateProperties
import net.neoforged.neoforge.capabilities.Capabilities import net.neoforged.neoforge.capabilities.Capabilities
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
import ru.dbotthepony.mc.otm.block.CableBlock import ru.dbotthepony.mc.otm.block.CableBlock
@ -114,12 +115,30 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP
if (!SERVER_IS_LIVE) return if (!SERVER_IS_LIVE) return
val level = level val level = level
val powered = node.graph.livelyNodes.filter {
it.blockEntity.energySides.filter {
side -> side.value.neighbour.isPresent && side.value.neighbour.get() !is CableSide
}.isNotEmpty()
}.size >= 2
level?.once { level?.once {
if (!node.isValid) return@once if (!node.isValid) return@once
val newState = blockState.setValue(CableBlock.MAPPING_CONNECTION_PROP[side]!!, status)
val newState = blockState
.setValue(CableBlock.MAPPING_CONNECTION_PROP[side]!!, status)
.setValue(BlockStateProperties.POWERED, powered)
if (newState !== blockState && SERVER_IS_LIVE) if (newState !== blockState && SERVER_IS_LIVE)
level.setBlock(blockPos, newState, Block.UPDATE_CLIENTS) level.setBlock(blockPos, newState, Block.UPDATE_CLIENTS)
node.graph.livelyNodes.forEach {
if (it.isValid) {
val newState = it.blockEntity.blockState.setValue(BlockStateProperties.POWERED, powered)
if (newState !== it.blockEntity.blockState && SERVER_IS_LIVE)
level.setBlock(it.blockEntity.blockPos, newState, Block.UPDATE_CLIENTS)
}
}
} }
} }

View File

@ -0,0 +1,19 @@
{
"parent": "block/block",
"texture_size": [16, 16],
"textures": {
"particle": "#0"
},
"elements": [
{
"from": [5, 5, 11],
"to": [11, 11, 16],
"faces": {
"east": {"uv": [6, 6, 11, 12], "texture": "#0"},
"west": {"uv": [6, 6, 11, 12], "texture": "#0"},
"up": {"uv": [6, 6, 11, 12], "rotation": 90, "texture": "#0"},
"down": {"uv": [6, 6, 11, 12], "rotation": 90, "texture": "#0"}
}
}
]
}

View File

@ -0,0 +1,21 @@
{
"parent": "block/block",
"texture_size": [16, 16],
"textures": {
"particle": "#0"
},
"elements": [
{
"from": [5, 5, 5],
"to": [11, 11, 11],
"faces": {
"north": {"uv": [0, 6, 6, 12], "texture": "#0"},
"east": {"uv": [0, 6, 6, 12], "texture": "#0"},
"south": {"uv": [0, 6, 6, 12], "texture": "#0"},
"west": {"uv": [0, 6, 6, 12], "texture": "#0"},
"up": {"uv": [0, 6, 6, 12], "texture": "#0"},
"down": {"uv": [0, 6, 6, 12], "texture": "#0"}
}
}
]
}