Update Matter recycler to use Slotted Container

This commit is contained in:
DBotThePony 2025-03-06 20:31:28 +07:00
parent f8e9a67994
commit e8ba5916b1
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 17 additions and 16 deletions

View File

@ -21,8 +21,8 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage
import ru.dbotthepony.mc.otm.config.MachinesConfig
import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.container.HandlerFilter
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.otmRandom
import ru.dbotthepony.mc.otm.graph.matter.MatterGraph
@ -33,9 +33,7 @@ import ru.dbotthepony.mc.otm.data.codec.DecimalCodec
import ru.dbotthepony.mc.otm.data.codec.minRange
import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
: MatteryWorkerBlockEntity<MatterRecyclerBlockEntity.RecyclerJob>(MBlockEntities.MATTER_RECYCLER, blockPos, blockState, RecyclerJob.CODEC) {
class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryWorkerBlockEntity<MatterRecyclerBlockEntity.RecyclerJob>(MBlockEntities.MATTER_RECYCLER, blockPos, blockState, RecyclerJob.CODEC) {
class RecyclerJob(ticks: Double, powerUsage: Decimal, var totalMatter: Decimal) : Job(ticks, powerUsage) {
companion object {
val CODEC: Codec<RecyclerJob> by lazy {
@ -48,20 +46,22 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
override val upgrades = makeUpgrades(3, UpgradeType.BASIC_MATTER)
val matter = ProfiledMatterStorage(MatterStorageImpl(::matterLevelUpdated, FlowDirection.OUTPUT, upgrades.matterCapacity(MachinesConfig.MatterRecycler.VALUES::matterCapacity)))
val container = MatteryContainer(::itemContainerUpdated, 1).also(::addDroppableContainer)
private class Slot(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
override fun canAutomationTakeItem(desired: Int): Boolean {
return false
}
override fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
return super.canAutomationPlaceItem(itemStack) && itemStack.item is MatterDustItem
}
}
val container = SlottedContainer.simple(1, ::Slot, ::itemContainerUpdated).also(::addDroppableContainer)
val matterNode = SimpleMatterNode(matter = matter)
override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::energyLevelUpdated, upgrades.transform(MachinesConfig.MatterRecycler.VALUES)))
val itemConfig = ConfigurableItemHandler(input = container.handler(object : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return stack.item is MatterDustItem
}
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
return false
}
}))
val itemConfig = ConfigurableItemHandler(container)
val energyConfig = ConfigurableEnergy(energy)

View File

@ -4,6 +4,7 @@ import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity
import ru.dbotthepony.mc.otm.container.EnhancedContainer
import ru.dbotthepony.mc.otm.item.matter.MatterDustItem
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
@ -20,7 +21,7 @@ class MatterRecyclerMenu @JvmOverloads constructor(
inventory: Inventory,
tile: MatterRecyclerBlockEntity? = null
) : MatteryPoweredMenu(MMenus.MATTER_RECYCLER, containerID, inventory, tile) {
val input = object : MatteryMenuSlot(tile?.container ?: SimpleContainer(1), 0) {
val input = object : MatteryMenuSlot(tile?.container ?: EnhancedContainer(1), 0) {
override fun mayPlace(itemStack: ItemStack): Boolean {
return itemStack.item is MatterDustItem && (itemStack.item as MatterDustItem).getMatterValue(itemStack) != null
}