furnaces and plate presses now store experience into essence storage on job finish and neighbour block update
This commit is contained in:
parent
814328630c
commit
f3da82beaf
@ -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<ItemJob> {
|
||||
|
@ -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<ItemJob>, id: Int) {
|
||||
if (outputs[id].fullyAddItem(status.job.itemStack)) {
|
||||
experience += status.experience
|
||||
tryStoreExperience(null)
|
||||
} else {
|
||||
status.noItem()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user