From 7d4ee8593c4cc1df3e28a10b097e592c0e04c619 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Sat, 18 Apr 2026 12:12:31 +0200 Subject: [PATCH] combustion gen drops items and such --- .../org/neoflock/neocomputers/block/Capacitor.kt | 2 ++ .../org/neoflock/neocomputers/block/Generators.kt | 12 ++++++++++++ .../entity/CombustionGeneratorBlockEntity.kt | 6 ++++++ .../neocomputers/entity/SolarGeneratorBlockEntity.kt | 2 ++ 4 files changed, 22 insertions(+) diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt index 34c3ee8..efebf8f 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Capacitor.kt @@ -29,10 +29,12 @@ open class CapacitorEntity(val capacity: Long, type: BlockEntityType<*>, pos: Bl } override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) { + super.loadAdditional(compoundTag, provider) node.energy = min(compoundTag.getLong("energy"), node.energyCapacity) } override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) { + super.saveAdditional(compoundTag, provider) compoundTag.putLong("energy", node.energy) } } diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt index 25e51ea..77406a9 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Generators.kt @@ -7,6 +7,7 @@ import net.minecraft.server.level.ServerPlayer import net.minecraft.sounds.SoundEvents import net.minecraft.sounds.SoundSource import net.minecraft.util.RandomSource +import net.minecraft.world.Containers import net.minecraft.world.InteractionResult import net.minecraft.world.entity.player.Player import net.minecraft.world.level.Level @@ -74,4 +75,15 @@ class CombustionGeneratorBlock : NodeBlock, EntityBlock { level.addParticle(ParticleTypes.FLAME, x+0.5, y+1, z+0.5, 0.0, 0.0, 0.0) } } + + override fun onRemove( + blockState: BlockState, + level: Level, + blockPos: BlockPos, + blockState2: BlockState, + bl: Boolean + ) { + Containers.dropContentsOnDestroy(blockState, blockState2, level, blockPos) + super.onRemove(blockState, level, blockPos, blockState2, bl) + } } diff --git a/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt b/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt index 09b7495..0e6db01 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/CombustionGeneratorBlockEntity.kt @@ -10,12 +10,14 @@ import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerPlayer import net.minecraft.sounds.SoundEvents import net.minecraft.sounds.SoundSource +import net.minecraft.world.ContainerHelper import net.minecraft.world.MenuProvider import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.item.ItemStack import net.minecraft.world.level.Level +import net.minecraft.world.level.block.ChestBlock import net.minecraft.world.level.block.FurnaceBlock import net.minecraft.world.level.block.state.BlockState import org.neoflock.neocomputers.block.CombustionGeneratorBlock @@ -88,12 +90,16 @@ class CombustionGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) } override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) { + super.loadAdditional(compoundTag, provider) node.energy = min(node.energyCapacity, compoundTag.getLong("energy")) burningTimeRemaining = compoundTag.getInt("burningTimeRemaining") + ContainerHelper.loadAllItems(compoundTag, getItems(), provider) } override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) { + super.saveAdditional(compoundTag, provider) compoundTag.putLong("energy", node.energy) compoundTag.putInt("burningTimeRemaining", burningTimeRemaining) + ContainerHelper.saveAllItems(compoundTag, getItems(), provider) } } \ 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 9adfca3..1c099ea 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/entity/SolarGeneratorBlockEntity.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/entity/SolarGeneratorBlockEntity.kt @@ -26,10 +26,12 @@ class SolarGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) : No } override fun loadAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) { + super.loadAdditional(compoundTag, provider) node.energy = compoundTag.getLong("energy") } override fun saveAdditional(compoundTag: CompoundTag, provider: HolderLookup.Provider) { + super.saveAdditional(compoundTag, provider) compoundTag.putLong("energy", node.energy) } } \ No newline at end of file