Rename item handler impl, remove unused code
This commit is contained in:
parent
d66b96c791
commit
e9b753667a
@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.block.entity.decorative
|
|||||||
|
|
||||||
import net.minecraft.advancements.CriteriaTriggers
|
import net.minecraft.advancements.CriteriaTriggers
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.LongTag
|
import net.minecraft.nbt.LongTag
|
||||||
import net.minecraft.nbt.StringTag
|
import net.minecraft.nbt.StringTag
|
||||||
@ -25,14 +24,11 @@ import net.minecraft.world.level.storage.loot.LootContext
|
|||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
||||||
import net.minecraft.world.phys.Vec3
|
import net.minecraft.world.phys.Vec3
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock
|
import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
import ru.dbotthepony.mc.otm.core.nbt.map
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
@ -46,7 +42,7 @@ class CargoCrateBlockEntity(
|
|||||||
) : MatteryDeviceBlockEntity(MBlockEntities.CARGO_CRATE, p_155229_, p_155230_), IDroppableContainer {
|
) : MatteryDeviceBlockEntity(MBlockEntities.CARGO_CRATE, p_155229_, p_155230_), IDroppableContainer {
|
||||||
val container = MatteryContainer(this::setChanged, CAPACITY)
|
val container = MatteryContainer(this::setChanged, CAPACITY)
|
||||||
private var interactingPlayers = 0
|
private var interactingPlayers = 0
|
||||||
val handler = container.handler(object : MatteryContainerHooks {
|
val handler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return lootTable == null
|
return lootTable == null
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.matter
|
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
@ -14,9 +10,6 @@ import net.minecraft.world.level.Level
|
|||||||
import net.minecraft.world.level.block.Block
|
import net.minecraft.world.level.block.Block
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
import net.minecraftforge.common.ForgeConfigSpec
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock
|
import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock
|
||||||
@ -29,21 +22,18 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
|||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||||
import ru.dbotthepony.mc.otm.menu.matter.MatterBottlerMenu
|
import ru.dbotthepony.mc.otm.menu.matter.MatterBottlerMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
import ru.dbotthepony.mc.otm.registry.MNames
|
||||||
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
||||||
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
|
||||||
|
|
||||||
class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||||
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, p_155229_, p_155230_), IMatterGraphNode, IDroppableContainer {
|
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, p_155229_, p_155230_), IMatterGraphNode, IDroppableContainer {
|
||||||
@ -99,7 +89,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
|
|
||||||
override val droppableContainer by ::container
|
override val droppableContainer by ::container
|
||||||
|
|
||||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
if (isBottling) {
|
if (isBottling) {
|
||||||
return slot < 3 && stack.getCapability(MatteryCapability.MATTER).isPresent
|
return slot < 3 && stack.getCapability(MatteryCapability.MATTER).isPresent
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.matter
|
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
@ -13,10 +10,6 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
import net.minecraftforge.common.ForgeConfigSpec
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import net.minecraftforge.items.IItemHandler
|
|
||||||
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||||
@ -27,14 +20,13 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
|||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||||
import ru.dbotthepony.mc.otm.item.MatterDustItem
|
import ru.dbotthepony.mc.otm.item.MatterDustItem
|
||||||
import ru.dbotthepony.mc.otm.menu.matter.MatterDecomposerMenu
|
import ru.dbotthepony.mc.otm.menu.matter.MatterDecomposerMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MItems
|
import ru.dbotthepony.mc.otm.registry.MItems
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
import ru.dbotthepony.mc.otm.registry.MNames
|
||||||
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
||||||
@ -43,7 +35,6 @@ import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
|||||||
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.set
|
import ru.dbotthepony.mc.otm.core.math.set
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterManager
|
import ru.dbotthepony.mc.otm.matter.MatterManager
|
||||||
|
|
||||||
@ -151,7 +142,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState)
|
|||||||
val container = MatteryContainer(this::setChangedLight, 3)
|
val container = MatteryContainer(this::setChangedLight, 3)
|
||||||
override val droppableContainer by ::container
|
override val droppableContainer by ::container
|
||||||
|
|
||||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return slot == INPUT_SLOT && MatterManager.canDecompose(stack)
|
return slot == INPUT_SLOT && MatterManager.canDecompose(stack)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.matter
|
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
@ -14,9 +11,6 @@ import net.minecraft.world.level.Level
|
|||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
import net.minecraftforge.common.ForgeConfigSpec
|
||||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue
|
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||||
@ -27,19 +21,16 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
|||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||||
import ru.dbotthepony.mc.otm.item.MatterDustItem
|
import ru.dbotthepony.mc.otm.item.MatterDustItem
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
|
||||||
import ru.dbotthepony.mc.otm.menu.matter.MatterRecyclerMenu
|
import ru.dbotthepony.mc.otm.menu.matter.MatterRecyclerMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
||||||
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
import ru.dbotthepony.mc.otm.registry.MNames
|
||||||
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
||||||
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
||||||
@ -90,7 +81,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
return matter
|
return matter
|
||||||
}
|
}
|
||||||
|
|
||||||
private val itemHandler = container.handler(object : MatteryContainerHooks {
|
private val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return stack.item is MatterDustItem
|
return stack.item is MatterDustItem
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.matter
|
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
@ -13,9 +10,6 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
import net.minecraftforge.common.ForgeConfigSpec
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||||
@ -25,13 +19,13 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
|||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHandler
|
import ru.dbotthepony.mc.otm.container.ContainerHandler
|
||||||
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||||
import ru.dbotthepony.mc.otm.menu.matter.MatterReplicatorMenu
|
import ru.dbotthepony.mc.otm.menu.matter.MatterReplicatorMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
import ru.dbotthepony.mc.otm.registry.MNames
|
||||||
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
@ -109,7 +103,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
override val matterNode = Graph6Node<IMatterGraphNode>(this)
|
override val matterNode = Graph6Node<IMatterGraphNode>(this)
|
||||||
val matter = MatterStorageImpl(this::matterLevelUpdated, FlowDirection.INPUT, ::MATTER_CAPACITY)
|
val matter = MatterStorageImpl(this::matterLevelUpdated, FlowDirection.INPUT, ::MATTER_CAPACITY)
|
||||||
val container = MatteryContainer(this::itemContainerUpdated, 5)
|
val container = MatteryContainer(this::itemContainerUpdated, 5)
|
||||||
val itemHandler = container.handler(MatteryContainerHandler.OnlyOut)
|
val itemHandler = container.handler(HandlerFilter.OnlyOut)
|
||||||
override val droppableContainer by ::container
|
override val droppableContainer by ::container
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.matter
|
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
@ -13,9 +9,6 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
import net.minecraftforge.common.ForgeConfigSpec
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||||
@ -25,17 +18,15 @@ import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
|||||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternState
|
import ru.dbotthepony.mc.otm.capability.matter.IPatternState
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
||||||
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
|
||||||
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
import ru.dbotthepony.mc.otm.graph.Graph6Node
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphNode
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterNetworkGraph
|
||||||
import ru.dbotthepony.mc.otm.menu.matter.MatterScannerMenu
|
import ru.dbotthepony.mc.otm.menu.matter.MatterScannerMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
import ru.dbotthepony.mc.otm.registry.MNames
|
||||||
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
||||||
import ru.dbotthepony.mc.otm.matter.MatterManager
|
import ru.dbotthepony.mc.otm.matter.MatterManager
|
||||||
@ -47,7 +38,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
|
|
||||||
val container = MatteryContainer(this::itemContainerUpdated, 1)
|
val container = MatteryContainer(this::itemContainerUpdated, 1)
|
||||||
val energy = WorkerEnergyStorage(this::powerLevelUpdated, ENERGY_VALUES)
|
val energy = WorkerEnergyStorage(this::powerLevelUpdated, ENERGY_VALUES)
|
||||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return MatterManager.canDecompose(stack)
|
return MatterManager.canDecompose(stack)
|
||||||
}
|
}
|
||||||
|
@ -2,32 +2,24 @@ package ru.dbotthepony.mc.otm.block.entity.tech
|
|||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
import net.minecraft.core.Direction
|
||||||
import net.minecraft.nbt.CompoundTag
|
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import net.minecraftforge.energy.IEnergyStorage
|
import net.minecraftforge.energy.IEnergyStorage
|
||||||
import org.apache.logging.log4j.LogManager
|
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.*
|
import ru.dbotthepony.mc.otm.capability.*
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.compat.mekanism.Mattery2MekanismEnergyWrapper
|
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
||||||
import ru.dbotthepony.mc.otm.core.math.facingOne
|
import ru.dbotthepony.mc.otm.core.math.facingOne
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
|
||||||
import ru.dbotthepony.mc.otm.core.util.BESubscribeList
|
import ru.dbotthepony.mc.otm.core.util.BESubscribeList
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.BatteryBankMenu
|
import ru.dbotthepony.mc.otm.menu.tech.BatteryBankMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
@ -51,7 +43,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
|
|||||||
|
|
||||||
override val droppableContainer by ::container
|
override val droppableContainer by ::container
|
||||||
private val itemHandler = container.handler(
|
private val itemHandler = container.handler(
|
||||||
object : MatteryContainerHooks {
|
object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return stack.getCapability(ForgeCapabilities.ENERGY).isPresent
|
return stack.getCapability(ForgeCapabilities.ENERGY).isPresent
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.tech
|
package ru.dbotthepony.mc.otm.block.entity.tech
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
@ -14,9 +11,7 @@ import net.minecraft.world.level.block.Block
|
|||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
import net.minecraftforge.common.ForgeConfigSpec
|
||||||
import net.minecraftforge.common.ForgeHooks
|
import net.minecraftforge.common.ForgeHooks
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import net.minecraftforge.energy.IEnergyStorage
|
import net.minecraftforge.energy.IEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||||
@ -25,7 +20,7 @@ import ru.dbotthepony.mc.otm.capability.*
|
|||||||
import ru.dbotthepony.mc.otm.capability.energy.GeneratorEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.GeneratorEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.compat.mekanism.Mattery2MekanismEnergyWrapper
|
import ru.dbotthepony.mc.otm.compat.mekanism.Mattery2MekanismEnergyWrapper
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
|
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
@ -34,7 +29,6 @@ import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
|||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
||||||
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.facingOne
|
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
import ru.dbotthepony.mc.otm.core.nbt.map
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
import ru.dbotthepony.mc.otm.core.util.BESubscribeList
|
import ru.dbotthepony.mc.otm.core.util.BESubscribeList
|
||||||
@ -44,12 +38,11 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
|
|||||||
return ChemicalGeneratorMenu(containerID, inventory, this)
|
return ChemicalGeneratorMenu(containerID, inventory, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var valid = true
|
|
||||||
val container = MatteryContainer(this::setChangedLight, SLOTS)
|
val container = MatteryContainer(this::setChangedLight, SLOTS)
|
||||||
override val droppableContainer by ::container
|
override val droppableContainer by ::container
|
||||||
val energy = GeneratorEnergyStorage(this::setChangedLight, CAPACITY, THROUGHPUT)
|
val energy = GeneratorEnergyStorage(this::setChangedLight, CAPACITY, THROUGHPUT)
|
||||||
|
|
||||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
if (slot == SLOT_INPUT)
|
if (slot == SLOT_INPUT)
|
||||||
return ForgeHooks.getBurnTime(stack, null) > 0
|
return ForgeHooks.getBurnTime(stack, null) > 0
|
||||||
@ -70,13 +63,9 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
savetable(::energy, ENERGY_KEY)
|
savetable(::energy, ENERGY_KEY)
|
||||||
exposeGlobally(ForgeCapabilities.ITEM_HANDLER, itemHandler)
|
savetable(::container, INVENTORY_KEY)
|
||||||
exposeGlobally(ForgeCapabilities.ENERGY, energy)
|
exposeEnergyGlobally(energy)
|
||||||
exposeGlobally(MatteryCapability.ENERGY, energy)
|
exposeItemsGlobally(itemHandler)
|
||||||
|
|
||||||
if (isMekanismLoaded) {
|
|
||||||
exposeGlobally(MatteryCapability.MEKANISM_ENERGY, Mattery2MekanismEnergyWrapper(energy))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val consumers = BESubscribeList(this, ForgeCapabilities.ENERGY)
|
private val consumers = BESubscribeList(this, ForgeCapabilities.ENERGY)
|
||||||
@ -88,20 +77,6 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
|
|||||||
checkFuelSlot = true
|
checkFuelSlot = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidateCaps() {
|
|
||||||
super.invalidateCaps()
|
|
||||||
itemHandler.invalidate()
|
|
||||||
energy.invalidate()
|
|
||||||
valid = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reviveCaps() {
|
|
||||||
super.reviveCaps()
|
|
||||||
itemHandler.revive()
|
|
||||||
energy.revive()
|
|
||||||
valid = true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setLevel(p_155231_: Level) {
|
override fun setLevel(p_155231_: Level) {
|
||||||
super.setLevel(p_155231_)
|
super.setLevel(p_155231_)
|
||||||
tickOnceServer(consumers::update)
|
tickOnceServer(consumers::update)
|
||||||
@ -110,8 +85,6 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
|
|||||||
override fun saveAdditional(nbt: CompoundTag) {
|
override fun saveAdditional(nbt: CompoundTag) {
|
||||||
super.saveAdditional(nbt)
|
super.saveAdditional(nbt)
|
||||||
|
|
||||||
nbt[ENERGY_KEY] = energy.serializeNBT()
|
|
||||||
nbt[INVENTORY_KEY] = container.serializeNBT()
|
|
||||||
nbt[WORK_TICKS_KEY] = workTicks
|
nbt[WORK_TICKS_KEY] = workTicks
|
||||||
nbt[WORK_TICKS_TOTAL_KEY] = workTicksTotal
|
nbt[WORK_TICKS_TOTAL_KEY] = workTicksTotal
|
||||||
}
|
}
|
||||||
@ -119,17 +92,13 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
|
|||||||
override fun load(nbt: CompoundTag) {
|
override fun load(nbt: CompoundTag) {
|
||||||
super.load(nbt)
|
super.load(nbt)
|
||||||
|
|
||||||
nbt.map(ENERGY_KEY, energy::deserializeNBT)
|
|
||||||
container.deserializeNBT(nbt[INVENTORY_KEY])
|
|
||||||
workTicks = nbt.getInt(WORK_TICKS_KEY)
|
workTicks = nbt.getInt(WORK_TICKS_KEY)
|
||||||
workTicksTotal = nbt.getInt(WORK_TICKS_TOTAL_KEY)
|
workTicksTotal = nbt.getInt(WORK_TICKS_TOTAL_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setBlockState(p_155251_: BlockState) {
|
override fun setBlockState(p_155251_: BlockState) {
|
||||||
super.setBlockState(p_155251_)
|
super.setBlockState(p_155251_)
|
||||||
|
tickOnceServer(consumers::update)
|
||||||
if (valid)
|
|
||||||
tickOnceServer(consumers::update)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var workTicks = 0
|
var workTicks = 0
|
||||||
|
@ -7,11 +7,10 @@ import net.minecraft.world.inventory.AbstractContainerMenu
|
|||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.item.Items
|
import net.minecraft.world.item.Items
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.CobblerMenu
|
import ru.dbotthepony.mc.otm.menu.tech.CobblerMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ class CobblerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
|
|
||||||
override val droppableContainer = MatteryContainer(this::itemContainerUpdated, CONTAINER_SIZE)
|
override val droppableContainer = MatteryContainer(this::itemContainerUpdated, CONTAINER_SIZE)
|
||||||
|
|
||||||
val handler = droppableContainer.handler(object : MatteryContainerHooks {
|
val handler = droppableContainer.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.tech
|
package ru.dbotthepony.mc.otm.block.entity.tech
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.world.Container
|
import net.minecraft.world.Container
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
@ -10,14 +8,10 @@ import net.minecraft.world.entity.player.Player
|
|||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
|
||||||
import ru.dbotthepony.mc.otm.capability.canSetBatteryMattery
|
import ru.dbotthepony.mc.otm.capability.canSetBatteryMattery
|
||||||
import ru.dbotthepony.mc.otm.capability.energy
|
import ru.dbotthepony.mc.otm.capability.energy
|
||||||
import ru.dbotthepony.mc.otm.capability.energyStoredMattery
|
import ru.dbotthepony.mc.otm.capability.energyStoredMattery
|
||||||
@ -25,10 +19,8 @@ import ru.dbotthepony.mc.otm.capability.extractEnergy
|
|||||||
import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery
|
import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery
|
||||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.EnergyServoMenu
|
import ru.dbotthepony.mc.otm.menu.tech.EnergyServoMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
import ru.dbotthepony.mc.otm.registry.MBlocks
|
||||||
@ -42,7 +34,7 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte
|
|||||||
override val droppableContainer: Container
|
override val droppableContainer: Container
|
||||||
get() = container
|
get() = container
|
||||||
|
|
||||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return when (slot) {
|
return when (slot) {
|
||||||
SLOT_DISCHARGE -> stack.isEmpty || stack.energy?.let { it.extractEnergy(Int.MAX_VALUE, true) > 0 } ?: false
|
SLOT_DISCHARGE -> stack.isEmpty || stack.energy?.let { it.extractEnergy(Int.MAX_VALUE, true) > 0 } ?: false
|
||||||
|
@ -1,37 +1,24 @@
|
|||||||
package ru.dbotthepony.mc.otm.block.entity.tech
|
package ru.dbotthepony.mc.otm.block.entity.tech
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.Direction
|
|
||||||
import net.minecraft.nbt.CompoundTag
|
|
||||||
import net.minecraft.network.chat.Component
|
|
||||||
import net.minecraft.server.level.ServerLevel
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.ExperienceOrb
|
import net.minecraft.world.entity.ExperienceOrb
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.capabilities.Capability
|
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import ru.dbotthepony.mc.otm.config.ServerConfig
|
|
||||||
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
import ru.dbotthepony.mc.otm.block.IDroppableContainer
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainerHooks
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu
|
import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.registry.MRecipes
|
import ru.dbotthepony.mc.otm.registry.MRecipes
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
|
||||||
import ru.dbotthepony.mc.otm.once
|
|
||||||
import ru.dbotthepony.mc.otm.onceServer
|
|
||||||
|
|
||||||
class PlatePressBlockEntity(
|
class PlatePressBlockEntity(
|
||||||
p_155229_: BlockPos,
|
p_155229_: BlockPos,
|
||||||
@ -52,7 +39,7 @@ class PlatePressBlockEntity(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val droppableContainer by ::container
|
override val droppableContainer by ::container
|
||||||
val itemHandler = container.handler(object : MatteryContainerHooks {
|
val itemHandler = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
return slot != SLOT_OUTPUT
|
return slot != SLOT_OUTPUT
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.container
|
||||||
|
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import net.minecraftforge.common.util.LazyOptional
|
||||||
|
import net.minecraftforge.items.IItemHandler
|
||||||
|
|
||||||
|
class ContainerHandler @JvmOverloads internal constructor(
|
||||||
|
private val container: MatteryContainer,
|
||||||
|
private val filter: HandlerFilter = HandlerFilter.Both,
|
||||||
|
) : IItemHandler {
|
||||||
|
override fun getSlots() = container.containerSize
|
||||||
|
override fun getStackInSlot(slot: Int) = container[slot]
|
||||||
|
|
||||||
|
override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean): ItemStack {
|
||||||
|
if (!filter.canInsert(slot, stack))
|
||||||
|
return stack
|
||||||
|
|
||||||
|
filter.preInsert(slot, stack, simulate)
|
||||||
|
val localStack = container[slot]
|
||||||
|
|
||||||
|
if (localStack.isEmpty) {
|
||||||
|
if (!simulate) {
|
||||||
|
val copy = stack.copy()
|
||||||
|
container.setChanged(slot, copy, ItemStack.EMPTY)
|
||||||
|
container.setItem(slot, copy)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
} else if (localStack.isStackable && localStack.maxStackSize > localStack.count && ItemStack.isSameItemSameTags(localStack, stack)) {
|
||||||
|
val newCount = localStack.maxStackSize.coerceAtMost(localStack.count + stack.count)
|
||||||
|
val diff = newCount - localStack.count
|
||||||
|
|
||||||
|
if (diff != 0) {
|
||||||
|
if (!simulate) {
|
||||||
|
val old = localStack.copy()
|
||||||
|
localStack.grow(diff)
|
||||||
|
container.setChanged(slot, localStack, old)
|
||||||
|
}
|
||||||
|
|
||||||
|
val copy = stack.copy()
|
||||||
|
copy.shrink(diff)
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun extractItem(slot: Int, amount: Int, simulate: Boolean): ItemStack {
|
||||||
|
if (amount == 0)
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
|
||||||
|
require(amount >= 0) { "Can not extract negative amount of items" }
|
||||||
|
|
||||||
|
filter.preExtract(slot, amount, simulate)
|
||||||
|
|
||||||
|
val localStack = container.getItem(slot)
|
||||||
|
if (localStack.isEmpty) return ItemStack.EMPTY
|
||||||
|
if (!filter.canExtract(slot, amount, localStack)) return ItemStack.EMPTY
|
||||||
|
|
||||||
|
val minimal = amount.coerceAtMost(localStack.count)
|
||||||
|
val copy = localStack.copy()
|
||||||
|
copy.count = minimal
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
|
val old = localStack.copy()
|
||||||
|
localStack.shrink(minimal)
|
||||||
|
container.setChanged(slot, localStack, old)
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSlotLimit(slot: Int): Int {
|
||||||
|
return container.maxStackSize
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isItemValid(slot: Int, stack: ItemStack): Boolean {
|
||||||
|
return filter.canInsert(slot, stack)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.container
|
||||||
|
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
|
||||||
|
interface HandlerFilter {
|
||||||
|
fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun preInsert(slot: Int, stack: ItemStack, simulate: Boolean) {}
|
||||||
|
fun preExtract(slot: Int, amount: Int, simulate: Boolean) {}
|
||||||
|
|
||||||
|
object OnlyIn : HandlerFilter {
|
||||||
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object OnlyOut : HandlerFilter {
|
||||||
|
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object Both : HandlerFilter
|
||||||
|
}
|
@ -148,28 +148,28 @@ open class MatteryContainer(val watcher: Runnable, private val size: Int) : Cont
|
|||||||
fun handler(
|
fun handler(
|
||||||
insert_validator: (slot: Int, stack: ItemStack) -> Boolean,
|
insert_validator: (slot: Int, stack: ItemStack) -> Boolean,
|
||||||
extract_validator: (slot: Int, amount: Int, stack: ItemStack) -> Boolean
|
extract_validator: (slot: Int, amount: Int, stack: ItemStack) -> Boolean
|
||||||
): MatteryContainerHandler {
|
): ContainerHandler {
|
||||||
return MatteryContainerHandler(this, object : MatteryContainerHooks {
|
return ContainerHandler(this, object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack)
|
override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack)
|
||||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = extract_validator(slot, amount, stack)
|
override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = extract_validator(slot, amount, stack)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handler(
|
fun handler(
|
||||||
filter: MatteryContainerHooks
|
filter: HandlerFilter
|
||||||
): MatteryContainerHandler {
|
): ContainerHandler {
|
||||||
return MatteryContainerHandler(this, filter)
|
return ContainerHandler(this, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handler(insert_validator: (Int, ItemStack) -> Boolean): MatteryContainerHandler {
|
fun handler(insert_validator: (Int, ItemStack) -> Boolean): ContainerHandler {
|
||||||
return MatteryContainerHandler(this, object : MatteryContainerHooks {
|
return ContainerHandler(this, object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack)
|
override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack)
|
||||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = false
|
override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handler(): MatteryContainerHandler {
|
fun handler(): ContainerHandler {
|
||||||
return MatteryContainerHandler(this)
|
return ContainerHandler(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getMaxStackSize(slot: Int) = maxStackSize
|
open fun getMaxStackSize(slot: Int) = maxStackSize
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
package ru.dbotthepony.mc.otm.container
|
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack
|
|
||||||
import net.minecraftforge.common.util.LazyOptional
|
|
||||||
import net.minecraftforge.items.IItemHandler
|
|
||||||
|
|
||||||
interface MatteryContainerHooks {
|
|
||||||
fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun preInsert(slot: Int, stack: ItemStack, simulate: Boolean) {}
|
|
||||||
fun preExtract(slot: Int, amount: Int, simulate: Boolean) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MatteryContainerHandler @JvmOverloads internal constructor(
|
|
||||||
private val container: MatteryContainer,
|
|
||||||
private val hooks: MatteryContainerHooks = Both,
|
|
||||||
) : IItemHandler {
|
|
||||||
object OnlyIn : MatteryContainerHooks {
|
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object OnlyOut : MatteryContainerHooks {
|
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object Both : MatteryContainerHooks
|
|
||||||
|
|
||||||
private var handler = LazyOptional.of<IItemHandler> { this }
|
|
||||||
|
|
||||||
fun get(): LazyOptional<IItemHandler> {
|
|
||||||
return handler
|
|
||||||
}
|
|
||||||
|
|
||||||
fun invalidate() {
|
|
||||||
handler.invalidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun revive() {
|
|
||||||
handler = LazyOptional.of { this }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSlots() = container.containerSize
|
|
||||||
override fun getStackInSlot(slot: Int) = container[slot]
|
|
||||||
|
|
||||||
override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean): ItemStack {
|
|
||||||
if (!hooks.canInsert(slot, stack))
|
|
||||||
return stack
|
|
||||||
|
|
||||||
hooks.preInsert(slot, stack, simulate)
|
|
||||||
val localStack = container[slot]
|
|
||||||
|
|
||||||
if (localStack.isEmpty) {
|
|
||||||
if (!simulate) {
|
|
||||||
val copy = stack.copy()
|
|
||||||
container.setChanged(slot, copy, ItemStack.EMPTY)
|
|
||||||
container.setItem(slot, copy)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ItemStack.EMPTY
|
|
||||||
} else if (localStack.isStackable && localStack.maxStackSize > localStack.count && ItemStack.isSameItemSameTags(localStack, stack)) {
|
|
||||||
val newCount = Math.min(localStack.maxStackSize, localStack.count + stack.count)
|
|
||||||
val diff = newCount - localStack.count
|
|
||||||
|
|
||||||
if (diff != 0) {
|
|
||||||
if (!simulate) {
|
|
||||||
val copy = localStack.copy()
|
|
||||||
localStack.grow(diff)
|
|
||||||
container.setChanged(slot, localStack, copy)
|
|
||||||
}
|
|
||||||
|
|
||||||
val copy = stack.copy()
|
|
||||||
copy.shrink(diff)
|
|
||||||
return copy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extractItem(slot: Int, amount: Int, simulate: Boolean): ItemStack {
|
|
||||||
if (amount == 0)
|
|
||||||
return ItemStack.EMPTY
|
|
||||||
|
|
||||||
require(amount >= 0) { "Can not extract negative amount of items" }
|
|
||||||
|
|
||||||
hooks.preExtract(slot, amount, simulate)
|
|
||||||
|
|
||||||
val localStack = container.getItem(slot)
|
|
||||||
if (localStack.isEmpty) return ItemStack.EMPTY
|
|
||||||
if (!hooks.canExtract(slot, amount, localStack)) return ItemStack.EMPTY
|
|
||||||
|
|
||||||
val minimal = Math.min(amount, localStack.count)
|
|
||||||
val copy = localStack.copy()
|
|
||||||
copy.count = minimal
|
|
||||||
|
|
||||||
if (!simulate) {
|
|
||||||
val copy = localStack.copy()
|
|
||||||
localStack.shrink(minimal)
|
|
||||||
container.setChanged(slot, localStack, copy)
|
|
||||||
}
|
|
||||||
|
|
||||||
return copy
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSlotLimit(slot: Int): Int {
|
|
||||||
return container.maxStackSize
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isItemValid(slot: Int, stack: ItemStack): Boolean {
|
|
||||||
return hooks.canInsert(slot, stack)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user