Compare commits
No commits in common. "70c5382e9d7a62580690bdc246e33d36c0eb0375" and "3a5f37bd7634b93a594ff32a071100d20443f454" have entirely different histories.
70c5382e9d
...
3a5f37bd76
@ -76,8 +76,6 @@ class CombinedContainer<S : IContainerSlot>(containers: Stream<Pair<IEnhancedCon
|
|||||||
.collect(ImmutableMap.toImmutableMap({ it.key }, { it.value }))
|
.collect(ImmutableMap.toImmutableMap({ it.key }, { it.value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
override val hasFilterableSlots: Boolean = super.hasFilterableSlots
|
|
||||||
|
|
||||||
override fun clearContent() {
|
override fun clearContent() {
|
||||||
for (container in fullCoverage) {
|
for (container in fullCoverage) {
|
||||||
container.clearContent()
|
container.clearContent()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.container
|
package ru.dbotthepony.mc.otm.container
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntCollection
|
import it.unimi.dsi.fastutil.ints.IntCollection
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet
|
||||||
import net.minecraft.world.Container
|
import net.minecraft.world.Container
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.entity.player.StackedContents
|
import net.minecraft.world.entity.player.StackedContents
|
||||||
@ -252,102 +253,60 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addItem(stack: ItemStack, simulate: Boolean, filterPass: Boolean, slots: IntCollection, onlyIntoExisting: Boolean, popTime: Int?, ignoreFilters: Boolean): ItemStack {
|
fun addItem(stack: ItemStack, simulate: Boolean, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null): ItemStack {
|
||||||
if (stack.isEmpty || slots.isEmpty())
|
if (stack.isEmpty || slots.isEmpty())
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
|
val copy = stack.copy()
|
||||||
|
|
||||||
// двигаем в одинаковые слоты
|
// двигаем в одинаковые слоты
|
||||||
for (i in slotWithItemIterator(stack.item, slots)) {
|
for (slot in slotWithItemIterator(stack.item, slots)) {
|
||||||
val slot = containerSlot(i)
|
if (ItemStack.isSameItemSameComponents(this[slot], copy)) {
|
||||||
|
val slotStack = this[slot]
|
||||||
|
val slotLimit = getMaxStackSize(slot, slotStack)
|
||||||
|
|
||||||
val condition: Boolean
|
if (slotStack.count < slotLimit) {
|
||||||
|
val newCount = (slotStack.count + copy.count).coerceAtMost(slotLimit)
|
||||||
if (slot is IFilteredContainerSlot) {
|
val diff = newCount - slotStack.count
|
||||||
condition = (ignoreFilters || !slot.isForbiddenForAutomation) &&
|
|
||||||
ItemStack.isSameItemSameComponents(slot.item, stack) &&
|
|
||||||
(ignoreFilters || !filterPass && !slot.hasFilter || filterPass && slot.hasFilter && slot.testSlotFilter(stack))
|
|
||||||
} else {
|
|
||||||
condition = (ignoreFilters || !filterPass) && ItemStack.isSameItemSameComponents(slot.item, stack)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (condition) {
|
|
||||||
val slotLimit = slot.maxStackSize(slot.item)
|
|
||||||
|
|
||||||
if (slot.item.count < slotLimit) {
|
|
||||||
val newCount = (slot.item.count + stack.count).coerceAtMost(slotLimit)
|
|
||||||
val diff = newCount - slot.item.count
|
|
||||||
|
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
slot.item.count = newCount
|
slotStack.count = newCount
|
||||||
slot.setChanged()
|
setChanged(slot)
|
||||||
|
|
||||||
if (popTime != null) {
|
if (popTime != null) {
|
||||||
slot.item.popTime = popTime
|
slotStack.popTime = popTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.shrink(diff)
|
copy.shrink(diff)
|
||||||
|
|
||||||
if (stack.isEmpty)
|
if (copy.isEmpty) {
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!onlyIntoExisting) {
|
if (!onlyIntoExisting) {
|
||||||
for (i in emptySlotIndexIterator(slots)) {
|
// двигаем в пустые слоты
|
||||||
val slot = containerSlot(i)
|
for (slot in emptySlotIndexIterator(slots)) {
|
||||||
|
val diff = copy.count.coerceAtMost(getMaxStackSize(slot, stack))
|
||||||
|
|
||||||
val condition: Boolean
|
if (!simulate) {
|
||||||
|
val copyToPut = copy.copy()
|
||||||
if (slot is IFilteredContainerSlot) {
|
copyToPut.count = diff
|
||||||
condition = (ignoreFilters || !slot.isForbiddenForAutomation) &&
|
this[slot] = copyToPut
|
||||||
(ignoreFilters || !filterPass && !slot.hasFilter || filterPass && slot.hasFilter && slot.testSlotFilter(stack))
|
setChanged()
|
||||||
} else {
|
|
||||||
condition = ignoreFilters || !filterPass
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition) {
|
copy.shrink(diff)
|
||||||
val diff = stack.count.coerceAtMost(slot.maxStackSize(stack))
|
|
||||||
|
|
||||||
if (!simulate) {
|
if (copy.isEmpty)
|
||||||
val copyToPut = stack.copy()
|
return ItemStack.EMPTY
|
||||||
copyToPut.count = diff
|
|
||||||
slot.item = copyToPut
|
|
||||||
|
|
||||||
if (popTime != null) {
|
|
||||||
copyToPut.popTime = popTime
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.shrink(diff)
|
|
||||||
|
|
||||||
if (stack.isEmpty)
|
|
||||||
return ItemStack.EMPTY
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack
|
return copy
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hint used internally by [IEnhancedContainer] to potentially speed up default method implementations
|
|
||||||
*/
|
|
||||||
val hasFilterableSlots: Boolean
|
|
||||||
get() = false
|
|
||||||
|
|
||||||
fun addItem(stack: ItemStack, simulate: Boolean, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null, ignoreFilters: Boolean = false): ItemStack {
|
|
||||||
if (stack.isEmpty || slots.isEmpty())
|
|
||||||
return stack
|
|
||||||
|
|
||||||
if (ignoreFilters || !hasFilterableSlots) {
|
|
||||||
return addItem(stack.copy(), simulate, filterPass = true, slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = true)
|
|
||||||
} else {
|
|
||||||
var copy = addItem(stack.copy(), simulate, filterPass = true, slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
|
||||||
copy = addItem(copy, simulate, filterPass = false, slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
|
||||||
return copy
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,20 +314,20 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
|||||||
*
|
*
|
||||||
* @return Whenever [stack] was modified
|
* @return Whenever [stack] was modified
|
||||||
*/
|
*/
|
||||||
fun consumeItem(stack: ItemStack, simulate: Boolean, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null, ignoreFilters: Boolean = false): Boolean {
|
fun consumeItem(stack: ItemStack, simulate: Boolean, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null): Boolean {
|
||||||
if (stack.isEmpty)
|
if (stack.isEmpty || slots.isEmpty())
|
||||||
return false
|
return false
|
||||||
|
|
||||||
val result = addItem(stack, simulate = simulate, slots = slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = ignoreFilters)
|
val result = addItem(stack, simulate, slots, onlyIntoExisting, popTime)
|
||||||
if (!simulate) stack.count = result.count
|
if (!simulate) stack.count = result.count
|
||||||
return result.count != stack.count
|
return result.count != stack.count
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fullyAddItem(stack: ItemStack, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null, ignoreFilters: Boolean = false): Boolean {
|
fun fullyAddItem(stack: ItemStack, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null): Boolean {
|
||||||
if (!addItem(stack, simulate = true, slots = slots, popTime = popTime, onlyIntoExisting = onlyIntoExisting, ignoreFilters = ignoreFilters).isEmpty)
|
if (!addItem(stack, true, slots, onlyIntoExisting, popTime).isEmpty)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return addItem(stack, simulate = false, slots = slots, popTime = popTime, onlyIntoExisting = onlyIntoExisting, ignoreFilters = ignoreFilters).isEmpty
|
return addItem(stack, false, slots, onlyIntoExisting, popTime).isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stream(): Stream<ItemStack> {
|
fun stream(): Stream<ItemStack> {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.dbotthepony.mc.otm.container
|
package ru.dbotthepony.mc.otm.container
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntCollection
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import ru.dbotthepony.kommons.collect.any
|
import ru.dbotthepony.kommons.collect.any
|
||||||
|
|
||||||
@ -31,6 +33,147 @@ interface ISlottedContainer<out S : IContainerSlot> : IEnhancedContainer<S> {
|
|||||||
containerSlot(slot).item = itemStack
|
containerSlot(slot).item = itemStack
|
||||||
}
|
}
|
||||||
|
|
||||||
override val hasFilterableSlots: Boolean
|
private fun addItem(stack: ItemStack, simulate: Boolean, filterPass: Boolean, slots: IntCollection, onlyIntoExisting: Boolean, popTime: Int?, ignoreFilters: Boolean): ItemStack {
|
||||||
|
if (stack.isEmpty || slots.isEmpty())
|
||||||
|
return stack
|
||||||
|
|
||||||
|
// двигаем в одинаковые слоты
|
||||||
|
for (i in slotWithItemIterator(stack.item, slots)) {
|
||||||
|
val slot = containerSlot(i)
|
||||||
|
|
||||||
|
val condition: Boolean
|
||||||
|
|
||||||
|
if (slot is IFilteredContainerSlot) {
|
||||||
|
condition = (ignoreFilters || !slot.isForbiddenForAutomation) &&
|
||||||
|
ItemStack.isSameItemSameComponents(slot.item, stack) &&
|
||||||
|
(ignoreFilters || !filterPass && !slot.hasFilter || filterPass && slot.hasFilter && slot.testSlotFilter(stack))
|
||||||
|
} else {
|
||||||
|
condition = (ignoreFilters || !filterPass) && ItemStack.isSameItemSameComponents(slot.item, stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (condition) {
|
||||||
|
val slotLimit = slot.maxStackSize(slot.item)
|
||||||
|
|
||||||
|
if (slot.item.count < slotLimit) {
|
||||||
|
val newCount = (slot.item.count + stack.count).coerceAtMost(slotLimit)
|
||||||
|
val diff = newCount - slot.item.count
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
|
slot.item.count = newCount
|
||||||
|
slot.setChanged()
|
||||||
|
|
||||||
|
if (popTime != null) {
|
||||||
|
slot.item.popTime = popTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.shrink(diff)
|
||||||
|
|
||||||
|
if (stack.isEmpty)
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!onlyIntoExisting) {
|
||||||
|
for (i in emptySlotIndexIterator(slots)) {
|
||||||
|
val slot = containerSlot(i)
|
||||||
|
|
||||||
|
val condition: Boolean
|
||||||
|
|
||||||
|
if (slot is IFilteredContainerSlot) {
|
||||||
|
condition = (ignoreFilters || !slot.isForbiddenForAutomation) &&
|
||||||
|
(ignoreFilters || !filterPass && !slot.hasFilter || filterPass && slot.hasFilter && slot.testSlotFilter(stack))
|
||||||
|
} else {
|
||||||
|
condition = ignoreFilters || !filterPass
|
||||||
|
}
|
||||||
|
|
||||||
|
if (condition) {
|
||||||
|
val diff = stack.count.coerceAtMost(slot.maxStackSize(stack))
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
|
val copyToPut = stack.copy()
|
||||||
|
copyToPut.count = diff
|
||||||
|
slot.item = copyToPut
|
||||||
|
|
||||||
|
if (popTime != null) {
|
||||||
|
copyToPut.popTime = popTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.shrink(diff)
|
||||||
|
|
||||||
|
if (stack.isEmpty)
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hint used internally by [ISlottedContainer] to potentially speed up default method implementations
|
||||||
|
*/
|
||||||
|
val hasFilterableSlots: Boolean
|
||||||
get() = slotIterator().any { it is IFilteredContainerSlot }
|
get() = slotIterator().any { it is IFilteredContainerSlot }
|
||||||
|
|
||||||
|
fun addItem(stack: ItemStack, simulate: Boolean, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null, ignoreFilters: Boolean): ItemStack {
|
||||||
|
if (stack.isEmpty || slots.isEmpty())
|
||||||
|
return stack
|
||||||
|
|
||||||
|
if (ignoreFilters || !hasFilterableSlots) {
|
||||||
|
return addItem(stack.copy(), simulate, filterPass = true, slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = true)
|
||||||
|
} else {
|
||||||
|
var copy = addItem(stack.copy(), simulate, filterPass = true, slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
||||||
|
copy = addItem(copy, simulate, filterPass = false, slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlike [addItem], modifies original [stack]
|
||||||
|
*
|
||||||
|
* @return Whenever [stack] was modified
|
||||||
|
*/
|
||||||
|
fun consumeItem(stack: ItemStack, simulate: Boolean, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null, ignoreFilters: Boolean): Boolean {
|
||||||
|
if (stack.isEmpty)
|
||||||
|
return false
|
||||||
|
|
||||||
|
val result = addItem(stack, simulate = simulate, slots = slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = ignoreFilters)
|
||||||
|
if (!simulate) stack.count = result.count
|
||||||
|
return result.count != stack.count
|
||||||
|
}
|
||||||
|
|
||||||
|
fun fullyAddItem(stack: ItemStack, slots: IntCollection = slotRange, onlyIntoExisting: Boolean = false, popTime: Int? = null, ignoreFilters: Boolean): Boolean {
|
||||||
|
if (!addItem(stack, simulate = true, slots = slots, popTime = popTime, onlyIntoExisting = onlyIntoExisting, ignoreFilters = ignoreFilters).isEmpty)
|
||||||
|
return false
|
||||||
|
|
||||||
|
return addItem(stack, simulate = false, slots = slots, popTime = popTime, onlyIntoExisting = onlyIntoExisting, ignoreFilters = ignoreFilters).isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addItem(
|
||||||
|
stack: ItemStack,
|
||||||
|
simulate: Boolean,
|
||||||
|
slots: IntCollection,
|
||||||
|
onlyIntoExisting: Boolean,
|
||||||
|
popTime: Int?
|
||||||
|
): ItemStack {
|
||||||
|
return addItem(stack, simulate = simulate, slots = slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun consumeItem(
|
||||||
|
stack: ItemStack,
|
||||||
|
simulate: Boolean,
|
||||||
|
slots: IntCollection,
|
||||||
|
onlyIntoExisting: Boolean,
|
||||||
|
popTime: Int?
|
||||||
|
): Boolean {
|
||||||
|
return consumeItem(stack, simulate = simulate, slots = slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun fullyAddItem(stack: ItemStack, slots: IntCollection, onlyIntoExisting: Boolean, popTime: Int?): Boolean {
|
||||||
|
return fullyAddItem(stack, slots = slots, onlyIntoExisting = onlyIntoExisting, popTime = popTime, ignoreFilters = false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,4 @@ class ExopackContainer(size: Int, val player: MatteryPlayer) : EnhancedContainer
|
|||||||
override fun containerSlot(slot: Int): IPlayerInventorySlot {
|
override fun containerSlot(slot: Int): IPlayerInventorySlot {
|
||||||
return Slot(slot)
|
return Slot(slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val hasFilterableSlots: Boolean
|
|
||||||
get() = true
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user