fixes and made solar power also nodes

This commit is contained in:
2026-04-14 00:40:41 +02:00
parent 8d146fbd17
commit ab9d1baa36
4 changed files with 40 additions and 56 deletions

View File

@@ -1,6 +1,5 @@
package org.neoflock.neocomputers.block
import net.minecraft.client.resources.sounds.Sound
import net.minecraft.core.BlockPos
import net.minecraft.network.chat.ChatType
import net.minecraft.network.chat.OutgoingChatMessage
@@ -9,56 +8,21 @@ import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.InteractionResult
import net.minecraft.world.entity.player.Player
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.FurnaceBlock
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockBehaviour
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.BlockHitResult
import org.neoflock.neocomputers.entity.BlockEntities
import org.neoflock.neocomputers.entity.SolarGeneratorBlockEntity
import org.neoflock.neocomputers.entity.CombustionGeneratorBlockEntity
class SolarGeneratorBlock : BaseBlock(), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return SolarGeneratorBlockEntity(blockPos, blockState)
}
override fun <T : BlockEntity> getTicker(
level: Level,
blockState: BlockState,
blockEntityType: BlockEntityType<T>
): BlockEntityTicker<T> {
return object : BlockEntityTicker<T> {
override fun tick(level: Level, blockPos: BlockPos, blockState: BlockState, blockEntity: T) {
if(blockEntity !is SolarGeneratorBlockEntity) return;
blockEntity.giveSolarPower();
}
}
}
class SolarGeneratorBlock : NodeBlock(), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity = SolarGeneratorBlockEntity(blockPos, blockState).initNetworking()
}
// TODO: make it glow when burning
class CombustionGeneratorBlock : Block(BlockBehaviour.Properties.of()), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
return CombustionGeneratorBlockEntity(blockPos, blockState)
}
override fun <T : BlockEntity> getTicker(
level: Level,
blockState: BlockState,
blockEntityType: BlockEntityType<T>
): BlockEntityTicker<T> {
return object : BlockEntityTicker<T> {
override fun tick(level: Level, blockPos: BlockPos, blockState: BlockState, blockEntity: T) {
if(blockEntity !is CombustionGeneratorBlockEntity) return;
blockEntity.burnFuelForEnergy();
}
}
}
class CombustionGeneratorBlock : NodeBlock(), EntityBlock {
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity = CombustionGeneratorBlockEntity(blockPos, blockState).initNetworking()
override fun useWithoutItem(
blockState: BlockState,
@@ -66,7 +30,7 @@ class CombustionGeneratorBlock : Block(BlockBehaviour.Properties.of()), EntityBl
blockPos: BlockPos,
player: Player,
blockHitResult: BlockHitResult
): InteractionResult? {
): InteractionResult {
if(!level.isClientSide()) {
val sp = player as ServerPlayer
val ent = level.getBlockEntity(blockPos, BlockEntities.COMBUSTGEN_ENTITY.get())
@@ -77,6 +41,6 @@ class CombustionGeneratorBlock : Block(BlockBehaviour.Properties.of()), EntityBl
sp.sendChatMessage(OutgoingChatMessage.create(msg), false, ChatType.bind(ChatType.CHAT, player))
}
}
return InteractionResult.SUCCESS;
return InteractionResult.SUCCESS
}
}

View File

@@ -16,8 +16,9 @@ import org.neoflock.neocomputers.network.Networking
abstract class NodeBlockEntity(blockEntityType: BlockEntityType<*>, blockPos: BlockPos, blockState: BlockState) : BlockEntity(blockEntityType, blockPos, blockState) {
abstract val node: Networking.Node
fun initNetworking() {
fun initNetworking(): NodeBlockEntity {
Networking.addNode(node)
return this
}
private var stateIsDirty = true
@@ -52,7 +53,7 @@ abstract class NodeBlockEntity(blockEntityType: BlockEntityType<*>, blockPos: Bl
fun needsSynchronization() = stateIsDirty
fun ensureSynchronized() {
open fun tickNode() {
if(!stateIsDirty) return
stateIsDirty = false
computeEdges().forEach {
@@ -81,7 +82,7 @@ abstract class NodeBlock: BaseBlock(), EntityBlock {
return object : BlockEntityTicker<T> {
override fun tick(level: Level, blockPos: BlockPos, blockState: BlockState, blockEntity: T) {
if(blockEntity !is NodeBlockEntity) return;
blockEntity.ensureSynchronized()
blockEntity.tickNode()
}
}
}