diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainer.kt index 6d81f58e1..b68cca149 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainer.kt @@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.data.codec.minRange import java.util.function.Predicate class SlottedContainer( - slots: Collection, + slots: Collection, private val stillValid: Predicate, private val globalChangeListeners: Array ) : ISlottedContainer, INBTSerializable { @@ -171,6 +171,51 @@ class SlottedContainer( notifyChanged() } + fun interface SlotProvider { + fun create(container: SlottedContainer, index: Int): ContainerSlot + } + + class Builder { + private val slots = ArrayList() + private var stillValid = Predicate { true } + private val globalChangeListeners = ArrayList() + + fun add(slot: SlotProvider): Builder { + slots.add(slot) + return this + } + + fun add(amount: Int, provider: SlotProvider): Builder { + for (i in 0 until amount) + slots.add(provider) + + return this + } + + fun stillValid(predicate: Predicate): Builder { + this.stillValid = predicate + return this + } + + fun onChanged(listener: Runnable): Builder { + globalChangeListeners.add(listener) + return this + } + + fun copy(): Builder { + val copy = Builder() + copy.slots.addAll(slots) + copy.globalChangeListeners.addAll(globalChangeListeners) + copy.stillValid = stillValid + return copy + } + + fun build(): SlottedContainer { + return SlottedContainer(slots, stillValid, globalChangeListeners.toTypedArray()) + } + } + + companion object { private val LOGGER = LogManager.getLogger() } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainerBuilder.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainerBuilder.kt deleted file mode 100644 index 5edb2d5b0..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/SlottedContainerBuilder.kt +++ /dev/null @@ -1,48 +0,0 @@ -package ru.dbotthepony.mc.otm.container - -import net.minecraft.world.entity.player.Player -import java.util.function.Predicate - -class SlottedContainerBuilder { - fun interface SlotProvider { - fun create(container: SlottedContainer, index: Int): ContainerSlot - } - - private val slots = ArrayList() - private var stillValid = Predicate { true } - private val globalChangeListeners = ArrayList() - - fun add(slot: SlotProvider): SlottedContainerBuilder { - slots.add(slot) - return this - } - - fun add(amount: Int, provider: SlotProvider): SlottedContainerBuilder { - for (i in 0 until amount) - slots.add(provider) - - return this - } - - fun stillValid(predicate: Predicate): SlottedContainerBuilder { - this.stillValid = predicate - return this - } - - fun onChanged(listener: Runnable): SlottedContainerBuilder { - globalChangeListeners.add(listener) - return this - } - - fun copy(): SlottedContainerBuilder { - val copy = SlottedContainerBuilder() - copy.slots.addAll(slots) - copy.globalChangeListeners.addAll(globalChangeListeners) - copy.stillValid = stillValid - return copy - } - - fun build(): SlottedContainer { - return SlottedContainer(slots, stillValid, globalChangeListeners.toTypedArray()) - } -}