From 94e6c505bd09a653008159af114a4418fea216e5 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Sun, 12 Apr 2026 20:39:46 +0200 Subject: [PATCH] initial work on combustion --- .../org/neoflock/neocomputers/block/Blocks.kt | 1 + .../neoflock/neocomputers/block/Generators.kt | 19 ++++++++++++++++++ .../neocomputers/entity/BlockEntities.kt | 9 +++++++-- .../entity/CombustionGeneratorBlockEntity.kt | 20 +++++++++++++++++++ .../entity/SolarGeneratorBlockEntity.kt | 2 +- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt index 1ab7e8e..36f559d 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt @@ -28,6 +28,7 @@ object Blocks { val SCREEN_BLOCK: RegistrySupplier = BaseBlock.register("screen") { ScreenBlock() } val CAPACITOR_BLOCK: RegistrySupplier = BaseBlock.register("capacitor") { CapacitorBlock() } val SOLARGEN_BLOCK: RegistrySupplier = BaseBlock.register("solargen") { SolarGeneratorBlock() } + val COMBUSTGEN_BLOCK: RegistrySupplier = BaseBlock.register("combustgen") { CombustionGeneratorBlock() } fun registerBlockItems() { BLOCKS.forEach(Consumer { sup: RegistrySupplier -> diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt index fd7d864..d88f0cc 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt @@ -15,6 +15,25 @@ class SolarGeneratorBlock : BaseBlock(), EntityBlock { return SolarGeneratorBlockEntity(BlockEntities.SOLARGEN_ENTITY.get(), blockPos, blockState) } + override fun getTicker( + level: Level, + blockState: BlockState, + blockEntityType: BlockEntityType + ): BlockEntityTicker { + return object : BlockEntityTicker { + override fun tick(level: Level, blockPos: BlockPos, blockState: BlockState, blockEntity: T) { + if(blockEntity !is SolarGeneratorBlockEntity) return; + blockEntity.giveSolarPower(); + } + } + } +} + +class CombustionGeneratorBlock : BaseBlock(), EntityBlock { + override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity { + return CombustionGeneratorBlockEntity(BlockEntities.COMBUSTGEN_ENTITY.get(), blockPos, blockState) + } + override fun getTicker( level: Level, blockState: BlockState, diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt index 8677568..af89181 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/BlockEntities.kt @@ -47,9 +47,14 @@ object BlockEntities { ::CapacitorEntity, mutableSetOf(Blocks.CAPACITOR_BLOCK.get()), BullshitFix() ) } - val SOLARGEN_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("solargen_entity") { + val SOLARGEN_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("solargen_entity") { BlockEntityType( - ::CapacitorEntity, mutableSetOf(Blocks.SOLARGEN_BLOCK.get()), BullshitFix() + ::SolarGeneratorBlockEntity, mutableSetOf(Blocks.SOLARGEN_BLOCK.get()), BullshitFix() + ) + } + val COMBUSTGEN_ENTITY: RegistrySupplier> = BLOCKENTITIES.register("combustgen_entity") { + BlockEntityType( + ::CombustionGeneratorBlockEntity, mutableSetOf(Blocks.COMBUSTGEN_BLOCK.get()), BullshitFix() ) } diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt new file mode 100644 index 0000000..f92fb95 --- /dev/null +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt @@ -0,0 +1,20 @@ +package org.neoflock.neocomputers.entity + +import net.minecraft.core.BlockPos +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.entity.BlockEntityType +import net.minecraft.world.level.block.state.BlockState +import org.neoflock.neocomputers.block.NodeBlockEntity + +class CombustionGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) : BlockEntity(BlockEntities.COMBUSTGEN_ENTITY.get(), blockPos, blockState) { + val energyPerTick: Long = 50 + + fun giveSolarPower() { + if(level?.isDay == true) { + val below = level?.getBlockEntity(blockPos.below()) + if(below is NodeBlockEntity) { + below.node.giveEnergy(energyPerTick) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/SolarGeneratorBlockEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/SolarGeneratorBlockEntity.kt index 5ee0677..c2408e6 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/SolarGeneratorBlockEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/SolarGeneratorBlockEntity.kt @@ -6,7 +6,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState import org.neoflock.neocomputers.block.NodeBlockEntity -class SolarGeneratorBlockEntity(entityType: BlockEntityType<*>, blockPos: BlockPos, blockState: BlockState) : BlockEntity(entityType, blockPos, blockState) { +class SolarGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) : BlockEntity(BlockEntities.SOLARGEN_ENTITY.get(), blockPos, blockState) { val energyPerTick: Long = 50 fun giveSolarPower() {