Compare commits
8 Commits
7c6d58b782
...
95f19bc18f
Author | SHA1 | Date | |
---|---|---|---|
95f19bc18f | |||
df5c8dc6aa | |||
d5a9632c97 | |||
cf32fd9d2a | |||
427b5f9179 | |||
f599f1c2b9 | |||
fd9960bd86 | |||
962ecb1996 |
@ -6,7 +6,6 @@ import net.minecraft.world.level.block.state.BlockState
|
||||
import ru.dbotthepony.mc.otm.capability.energy
|
||||
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.extractEnergy
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
|
@ -29,7 +29,6 @@ import net.minecraft.world.phys.Vec3
|
||||
import net.neoforged.neoforge.capabilities.Capabilities
|
||||
import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
|
@ -18,7 +18,6 @@ import ru.dbotthepony.mc.otm.capability.item.CombinedItemHandler
|
||||
import ru.dbotthepony.mc.otm.capability.fluid.BlockMatteryFluidHandler
|
||||
import ru.dbotthepony.mc.otm.capability.moveFluid
|
||||
import ru.dbotthepony.mc.otm.config.ItemsConfig
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.get
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
|
@ -18,7 +18,6 @@ import net.neoforged.neoforge.capabilities.Capabilities
|
||||
import net.neoforged.neoforge.fluids.FluidStack
|
||||
import net.neoforged.neoforge.fluids.capability.IFluidHandler
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||
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.immutableList
|
||||
|
@ -21,7 +21,6 @@ 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.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.UpgradeContainer
|
||||
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
|
@ -16,7 +16,6 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||
import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage
|
||||
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.immutableList
|
||||
|
@ -21,7 +21,6 @@ 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.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
@ -110,10 +109,15 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState)
|
||||
if (!status.job.matterValue.isZero)
|
||||
status.throttleFast()
|
||||
} else {
|
||||
status.job.matterValue -= matter.receiveMatter(status.job.matterValue, false)
|
||||
val received = matter.receiveMatter(status.job.matterValue, false)
|
||||
status.job.matterValue -= received
|
||||
|
||||
if (status.job.matterValue.isPositive)
|
||||
status.noMatter()
|
||||
if (status.job.matterValue.isPositive) {
|
||||
if (received.isPositive)
|
||||
status.noMatter(1)
|
||||
else
|
||||
status.noMatter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||
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.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.UpgradeContainer
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
|
@ -25,7 +25,6 @@ import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
|
@ -20,7 +20,6 @@ import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.matter.PatternState
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
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.menu.matter.MatterScannerMenu
|
||||
|
@ -19,7 +19,6 @@ import ru.dbotthepony.mc.otm.capability.energyStoredMattery
|
||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||
import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery
|
||||
import ru.dbotthepony.mc.otm.capability.transcieveEnergy
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
|
@ -12,7 +12,6 @@ import ru.dbotthepony.mc.otm.capability.*
|
||||
import ru.dbotthepony.mc.otm.capability.energy.GeneratorEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
|
||||
|
@ -11,7 +11,6 @@ import ru.dbotthepony.mc.otm.block.entity.ItemJob
|
||||
import ru.dbotthepony.mc.otm.block.entity.JobContainer
|
||||
import ru.dbotthepony.mc.otm.block.entity.JobStatus
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.menu.tech.CobblerMenu
|
||||
|
@ -16,7 +16,6 @@ import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.moveEnergy
|
||||
import ru.dbotthepony.mc.otm.config.EnergyBalanceValues
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
||||
|
@ -18,7 +18,6 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||
import ru.dbotthepony.mc.otm.capability.energy.CombinedProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.moveEnergy
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
||||
|
@ -16,7 +16,6 @@ import ru.dbotthepony.mc.otm.capability.extractEnergy
|
||||
import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery
|
||||
import ru.dbotthepony.mc.otm.capability.moveEnergy
|
||||
import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
|
@ -24,7 +24,6 @@ import ru.dbotthepony.mc.otm.block.tech.EssenceStorageBlock
|
||||
import ru.dbotthepony.mc.otm.capability.item.CombinedItemHandler
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
import ru.dbotthepony.mc.otm.container.EnhancedContainer
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
|
@ -9,7 +9,6 @@ import net.minecraft.world.level.block.state.BlockState
|
||||
import net.neoforged.neoforge.capabilities.Capabilities
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||
import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.multiblock.BlockEntityTag
|
||||
|
@ -15,7 +15,6 @@ import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||
import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage
|
||||
import ru.dbotthepony.mc.otm.capability.moveMatter
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
|
@ -18,7 +18,6 @@ import ru.dbotthepony.mc.otm.capability.UpgradeType
|
||||
import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||
import ru.dbotthepony.mc.otm.config.MachinesConfig
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.balance
|
||||
import ru.dbotthepony.mc.otm.container.slotted.AutomationFilters
|
||||
import ru.dbotthepony.mc.otm.container.slotted.FilteredContainerSlot
|
||||
|
@ -35,8 +35,8 @@ import ru.dbotthepony.mc.otm.core.immutableList
|
||||
import ru.dbotthepony.mc.otm.core.math.RelativeSide
|
||||
import ru.dbotthepony.mc.otm.core.util.ItemStackSorter
|
||||
import ru.dbotthepony.mc.otm.core.util.getLevelFromXp
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
|
||||
import ru.dbotthepony.mc.otm.menu.SortInput
|
||||
import ru.dbotthepony.mc.otm.menu.UpgradeSlots
|
||||
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
||||
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
|
||||
@ -449,7 +449,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
||||
return result
|
||||
}
|
||||
|
||||
fun sortingButtons(input: MatteryMenu.SortInput, unfoldableSettings: Boolean = true) {
|
||||
fun sortingButtons(input: SortInput, unfoldableSettings: Boolean = true) {
|
||||
object : ButtonPanel<S>(screen, this@DeviceControls, width = 18f, height = 18f) {
|
||||
var buttons: List<EditablePanel<*>>? = null
|
||||
|
||||
|
@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.MenuType
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
|
||||
import ru.dbotthepony.mc.otm.menu.SortInput
|
||||
|
||||
abstract class AbstractVanillaChestMenu(
|
||||
type: MenuType<*>,
|
||||
@ -17,7 +18,7 @@ abstract class AbstractVanillaChestMenu(
|
||||
abstract val columns: Int
|
||||
|
||||
abstract val containerSlots: List<MatteryMenuSlot>
|
||||
val sort = SortInput(container, playerSortSettings)
|
||||
val sort = SortInput(this, container, playerSortSettings)
|
||||
|
||||
override fun stillValid(player: Player): Boolean {
|
||||
return container.stillValid(player)
|
||||
|
@ -1,153 +0,0 @@
|
||||
package ru.dbotthepony.mc.otm.container
|
||||
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.neoforged.neoforge.capabilities.Capabilities
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.fluid.stream
|
||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
|
||||
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) {}
|
||||
|
||||
fun modifyInsertCount(slot: Int, stack: ItemStack, existing: ItemStack, simulate: Boolean): Int {
|
||||
return stack.count
|
||||
}
|
||||
|
||||
fun modifyExtractCount(slot: Int, amount: Int, simulate: Boolean): Int {
|
||||
return amount
|
||||
}
|
||||
|
||||
fun and(other: HandlerFilter): HandlerFilter {
|
||||
return object : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return this@HandlerFilter.canInsert(slot, stack) && other.canInsert(slot, stack)
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return this@HandlerFilter.canExtract(slot, amount, stack) && other.canExtract(slot, amount, stack)
|
||||
}
|
||||
|
||||
override fun preInsert(slot: Int, stack: ItemStack, simulate: Boolean) {
|
||||
this@HandlerFilter.preInsert(slot, stack, simulate)
|
||||
other.preInsert(slot, stack, simulate)
|
||||
}
|
||||
|
||||
override fun preExtract(slot: Int, amount: Int, simulate: Boolean) {
|
||||
this@HandlerFilter.preExtract(slot, amount, simulate)
|
||||
other.preExtract(slot, amount, simulate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object FluidContainers : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(Capabilities.FluidHandler.ITEM)?.let { it.tanks > 0 } ?: false
|
||||
}
|
||||
}
|
||||
|
||||
object DrainableFluidContainers : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(Capabilities.FluidHandler.ITEM)?.let { it.stream().anyMatch { it.isNotEmpty } } ?: false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return !canInsert(slot, stack)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
object Dischargeable : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { it.canExtract() && it.extractEnergy(Int.MAX_VALUE, true) > 0 } ?: false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canExtract() || it.extractEnergy(Int.MAX_VALUE, true) <= 0 } ?: true
|
||||
}
|
||||
}
|
||||
|
||||
object Chargeable : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { it.canReceive() && it.receiveEnergy(Int.MAX_VALUE, true) > 0 } ?: false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(Capabilities.EnergyStorage.ITEM)?.let { !it.canReceive() || it.receiveEnergy(Int.MAX_VALUE, true) <= 0 } ?: true
|
||||
}
|
||||
}
|
||||
|
||||
object ChemicalFuel : HandlerFilter {
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return stack.getBurnTime(null) <= 0
|
||||
}
|
||||
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getBurnTime(null) > 0
|
||||
}
|
||||
}
|
||||
|
||||
object IsPattern : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(MatteryCapability.PATTERN_ITEM) != null
|
||||
}
|
||||
}
|
||||
|
||||
object MatterProviders : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(MatteryCapability.MATTER_ITEM)
|
||||
?.let { it.matterFlow.output && it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
|
||||
?: false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(MatteryCapability.MATTER_ITEM)
|
||||
?.let { !it.matterFlow.output || it.extractMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
|
||||
?: false
|
||||
}
|
||||
}
|
||||
|
||||
object MatterConsumers : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(MatteryCapability.MATTER_ITEM)
|
||||
?.let { it.matterFlow.input && it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) > Decimal.ZERO }
|
||||
?: false
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return stack.getCapability(MatteryCapability.MATTER_ITEM)
|
||||
?.let { !it.matterFlow.input || it.receiveMatterChecked(Decimal.POSITIVE_INFINITY, true) <= Decimal.ZERO }
|
||||
?: false
|
||||
}
|
||||
}
|
||||
}
|
@ -17,8 +17,8 @@ object WitheredSkeletonSpawnHandler {
|
||||
val entity = event.entity
|
||||
|
||||
if (entity is WitherSkeleton) {
|
||||
val giveHelmet = event.level.otmRandom.nextFloat() < ServerConfig.WITHER_SKELETON_HELMET_CHANCE
|
||||
val giveSword = event.level.otmRandom.nextFloat() < ServerConfig.WITHER_SKELETON_SWORD_CHANCE
|
||||
val giveHelmet = event.level.otmRandom.nextDouble() < ServerConfig.WITHER_SKELETON_HELMET_CHANCE
|
||||
val giveSword = event.level.otmRandom.nextDouble() < ServerConfig.WITHER_SKELETON_SWORD_CHANCE
|
||||
|
||||
if (giveHelmet) {
|
||||
if (!entity.hasItemInSlot(EquipmentSlot.HEAD))
|
||||
|
@ -135,7 +135,7 @@ class ExopackInventoryMenu(val capability: MatteryPlayer) : MatteryMenu(null, CO
|
||||
}
|
||||
}
|
||||
|
||||
sortEnderChest = SortInput(player.enderChestInventory, playerEnderSortSettings)
|
||||
sortEnderChest = SortInput(this, player.enderChestInventory, playerEnderSortSettings)
|
||||
} else {
|
||||
enderChestSlots = listOf()
|
||||
sortEnderChest = null
|
||||
|
@ -3,8 +3,6 @@ package ru.dbotthepony.mc.otm.menu
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.mojang.datafixers.util.Pair
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrayList
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||
import it.unimi.dsi.fastutil.ints.IntCollection
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceArrayList
|
||||
@ -15,7 +13,6 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.Container
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||
@ -41,8 +38,6 @@ import ru.dbotthepony.mc.otm.compat.curios.curiosSlots
|
||||
import ru.dbotthepony.mc.otm.compat.curios.isCurioSlot
|
||||
import ru.dbotthepony.mc.otm.container.IEnhancedContainer
|
||||
import ru.dbotthepony.mc.otm.container.IFilteredContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.computeSortedIndices
|
||||
import ru.dbotthepony.mc.otm.container.sortWithIndices
|
||||
import ru.dbotthepony.mc.otm.container.util.containerSlotOrNull
|
||||
import ru.dbotthepony.mc.otm.core.ResourceLocation
|
||||
import ru.dbotthepony.mc.otm.core.collect.ConditionalSet
|
||||
@ -165,16 +160,6 @@ abstract class MatteryMenu(
|
||||
}
|
||||
}
|
||||
|
||||
inner class SortInput(val container: Container, val settings: IItemStackSortingSettings) {
|
||||
val input = PlayerInput(MatteryStreamCodec.Collection<RegistryFriendlyByteBuf, Int, IntCollection>(StreamCodecs.VAR_INT, ::IntArrayList)) {
|
||||
container.sortWithIndices(it)
|
||||
}
|
||||
|
||||
fun clientInput() {
|
||||
input.accept(container.computeSortedIndices(settings.actualComparator))
|
||||
}
|
||||
}
|
||||
|
||||
fun oneWayInput(allowSpectators: Boolean = false, handler: () -> Unit): PlayerInput<Nothing?> {
|
||||
return PlayerInput(StreamCodecs.NOTHING, allowSpectators) {
|
||||
handler.invoke()
|
||||
@ -316,7 +301,7 @@ abstract class MatteryMenu(
|
||||
_exopackChargeSlots.add(BatteryMenuSlot(mattery.exopackChargeSlots, i, direction = FlowDirection.INPUT).also { mapQuickMoveToExternal(it); mapQuickMoveToInventory(it); addSlot(it) })
|
||||
}
|
||||
|
||||
sortInventoryInput = SortInput(mattery.inventoryAndExopackNoHotbar, playerSortSettings)
|
||||
sortInventoryInput = SortInput(this, mattery.inventoryAndExopackNoHotbar, playerSortSettings)
|
||||
}
|
||||
|
||||
private var broadcastOnce = false
|
||||
@ -469,7 +454,7 @@ abstract class MatteryMenu(
|
||||
|
||||
if (target.any { it.any { it.containerSlotOrNull() is IFilteredContainerSlot } }) {
|
||||
for (collection in target) {
|
||||
if (moveItemStackTo(slot, collection, onlyFiltered = true)) {
|
||||
if (moveItemStackTo(ply, slot, collection, onlyFiltered = true)) {
|
||||
any = true
|
||||
|
||||
if (!slot.hasItem()) {
|
||||
@ -480,7 +465,7 @@ abstract class MatteryMenu(
|
||||
}
|
||||
|
||||
for (collection in target) {
|
||||
if (moveItemStackTo(slot, collection)) {
|
||||
if (moveItemStackTo(ply, slot, collection)) {
|
||||
any = true
|
||||
|
||||
if (!slot.hasItem()) {
|
||||
@ -527,95 +512,6 @@ abstract class MatteryMenu(
|
||||
return true
|
||||
}
|
||||
|
||||
fun moveItemStackTo(
|
||||
source: Slot,
|
||||
slots: Collection<Slot>,
|
||||
onlyFiltered: Boolean = false
|
||||
): Boolean {
|
||||
val remainder = moveItemStackToSlots(source.item, slots, onlyFiltered = onlyFiltered)
|
||||
|
||||
if (remainder.count == source.item.count) {
|
||||
return false
|
||||
}
|
||||
|
||||
val copy = source.item.copy()
|
||||
|
||||
if (remainder.isEmpty) {
|
||||
source.setByPlayer(ItemStack.EMPTY)
|
||||
source.onTake(player, copy)
|
||||
} else {
|
||||
copy.count = source.item.count - remainder.count
|
||||
source.item.count = remainder.count
|
||||
source.onTake(player, copy)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun moveItemStackToSlots(item: ItemStack, slots: Collection<Slot>, simulate: Boolean = false, onlyFiltered: Boolean = false): ItemStack {
|
||||
if (item.isEmpty) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
val copy = item.copy()
|
||||
|
||||
// first pass - stack with existing slots
|
||||
if (copy.isStackable) {
|
||||
for (slot in slots) {
|
||||
if (onlyFiltered && slot.containerSlotOrNull().let { it !is IFilteredContainerSlot || it.filter == null || !it.testSlotFilter(item) }) {
|
||||
continue
|
||||
} else if (!onlyFiltered && slot.containerSlotOrNull().let { it is IFilteredContainerSlot && it.filter != null }) {
|
||||
continue
|
||||
}
|
||||
|
||||
val limit = slot.getMaxStackSize(copy)
|
||||
|
||||
if (limit > slot.item.count && slot.mayPlace(item) && ItemStack.isSameItemSameComponents(slot.item, copy)) {
|
||||
val newCount = (slot.item.count + copy.count).coerceAtMost(limit)
|
||||
val diff = newCount - slot.item.count
|
||||
copy.count -= diff
|
||||
|
||||
if (!simulate) {
|
||||
slot.item.count += diff
|
||||
slot.setChanged()
|
||||
}
|
||||
|
||||
if (copy.isEmpty) {
|
||||
return copy
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// second pass - drop stack into first free slot
|
||||
for (slot in slots) {
|
||||
if (onlyFiltered && slot.containerSlotOrNull().let { it !is IFilteredContainerSlot || it.filter == null || !it.testSlotFilter(item) }) {
|
||||
continue
|
||||
} else if (!onlyFiltered && slot.containerSlotOrNull().let { it is IFilteredContainerSlot && it.filter != null }) {
|
||||
continue
|
||||
}
|
||||
|
||||
val limit = slot.getMaxStackSize(copy)
|
||||
|
||||
if (!slot.hasItem() && slot.mayPlace(item)) {
|
||||
val newCount = copy.count.coerceAtMost(limit)
|
||||
|
||||
if (!simulate) {
|
||||
slot.setByPlayer(copy.copy().also { it.count = newCount })
|
||||
slot.setChanged()
|
||||
}
|
||||
|
||||
copy.count -= newCount
|
||||
|
||||
if (copy.isEmpty) {
|
||||
return copy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return copy
|
||||
}
|
||||
|
||||
fun moveItemStackToSlots(item: ItemStack, initialSlot: Int, finalSlot: Int, inverse: Boolean = false, simulate: Boolean = false): ItemStack {
|
||||
if (initialSlot > finalSlot) {
|
||||
return item
|
||||
@ -717,5 +613,96 @@ abstract class MatteryMenu(
|
||||
InventoryMenu.EMPTY_ARMOR_SLOT_LEGGINGS,
|
||||
InventoryMenu.EMPTY_ARMOR_SLOT_CHESTPLATE,
|
||||
InventoryMenu.EMPTY_ARMOR_SLOT_HELMET)
|
||||
|
||||
fun moveItemStackTo(
|
||||
player: Player,
|
||||
source: Slot,
|
||||
slots: Collection<Slot>,
|
||||
onlyFiltered: Boolean = false
|
||||
): Boolean {
|
||||
val remainder = moveItemStackToSlots(source.item, slots, onlyFiltered = onlyFiltered)
|
||||
|
||||
if (remainder.count == source.item.count) {
|
||||
return false
|
||||
}
|
||||
|
||||
val copy = source.item.copy()
|
||||
|
||||
if (remainder.isEmpty) {
|
||||
source.setByPlayer(ItemStack.EMPTY)
|
||||
source.onTake(player, copy)
|
||||
} else {
|
||||
copy.count = source.item.count - remainder.count
|
||||
source.item.count = remainder.count
|
||||
source.onTake(player, copy)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
fun moveItemStackToSlots(item: ItemStack, slots: Collection<Slot>, simulate: Boolean = false, onlyFiltered: Boolean = false): ItemStack {
|
||||
if (item.isEmpty) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
val copy = item.copy()
|
||||
|
||||
// first pass - stack with existing slots
|
||||
if (copy.isStackable) {
|
||||
for (slot in slots) {
|
||||
if (onlyFiltered && slot.containerSlotOrNull().let { it !is IFilteredContainerSlot || it.filter == null || !it.testSlotFilter(item) }) {
|
||||
continue
|
||||
} else if (!onlyFiltered && slot.containerSlotOrNull().let { it is IFilteredContainerSlot && it.filter != null }) {
|
||||
continue
|
||||
}
|
||||
|
||||
val limit = slot.getMaxStackSize(copy)
|
||||
|
||||
if (limit > slot.item.count && slot.mayPlace(item) && ItemStack.isSameItemSameComponents(slot.item, copy)) {
|
||||
val newCount = (slot.item.count + copy.count).coerceAtMost(limit)
|
||||
val diff = newCount - slot.item.count
|
||||
copy.count -= diff
|
||||
|
||||
if (!simulate) {
|
||||
slot.item.count += diff
|
||||
slot.setChanged()
|
||||
}
|
||||
|
||||
if (copy.isEmpty) {
|
||||
return copy
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// second pass - drop stack into first free slot
|
||||
for (slot in slots) {
|
||||
if (onlyFiltered && slot.containerSlotOrNull().let { it !is IFilteredContainerSlot || it.filter == null || !it.testSlotFilter(item) }) {
|
||||
continue
|
||||
} else if (!onlyFiltered && slot.containerSlotOrNull().let { it is IFilteredContainerSlot && it.filter != null }) {
|
||||
continue
|
||||
}
|
||||
|
||||
val limit = slot.getMaxStackSize(copy)
|
||||
|
||||
if (!slot.hasItem() && slot.mayPlace(item)) {
|
||||
val newCount = copy.count.coerceAtMost(limit)
|
||||
|
||||
if (!simulate) {
|
||||
slot.setByPlayer(copy.copy().also { it.count = newCount })
|
||||
slot.setChanged()
|
||||
}
|
||||
|
||||
copy.count -= newCount
|
||||
|
||||
if (copy.isEmpty) {
|
||||
return copy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return copy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
src/main/kotlin/ru/dbotthepony/mc/otm/menu/SortInput.kt
Normal file
20
src/main/kotlin/ru/dbotthepony/mc/otm/menu/SortInput.kt
Normal file
@ -0,0 +1,20 @@
|
||||
package ru.dbotthepony.mc.otm.menu
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||
import it.unimi.dsi.fastutil.ints.IntCollection
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||
import net.minecraft.world.Container
|
||||
import ru.dbotthepony.mc.otm.container.computeSortedIndices
|
||||
import ru.dbotthepony.mc.otm.container.sortWithIndices
|
||||
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
|
||||
import ru.dbotthepony.mc.otm.network.StreamCodecs
|
||||
|
||||
class SortInput(menu: MatteryMenu, val container: Container, val settings: IItemStackSortingSettings) {
|
||||
val input = menu.PlayerInput(MatteryStreamCodec.Collection<RegistryFriendlyByteBuf, Int, IntCollection>(StreamCodecs.VAR_INT, ::IntArrayList)) {
|
||||
container.sortWithIndices(it)
|
||||
}
|
||||
|
||||
fun clientInput() {
|
||||
input.accept(container.computeSortedIndices(settings.actualComparator))
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Player
|
||||
import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.SortInput
|
||||
import ru.dbotthepony.mc.otm.menu.UserFilteredMenuSlot
|
||||
import ru.dbotthepony.mc.otm.menu.makeSlots
|
||||
import ru.dbotthepony.mc.otm.registry.game.MMenus
|
||||
@ -18,7 +19,7 @@ class CargoCrateMenu(
|
||||
val storageSlots = makeSlots(actualContainer, ::UserFilteredMenuSlot)
|
||||
private val trackedPlayerOpen = !inventory.player.isSpectator
|
||||
|
||||
val sort = SortInput(actualContainer, playerSortSettings)
|
||||
val sort = SortInput(this, actualContainer, playerSortSettings)
|
||||
|
||||
init {
|
||||
if (trackedPlayerOpen) {
|
||||
|
@ -8,6 +8,7 @@ import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
|
||||
import ru.dbotthepony.mc.otm.entity.MinecartCargoCrate
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenuSlot
|
||||
import ru.dbotthepony.mc.otm.menu.SortInput
|
||||
import ru.dbotthepony.mc.otm.menu.makeSlots
|
||||
import ru.dbotthepony.mc.otm.registry.game.MMenus
|
||||
|
||||
@ -21,7 +22,7 @@ class MinecartCargoCrateMenu(
|
||||
|
||||
private val trackedPlayerOpen = !inventory.player.isSpectator
|
||||
|
||||
val sort = SortInput(actualContainer, playerSortSettings)
|
||||
val sort = SortInput(this, actualContainer, playerSortSettings)
|
||||
|
||||
init {
|
||||
if (trackedPlayerOpen) {
|
||||
|
@ -8,6 +8,7 @@ import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||
import ru.dbotthepony.mc.otm.block.entity.tech.ItemHatchBlockEntity
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.SortInput
|
||||
import ru.dbotthepony.mc.otm.menu.UserFilteredMenuSlot
|
||||
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||
import ru.dbotthepony.mc.otm.menu.makeSlots
|
||||
@ -28,7 +29,7 @@ class ItemHatchMenu(
|
||||
}
|
||||
}
|
||||
|
||||
val sort = SortInput(actualContainer, playerSortSettings)
|
||||
val sort = SortInput(this, actualContainer, playerSortSettings)
|
||||
val redstone = EnumInputWithFeedback<RedstoneSetting>(this)
|
||||
|
||||
init {
|
||||
|
@ -79,7 +79,7 @@ class MatteryFoodData(private var player: Player) : FoodData() {
|
||||
if (saturationLevel > 0f) {
|
||||
val satisfied = min(saturationLevel.roundToInt(), points)
|
||||
points -= satisfied
|
||||
saturationLevel -= satisfied
|
||||
saturationLevel = max(0f, saturationLevel - satisfied)
|
||||
}
|
||||
|
||||
foodLevel = max(0, foodLevel - points)
|
||||
|
Loading…
Reference in New Issue
Block a user