From b076d295605ad70a715a3da53a720ffd3bd70da7 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 14 Mar 2025 18:29:51 +0700 Subject: [PATCH] Declare IEnhancedContainer as having generic parameter Slot --- .../entity/storage/DriveViewerBlockEntity.kt | 2 +- .../entity/storage/ItemMonitorBlockEntity.kt | 2 +- .../entity/tech/EssenceStorageBlockEntity.kt | 2 +- .../mc/otm/compat/vanilla/MatteryChestMenu.kt | 2 +- .../compat/vanilla/MatteryShulkerBoxMenu.kt | 2 +- .../mc/otm/container/CombinedContainer.kt | 18 +++++------ .../mc/otm/container/EnhancedContainer.kt | 32 +++++++++---------- .../mc/otm/container/IEnhancedContainer.kt | 20 ++++++------ .../container/IEnhancedCraftingContainer.kt | 4 +-- .../mc/otm/container/IMatteryContainer.kt | 2 +- .../mc/otm/container/ISlottedContainer.kt | 12 +------ .../mc/otm/container/UpgradeContainer.kt | 2 +- .../mc/otm/container/util/Iterators.kt | 10 +++--- .../mc/otm/item/matter/MatterDustItem.kt | 2 +- .../ru/dbotthepony/mc/otm/menu/Slots.kt | 10 +++--- .../mc/otm/menu/matter/MatterRecyclerMenu.kt | 2 +- .../otm/menu/matter/MatterReplicatorMenu.kt | 2 +- .../mc/otm/menu/matter/MatterScannerMenu.kt | 2 +- .../mc/otm/menu/matter/PatternStorageMenu.kt | 2 +- .../mc/otm/menu/storage/DriveRackMenu.kt | 2 +- .../mc/otm/menu/storage/DriveViewerMenu.kt | 2 +- .../mc/otm/menu/tech/ChemicalGeneratorMenu.kt | 2 +- .../mc/otm/menu/tech/CobblerMenu.kt | 2 +- .../mc/otm/menu/tech/EssenceStorageMenu.kt | 4 +-- .../mc/otm/menu/tech/PlatePressMenu.kt | 2 +- .../mc/otm/menu/tech/PoweredFurnaceMenu.kt | 2 +- .../mc/otm/player/ExopackContainer.kt | 3 +- .../mc/otm/player/MatteryPlayer.kt | 4 +-- 28 files changed, 73 insertions(+), 80 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt index c1c23799e..40f4eabd7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/DriveViewerBlockEntity.kt @@ -30,7 +30,7 @@ class DriveViewerBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::energyUpdated, MachinesConfig.DRIVE_VIEWER)) val energyConfig = ConfigurableEnergy(energy) - val container: EnhancedContainer = object : EnhancedContainer(1) { + val container: EnhancedContainer.Simple = object : EnhancedContainer.Simple(1) { override fun notifySlotChanged(slot: Int, old: ItemStack) { super.notifySlotChanged(slot, old) markDirtyFast() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt index d872ac632..3c44eabd5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/ItemMonitorBlockEntity.kt @@ -219,7 +219,7 @@ class ItemMonitorBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte fun howMuchPlayerCrafted(ply: Player): Int = craftingAmount.getInt(ply) fun lastCraftingRecipe(ply: Player) = lastCraftingRecipe[ply] - val craftingGrid = IEnhancedCraftingContainer.Wrapper(EnhancedContainer.withListener(3 * 3) { + val craftingGrid = IEnhancedCraftingContainer.Wrapper(EnhancedContainer.WithListener(3 * 3) { markDirtyFast() if (!inProcessOfCraft) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EssenceStorageBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EssenceStorageBlockEntity.kt index 0cd0feeda..e5221721c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EssenceStorageBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EssenceStorageBlockEntity.kt @@ -71,7 +71,7 @@ class EssenceStorageBlockEntity(blockPos: BlockPos, blockState: BlockState) : Ma } val capsuleContainer = SlottedContainer.simple(1, ::CapsuleSlot, ::markDirtyFast) - val servoContainer = EnhancedContainer.withListener(1, ::markDirtyFast) + val servoContainer = EnhancedContainer.WithListener(1, ::markDirtyFast) val mendingContainer = SlottedContainer.simple(1, ::MendingSlot, ::markDirtyFast).also(::addDroppableContainer) private var mending: Holder? = null diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryChestMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryChestMenu.kt index 25bb68fee..038854f22 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryChestMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryChestMenu.kt @@ -11,7 +11,7 @@ import ru.dbotthepony.mc.otm.menu.makeSlots class MatteryChestMenu( type: MenuType<*>, containerId: Int, inventory: Inventory, override val rows: Int, override val columns: Int, - container: Container = EnhancedContainer(rows * columns) + container: Container = EnhancedContainer.Simple(rows * columns) ) : AbstractVanillaChestMenu(type, containerId, inventory, container) { override val containerSlots = makeSlots(container, ::MatteryMenuSlot) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryShulkerBoxMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryShulkerBoxMenu.kt index 01bd06a14..9ebc6d65e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryShulkerBoxMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/compat/vanilla/MatteryShulkerBoxMenu.kt @@ -10,7 +10,7 @@ import ru.dbotthepony.mc.otm.menu.makeSlots class MatteryShulkerBoxMenu( containerId: Int, inventory: Inventory, - container: Container = EnhancedContainer(27) + container: Container = EnhancedContainer.Simple(27) ) : AbstractVanillaChestMenu(VanillaMenuTypes.SHULKER_BOX, containerId, inventory, container) { override val containerSlots = makeSlots(container, ::Slot) override val rows: Int diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/CombinedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/CombinedContainer.kt index 456f87cde..5f495f997 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/CombinedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/CombinedContainer.kt @@ -23,9 +23,9 @@ import ru.dbotthepony.mc.otm.core.isNotEmpty import ru.dbotthepony.mc.otm.core.stream import java.util.stream.Stream -class CombinedContainer(containers: Stream>>) : ISlottedContainer, IMatteryContainer { - constructor(vararg containers: IEnhancedContainer) : this(containers.stream().map { it to (0 until it.containerSize) }) - constructor(containers: Collection) : this(containers.stream().map { it to (0 until it.containerSize) }) +class CombinedContainer(containers: Stream, Iterable>>) : ISlottedContainer, IMatteryContainer { + constructor(vararg containers: IEnhancedContainer<*>) : this(containers.stream().map { it to (0 until it.containerSize) }) + constructor(containers: Collection>) : this(containers.stream().map { it to (0 until it.containerSize) }) private val slots: ImmutableList private val slotsMap: ImmutableMap> @@ -145,7 +145,7 @@ class CombinedContainer(containers: Stream>>() + private val values = ArrayList, Iterable>>() fun add(container: Container): Builder { return add(IEnhancedContainer.wrap(container)) @@ -167,27 +167,27 @@ class CombinedContainer(containers: Stream): Builder { values.add(container to container.slotRange) return this } - fun add(container: IEnhancedContainer, slots: Iterator): Builder { + fun add(container: IEnhancedContainer<*>, slots: Iterator): Builder { values.add(container to IntArrayList(slots)) return this } - fun add(container: IEnhancedContainer, slot: Int): Builder { + fun add(container: IEnhancedContainer<*>, slot: Int): Builder { values.add(container to intArrayOf(slot).asIterable()) return this } - fun add(container: IEnhancedContainer, from: Int, to: Int): Builder { + fun add(container: IEnhancedContainer<*>, from: Int, to: Int): Builder { values.add(container to (from .. to)) return this } - fun add(container: IEnhancedContainer, slots: Iterable): Builder { + fun add(container: IEnhancedContainer<*>, slots: Iterable): Builder { values.add(container to slots) return this } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/EnhancedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/EnhancedContainer.kt index 5f2f6c508..fe1aa25d8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/EnhancedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/EnhancedContainer.kt @@ -23,15 +23,9 @@ import ru.dbotthepony.mc.otm.core.nbt.set * This is supposed to be counterpart to [SimpleContainer] of Minecraft itself, with more features * and improved performance (inside [IEnhancedContainer] defined methods). */ -open class EnhancedContainer(private val size: Int) : IEnhancedContainer, INBTSerializable { +abstract class EnhancedContainer(private val size: Int) : IEnhancedContainer, INBTSerializable { private val items = Array(size) { ItemStack.EMPTY } private val observedItems = Array(size) { ItemStack.EMPTY } - private val slots by lazy(LazyThreadSafetyMode.PUBLICATION) { Array(size) { IContainerSlot.Simple(it, this) } } - - // can be safely overridden in subclasses, very little memory will be wasted - override fun containerSlot(slot: Int): IContainerSlot { - return slots[slot] - } protected open fun notifySlotChanged(slot: Int, old: ItemStack) {} @@ -184,16 +178,22 @@ open class EnhancedContainer(private val size: Int) : IEnhancedContainer, INBTSe } } - companion object { - private val LOGGER = LogManager.getLogger() + open class Simple(size: Int) : EnhancedContainer(size) { + private val slots by lazy(LazyThreadSafetyMode.PUBLICATION) { Array(size) { IContainerSlot.Simple(it, this) } } - fun withListener(slots: Int, listener: Runnable): EnhancedContainer { - return object : EnhancedContainer(slots) { - override fun notifySlotChanged(slot: Int, old: ItemStack) { - super.notifySlotChanged(slot, old) - listener.run() - } - } + override fun containerSlot(slot: Int): IContainerSlot { + return slots[slot] } } + + open class WithListener(size: Int, private val listener: Runnable) : Simple(size) { + override fun notifySlotChanged(slot: Int, old: ItemStack) { + super.notifySlotChanged(slot, old) + listener.run() + } + } + + companion object { + private val LOGGER = LogManager.getLogger() + } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt index 795e2e481..8a9fd2fac 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedContainer.kt @@ -24,7 +24,7 @@ import java.util.stream.StreamSupport * This is useful because it allows to interact with actually enhanced and regular containers through unified interface, * and actual implementations of this interface are likely to provide efficient method implementations in place of derived/emulated ones. */ -interface IEnhancedContainer : IContainer, RecipeInput, Iterable, StackedContentsCompatible { +interface IEnhancedContainer : IContainer, RecipeInput, Iterable, StackedContentsCompatible { // provide non-ambiguous get and set operators operator fun get(slot: Int): ItemStack { return getItem(slot) @@ -34,9 +34,7 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable, Sta setItem(slot, value) } - fun containerSlot(slot: Int): IContainerSlot { - return IContainerSlot.Simple(slot, this) - } + fun containerSlot(slot: Int): S override fun fillStackedContents(contents: StackedContents) { forEach { contents.accountStack(it) } @@ -45,11 +43,11 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable, Sta /** * Returns iterator over **all** slots this container has */ - fun slotIterator(): Iterator { + fun slotIterator(): Iterator { return (0 until containerSize).iterator().map { containerSlot(it) } } - fun nonEmptySlotIterator(): Iterator { + fun nonEmptySlotIterator(): Iterator { return slotIterator().filter { it.isNotEmpty } } @@ -307,7 +305,11 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable, Sta return StreamSupport.stream(spliterator(), false) } - private class Wrapper(private val parent: Container) : IEnhancedContainer { + private class Wrapper(private val parent: Container) : IEnhancedContainer { + override fun containerSlot(slot: Int): IContainerSlot { + return IContainerSlot.Simple(slot, parent) + } + override fun clearContent() { return parent.clearContent() } @@ -378,8 +380,8 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable, Sta } companion object { - fun wrap(other: Container): IEnhancedContainer { - if (other is IEnhancedContainer) + fun wrap(other: Container): IEnhancedContainer<*> { + if (other is IEnhancedContainer<*>) return other return Wrapper(other) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedCraftingContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedCraftingContainer.kt index 61dc89142..e7e10a0dd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedCraftingContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IEnhancedCraftingContainer.kt @@ -4,7 +4,7 @@ import net.minecraft.world.entity.player.StackedContents import net.minecraft.world.inventory.CraftingContainer import net.minecraft.world.item.ItemStack -interface IEnhancedCraftingContainer : IEnhancedContainer, CraftingContainer { +interface IEnhancedCraftingContainer : IEnhancedContainer, CraftingContainer { override fun getItems(): MutableList { return toList() } @@ -13,7 +13,7 @@ interface IEnhancedCraftingContainer : IEnhancedContainer, CraftingContainer { forEach { contents.accountSimpleStack(it) } } - class Wrapper(val parent: C, private val width: Int, private val height: Int) : IEnhancedCraftingContainer, IEnhancedContainer by parent { + class Wrapper, S : IContainerSlot>(val parent: C, private val width: Int, private val height: Int) : IEnhancedCraftingContainer, IEnhancedContainer by parent { init { require(width * height == parent.containerSize) { "Crafting container dimensions ($width x $height) do not match container size provided (${parent.containerSize})" } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IMatteryContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IMatteryContainer.kt index b41c5f2eb..7d383f010 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/IMatteryContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/IMatteryContainer.kt @@ -9,7 +9,7 @@ import ru.dbotthepony.mc.otm.core.collect.filter import ru.dbotthepony.mc.otm.core.collect.map import ru.dbotthepony.mc.otm.core.isNotEmpty -interface IMatteryContainer : IEnhancedContainer { +interface IMatteryContainer : IEnhancedContainer { fun getSlotFilter(slot: Int): Item? /** diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt index 020c2d6d3..d6bf3cda9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/ISlottedContainer.kt @@ -8,17 +8,7 @@ import ru.dbotthepony.kommons.collect.any /** * Skeletal implementation for containers which revolve around [IContainerSlot] */ -interface ISlottedContainer : IEnhancedContainer { - override fun containerSlot(slot: Int): S - - override fun slotIterator(): Iterator { - return super.slotIterator() as Iterator - } - - override fun nonEmptySlotIterator(): Iterator { - return super.nonEmptySlotIterator() as Iterator - } - +interface ISlottedContainer : IEnhancedContainer { override fun setChanged(slot: Int) { containerSlot(slot).setChanged() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt index 544f81a47..e18a3d427 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt @@ -17,7 +17,7 @@ class UpgradeContainer( val allowedUpgrades: Set = UpgradeType.ALL, val shouldLockUpgradeSlots: BooleanSupplier = BooleanSupplier { false }, private val listener: Runnable = Runnable {} -) : EnhancedContainer(slotCount), IMatteryUpgrade { +) : EnhancedContainer.Simple(slotCount), IMatteryUpgrade { override fun notifySlotChanged(slot: Int, old: ItemStack) { super.notifySlotChanged(slot, old) listener.run() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/util/Iterators.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/util/Iterators.kt index 9160415c9..39101d4cd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/util/Iterators.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/util/Iterators.kt @@ -13,7 +13,7 @@ import ru.dbotthepony.mc.otm.core.collect.map import ru.dbotthepony.mc.otm.core.isNotEmpty fun Container.containerSlot(slot: Int): IContainerSlot { - if (this is IEnhancedContainer) { + if (this is IEnhancedContainer<*>) { return containerSlot(slot) } else { return IContainerSlot.Simple(slot, this) @@ -24,7 +24,7 @@ fun Container.containerSlot(slot: Int): IContainerSlot { * Returns [IContainerSlot] only if this container is [IEnhancedContainer] */ fun Container.containerSlotOrNull(slot: Int): IContainerSlot? { - if (this is IEnhancedContainer) { + if (this is IEnhancedContainer<*>) { return containerSlot(slot) } else { return null @@ -40,7 +40,7 @@ fun Slot.containerSlotOrNull(): IContainerSlot? { } operator fun Container.iterator(): Iterator { - if (this is IEnhancedContainer) { + if (this is IEnhancedContainer<*>) { return iterator() } else { return (0 until containerSize).iterator().map { this[it] }.filter { it.isNotEmpty } @@ -48,7 +48,7 @@ operator fun Container.iterator(): Iterator { } fun Container.slotIterator(): Iterator { - if (this is IEnhancedContainer) { + if (this is IEnhancedContainer<*>) { return slotIterator() } else { return (0 until containerSize).iterator().map { IContainerSlot.Simple(it, this) } @@ -56,7 +56,7 @@ fun Container.slotIterator(): Iterator { } fun Container.nonEmptySlotIterator(): Iterator { - if (this is IEnhancedContainer) { + if (this is IEnhancedContainer<*>) { return nonEmptySlotIterator() } else { return (0 until containerSize).iterator().filter { this[it].isNotEmpty }.map { IContainerSlot.Simple(it, this) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt index 717524447..e8060499d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt @@ -66,7 +66,7 @@ class MatterDustItem : Item(Properties().stacksTo(64)), IMatterItem { return MatterValue(value, 1.0) } - fun moveIntoContainer(matterValue: Decimal, container: IEnhancedContainer, mainSlot: Int, stackingSlot: Int): Decimal { + fun moveIntoContainer(matterValue: Decimal, container: IEnhancedContainer<*>, mainSlot: Int, stackingSlot: Int): Decimal { @Suppress("name_shadowing") var matterValue = matterValue diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt index 871d36bb3..a41dad0c2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt @@ -65,8 +65,8 @@ open class MatteryMenuSlot(container: Container, index: Int, x: Int = 0, y: Int } override fun setChanged() { - if (container is IEnhancedContainer) { - (container as IEnhancedContainer).setChanged(containerSlot) + if (container is IEnhancedContainer<*>) { + (container as IEnhancedContainer<*>).setChanged(containerSlot) } else { super.setChanged() } @@ -83,7 +83,7 @@ open class MatteryMenuSlot(container: Container, index: Int, x: Int = 0, y: Int override fun getMaxStackSize(): Int { val container = container - if (container is IEnhancedContainer) { + if (container is IEnhancedContainer<*>) { return container.getMaxStackSize(slotIndex, ItemStack.EMPTY) } else { return super.getMaxStackSize() @@ -93,7 +93,7 @@ open class MatteryMenuSlot(container: Container, index: Int, x: Int = 0, y: Int override fun getMaxStackSize(itemStack: ItemStack): Int { val container = container - if (container is IEnhancedContainer) { + if (container is IEnhancedContainer<*>) { return container.getMaxStackSize(slotIndex, itemStack) } else { return super.getMaxStackSize(itemStack) @@ -278,7 +278,7 @@ fun MatteryMenu.makeUpgradeSlots(count: Int, container: UpgradeContainer?): Upgr allowedTypes[value] = BooleanSupplier { b.get() } } - val syncContainer = container ?: EnhancedContainer(count) + val syncContainer = container ?: EnhancedContainer.Simple(count) val isOpen = InstantBooleanInput(this) return UpgradeSlots( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt index 8a7b3f2b4..011aeb2fb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt @@ -21,7 +21,7 @@ class MatterRecyclerMenu @JvmOverloads constructor( inventory: Inventory, tile: MatterRecyclerBlockEntity? = null ) : MatteryPoweredMenu(MMenus.MATTER_RECYCLER, containerID, inventory, tile) { - val input = object : MatteryMenuSlot(tile?.container ?: EnhancedContainer(1), 0) { + val input = object : MatteryMenuSlot(tile?.container ?: EnhancedContainer.Simple(1), 0) { override fun mayPlace(itemStack: ItemStack): Boolean { return itemStack.item is MatterDustItem && (itemStack.item as MatterDustItem).getMatterValue(itemStack) != null } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt index d1956e505..a4824823a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt @@ -35,7 +35,7 @@ class MatterReplicatorMenu @JvmOverloads constructor( val upgrades = makeUpgradeSlots(3, tile?.upgrades) init { - val container = CombinedContainer(tile?.outputContainer ?: EnhancedContainer(3), tile?.dustContainer ?: EnhancedContainer(2)) + val container = CombinedContainer(tile?.outputContainer ?: EnhancedContainer.Simple(3), tile?.dustContainer ?: EnhancedContainer.Simple(2)) storageSlots = immutableList(5) { addStorageSlot(OutputMenuSlot(container, it, onTake = { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt index 005e774c1..85157fb8d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt @@ -31,7 +31,7 @@ class MatterScannerMenu( val upgrades = makeUpgradeSlots(2, tile?.upgrades) init { - val container = tile?.container ?: EnhancedContainer(1) + val container = tile?.container ?: EnhancedContainer.Simple(1) input = object : MatteryMenuSlot(container, 0, 64, 38) { override fun mayPlace(itemStack: ItemStack) = MatterManager.canDecompose(itemStack) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/PatternStorageMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/PatternStorageMenu.kt index 920899dec..2ddc1a530 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/PatternStorageMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/PatternStorageMenu.kt @@ -32,7 +32,7 @@ class PatternStorageMenu @JvmOverloads constructor( }) } - val patterns = tile?.container ?: EnhancedContainer(2 * 4) + val patterns = tile?.container ?: EnhancedContainer.Simple(2 * 4) storageSlots = immutableList(patterns.containerSize) { addStorageSlot(PatternMenuSlot(patterns, it)) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveRackMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveRackMenu.kt index 2fc33a8f0..e0e8c4b40 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveRackMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveRackMenu.kt @@ -19,7 +19,7 @@ class DriveRackMenu @JvmOverloads constructor( inventory: Inventory, tile: DriveRackBlockEntity? = null ) : MatteryPoweredMenu(MMenus.DRIVE_RACK, containerId, inventory, tile) { - val storageSlots = makeSlots(tile?.container ?: EnhancedContainer(4), ::DriveMenuSlot) + val storageSlots = makeSlots(tile?.container ?: EnhancedContainer.Simple(4), ::DriveMenuSlot) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) val profiledEnergy = ProfiledLevelGaugeWidget(this, tile?.energy, energyWidget) val insertPriority = IntInputWithFeedback(this, tile?.let { it::insertPriority }) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt index d7390009d..1f0a190c0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/storage/DriveViewerMenu.kt @@ -37,7 +37,7 @@ class DriveViewerMenu( ) : MatteryPoweredMenu(MMenus.DRIVE_VIEWER, containerID, inventory, tile), INetworkedItemViewProvider { override val networkedItemView = NetworkedItemView(inventory.player, this, tile == null) - val driveSlot = object : MatteryMenuSlot(tile?.container ?: EnhancedContainer(1), 0) { + val driveSlot = object : MatteryMenuSlot(tile?.container ?: EnhancedContainer.Simple(1), 0) { override fun mayPlace(itemStack: ItemStack): Boolean { return itemStack.getCapability(MatteryCapability.CONDENSATION_DRIVE) != null } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/ChemicalGeneratorMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/ChemicalGeneratorMenu.kt index 3e2c08051..445d5433d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/ChemicalGeneratorMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/ChemicalGeneratorMenu.kt @@ -38,7 +38,7 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t } } - val residueSlot = object : MatteryMenuSlot(tile?.residueContainer ?: EnhancedContainer(1), 0) { + val residueSlot = object : MatteryMenuSlot(tile?.residueContainer ?: EnhancedContainer.Simple(1), 0) { override fun mayPlace(itemStack: ItemStack): Boolean { return false } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/CobblerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/CobblerMenu.kt index a7258ace0..1bbc3b4e8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/CobblerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/CobblerMenu.kt @@ -17,7 +17,7 @@ class CobblerMenu( inventory: Inventory, tile: CobblerBlockEntity? = null ) : MatteryMenu(MMenus.COBBLESTONE_GENERATOR, p_38852_, inventory, tile) { - val storageSlots = makeSlots(tile?.container ?: EnhancedContainer(CobblerBlockEntity.CONTAINER_SIZE), ::OutputMenuSlot) + val storageSlots = makeSlots(tile?.container ?: EnhancedContainer.Simple(CobblerBlockEntity.CONTAINER_SIZE), ::OutputMenuSlot) val redstone = EnumInputWithFeedback(this) val itemConfig = ItemConfigPlayerInput(this) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EssenceStorageMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EssenceStorageMenu.kt index f3c4258fd..1c362f84d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EssenceStorageMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EssenceStorageMenu.kt @@ -34,13 +34,13 @@ class EssenceStorageMenu( val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val fluidConfig = FluidConfigPlayerInput(this, tile?.fluidConfig) - val capsuleSlot = object : MatteryMenuSlot(tile?.capsuleContainer ?: EnhancedContainer(1), 0) { + val capsuleSlot = object : MatteryMenuSlot(tile?.capsuleContainer ?: EnhancedContainer.Simple(1), 0) { override fun mayPlace(itemStack: ItemStack): Boolean { return itemStack.item is EssenceCapsuleItem && super.mayPlace(itemStack) } } - val servoSlot = object : MatteryMenuSlot(tile?.servoContainer ?: EnhancedContainer(1), 0) { + val servoSlot = object : MatteryMenuSlot(tile?.servoContainer ?: EnhancedContainer.Simple(1), 0) { override fun mayPlace(itemStack: ItemStack): Boolean { return itemStack.item == MItems.ESSENCE_SERVO && super.mayPlace(itemStack) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt index 052984a6c..ed4eccf7c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt @@ -31,7 +31,7 @@ class PlatePressMenu( isTwin: Boolean ) : AbstractProcessingMachineMenu(type, containerID, inventory, tile) { val inputSlots = makeSlots(tile?.inputContainer ?: SlottedContainer.filtered(if (isTwin) 2 else 1), ::MatteryMenuSlot) - val outputSlots = makeSlots(tile?.outputContainer ?: EnhancedContainer(if (isTwin) 2 else 1)) { a, b -> OutputMenuSlot(a, b) { tile?.experience?.popExperience(player as ServerPlayer) } } + val outputSlots = makeSlots(tile?.outputContainer ?: EnhancedContainer.Simple(if (isTwin) 2 else 1)) { a, b -> OutputMenuSlot(a, b) { tile?.experience?.popExperience(player as ServerPlayer) } } val gauges = immutableList(if (isTwin) 2 else 1) { ProgressGaugeWidget(this, tile?.jobEventLoops?.get(it)) } override val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig, allowPush = true) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt index f66e42b08..024b854c1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PoweredFurnaceMenu.kt @@ -40,7 +40,7 @@ class PoweredFurnaceMenu( // we can't make these slots to reject non-smeltable items // since mods may add obscure recipes/ingredients which never test true on client val inputSlots = makeSlots(tile?.inputs ?: SlottedContainer.filtered(2), ::UserFilteredMenuSlot) - val outputSlots = makeSlots(tile?.outputs ?: EnhancedContainer(2)) { c, s -> OutputMenuSlot(c, s) { tile?.experience?.popExperience(player as ServerPlayer) } } + val outputSlots = makeSlots(tile?.outputs ?: EnhancedContainer.Simple(2)) { c, s -> OutputMenuSlot(c, s) { tile?.experience?.popExperience(player as ServerPlayer) } } val progressGauge = immutableList(2) { ProgressGaugeWidget(this, tile?.jobEventLoops?.get(it)) } override val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig, allowPush = true) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/player/ExopackContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/player/ExopackContainer.kt index eb71b2c80..c3b7c9f9d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/player/ExopackContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/player/ExopackContainer.kt @@ -3,8 +3,9 @@ package ru.dbotthepony.mc.otm.player import net.minecraft.world.item.Item import ru.dbotthepony.mc.otm.container.EnhancedContainer import ru.dbotthepony.mc.otm.container.IContainerSlot +import ru.dbotthepony.mc.otm.container.IEnhancedContainer -class ExopackContainer(size: Int, val player: MatteryPlayer) : EnhancedContainer(size) { +class ExopackContainer(size: Int, val player: MatteryPlayer) : EnhancedContainer(size) { private inner class Slot(slot: Int) : IContainerSlot.Simple(slot, this@ExopackContainer), IPlayerInventorySlot { override var shouldCharge: Boolean get() = (PlayerInventoryWrapper.SLOTS + slot) in player.slotsChargeFlag diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/player/MatteryPlayer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/player/MatteryPlayer.kt index 48c6b88e3..2ce22ab3f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/player/MatteryPlayer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/player/MatteryPlayer.kt @@ -167,7 +167,7 @@ class MatteryPlayer(val ply: Player) { val level: Level get() = capability.ply.level() } - private inner class PlayerMatteryContainer(size: Int) : EnhancedContainer(size) { + private inner class PlayerMatteryContainer(size: Int) : EnhancedContainer.Simple(size) { override fun notifySlotChanged(slot: Int, old: ItemStack) { if (ply is ServerPlayer) { val item = this[slot].copy() @@ -317,7 +317,7 @@ class MatteryPlayer(val ply: Player) { val wrappedInventory = PlayerInventoryWrapper(this) - val wrappedItemInventory: IEnhancedContainer = object : IEnhancedContainer by wrappedInventory { + val wrappedItemInventory: IEnhancedContainer = object : IEnhancedContainer by wrappedInventory { override fun getContainerSize(): Int { return 36 }