From f3da82beaf40c2d62ddef8004cfbee0fbb3907f5 Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Sun, 29 Oct 2023 01:25:54 +0300 Subject: [PATCH] furnaces and plate presses now store experience into essence storage on job finish and neighbour block update --- .../entity/tech/PlatePressBlockEntity.kt | 23 +++++++++++++++++++ .../entity/tech/PoweredFurnaceBlockEntity.kt | 23 +++++++++++++++++++ .../mc/otm/block/tech/PlatePressBlock.kt | 21 +++++++++++++++++ .../mc/otm/block/tech/PoweredFurnaceBlock.kt | 21 +++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt index 27823bfcf..a570ee003 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt @@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block.entity.tech import it.unimi.dsi.fastutil.ints.IntArrayList import net.minecraft.core.BlockPos +import net.minecraft.core.Direction import net.minecraft.server.level.ServerLevel import net.minecraft.server.level.ServerPlayer import net.minecraft.world.entity.ExperienceOrb @@ -50,6 +51,27 @@ class PlatePressBlockEntity( } } + fun tryStoreExperience(essenceStorage: EssenceStorageBlockEntity?) { + if (experience <= 0.0) return + + if (essenceStorage != null) { + essenceStorage.experienceStored += experience.toLong() + experience = 0.0 + + return + } + + for (dir in Direction.entries) { + val tile = level?.getBlockEntity(blockPos.relative(dir)) ?: continue + + if (tile is EssenceStorageBlockEntity) { + tryStoreExperience(tile) + + break + } + } + } + val energyConfig = ConfigurableEnergy(energy) val itemConfig = ConfigurableItemHandler( input = inputContainer.handler(HandlerFilter.OnlyIn), @@ -79,6 +101,7 @@ class PlatePressBlockEntity( return status.noItem() experience = (experience + status.experience).coerceAtMost(100.0) + tryStoreExperience(null) } override fun computeNextJob(id: Int): JobContainer { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt index b853d37be..c5c59bc98 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PoweredFurnaceBlockEntity.kt @@ -1,6 +1,7 @@ package ru.dbotthepony.mc.otm.block.entity.tech import net.minecraft.core.BlockPos +import net.minecraft.core.Direction import net.minecraft.server.level.ServerLevel import net.minecraft.server.level.ServerPlayer import net.minecraft.world.entity.ExperienceOrb @@ -66,6 +67,27 @@ class PoweredFurnaceBlockEntity( } } + fun tryStoreExperience(essenceStorage: EssenceStorageBlockEntity?) { + if (experience <= 0.0) return + + if (essenceStorage != null) { + essenceStorage.experienceStored += experience.toLong() + experience = 0.0 + + return + } + + for (dir in Direction.entries) { + val tile = level?.getBlockEntity(blockPos.relative(dir)) ?: continue + + if (tile is EssenceStorageBlockEntity) { + tryStoreExperience(tile) + + break + } + } + } + init { savetables.stateful(::upgrades) savetables.stateful(::energy) @@ -98,6 +120,7 @@ class PoweredFurnaceBlockEntity( override fun onJobFinish(status: JobStatus, id: Int) { if (outputs[id].fullyAddItem(status.job.itemStack)) { experience += status.experience + tryStoreExperience(null) } else { status.noItem() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt index 22c3aeca4..83428bc32 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PlatePressBlock.kt @@ -19,6 +19,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.block.entity.tech.EssenceStorageBlockEntity import ru.dbotthepony.mc.otm.block.getShapeForEachState import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.shapes.BlockShapes @@ -65,4 +66,24 @@ class PlatePressBlock(properties: Properties = DEFAULT_PROPERTIES, val isTwin: B ): VoxelShape { return shapes[state]!! } + + @Suppress("OVERRIDE_DEPRECATION") + override fun neighborChanged( + state: BlockState, + level: Level, + pos: BlockPos, + neighbour: Block, + neighbourPos: BlockPos, + movedByPiston: Boolean + ) { + super.neighborChanged(state, level, pos, neighbour, neighbourPos, movedByPiston) + + val tile = level.getBlockEntity(pos) ?: return + val neighbourTile = level.getBlockEntity(neighbourPos) ?: return + + if (tile.isRemoved || neighbourTile.isRemoved) return + if (tile is PlatePressBlockEntity && neighbourTile is EssenceStorageBlockEntity) { + tile.tryStoreExperience(neighbourTile) + } + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PoweredFurnaceBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PoweredFurnaceBlock.kt index 747014792..c20ef5be8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PoweredFurnaceBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/tech/PoweredFurnaceBlock.kt @@ -17,6 +17,7 @@ import net.minecraft.world.phys.shapes.Shapes import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.entity.WorkerState +import ru.dbotthepony.mc.otm.block.entity.tech.EssenceStorageBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.PoweredFurnaceBlockEntity import ru.dbotthepony.mc.otm.block.getShapeForEachState import ru.dbotthepony.mc.otm.config.WorkerBalanceValues @@ -58,4 +59,24 @@ class PoweredFurnaceBlock( return BlockEntityTicker { _, _, _, tile -> if (tile is PoweredFurnaceBlockEntity) tile.tick() } } + + @Suppress("OVERRIDE_DEPRECATION") + override fun neighborChanged( + state: BlockState, + level: Level, + pos: BlockPos, + neighbour: Block, + neighbourPos: BlockPos, + movedByPiston: Boolean + ) { + super.neighborChanged(state, level, pos, neighbour, neighbourPos, movedByPiston) + + val tile = level.getBlockEntity(pos) ?: return + val neighbourTile = level.getBlockEntity(neighbourPos) ?: return + + if (tile.isRemoved || neighbourTile.isRemoved) return + if (tile is PoweredFurnaceBlockEntity && neighbourTile is EssenceStorageBlockEntity) { + tile.tryStoreExperience(neighbourTile) + } + } }