From 7c4b000670bb0e8a9e60aa25649ab2b39d8b3b9a Mon Sep 17 00:00:00 2001
From: "Plamen K. Kosseff"
Date: Sat, 1 Apr 2023 18:49:27 +0300
Subject: [PATCH] Added support for sorting by accumulated item count.
---
build.gradle.kts | 2 +-
changelog.md | 37 ++++++++++++++++---
.../compat/integrations/Integrations.kt | 6 +++
.../mc/ipnext/ingame/VanillaAccessors.kt | 13 +++++--
.../mc/ipnext/item/ItemTypeExtensions.kt | 6 ++-
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../mc/ipnext/item/ItemTypeExtensions.kt | 2 +-
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../mc/ipnext/item/ItemTypeExtensions.kt | 2 +-
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../mc/ipnext/item/ItemTypeExtensions.kt | 2 +-
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../mc/ipnext/item/ItemTypeExtensions.kt | 2 +-
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../mc/ipnext/item/ItemTypeExtensions.kt | 3 +-
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../inventoryprofilesnext/config/rules.txt | 6 +++
platforms/forge-1.19/build.gradle.kts | 3 ++
.../inventoryprofilesnext/config/rules.txt | 6 +++
.../anti_ad/mc/ipnext/config/ConfigEnums.kt | 2 +
.../mc/ipnext/input/InventoryInputHandler.kt | 4 +-
.../mc/ipnext/inventory/AdvancedContainer.kt | 12 ++++--
.../inventory/GeneralInventoryActions.kt | 4 +-
.../ScoreBasedDualDiffCalculatorInstance.kt | 7 +++-
.../SimpleDiffCalculatorInstance.kt | 22 +++++------
.../org/anti_ad/mc/ipnext/item/ItemStack.kt | 18 +++++++--
.../org/anti_ad/mc/ipnext/item/ItemType.kt | 24 +++++++++---
.../org/anti_ad/mc/ipnext/item/rule/Rule.kt | 17 +++------
.../item/rule/natives/DefinedNativeRules.kt | 3 ++
.../java/org/anti_ad/mc/ipnext/util/Bucket.kt | 10 +++--
.../inventoryprofilesnext/lang/en_us.json | 2 +
.../inventoryprofilesnext/lang/uk_ua.json | 2 +-
34 files changed, 202 insertions(+), 63 deletions(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index 8cd5c141..53c5c2ce 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -88,7 +88,7 @@ allprojects {
group = "org.anti-ad.mc"
ext.set("mod_artefact_version", versionObj.toCleanString())
ext.set("mod_artefact_is_release", versionObj.isRelease())
- ext.set("libIPN_version", "2.0.5-SNAPSHOT")
+ ext.set("libIPN_version", "2.0.4")
tasks.withType().configureEach {
options.isFork = true
diff --git a/changelog.md b/changelog.md
index 1400ac90..01812d4b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,36 @@
+### 1.9.5
+
+- Added support for sorting based on the accumulated count of item type.
+ It can be selected in `Mod Settings -> Sort Order` there are two variants `Item Count Ascending` and `Item Count Descending`.
+
+ It also can be used in custom rules like this `::accumulated_count(number_order = ascending)`, by default the rule is in descending order.
+- Added full support for [Carpet's](https://www.curseforge.com/minecraft/mc-mods/carpet) stacable empty shulker boxes. Works only in 1.18-1.19.
+ Doesn't support the forge port of Carpet. *You need to have carpet installed on the client.*
+ 1.16 is not supported due to limitations in Carpet for that version of minecraft.
+- Other oversized stacks are now always left in their original positions when sorting.
+
+
+### WARNING
+
+Due to multiple Quilt specific crashes and one item duplication Quilt support is now defined as fallows:
+
+```
+This mod will work on Quilt using the offered Fabric compatibility.
+Any problems that are not reproducible on Fabric will be addressed with very low priority.
+```
+
+#### Supported Minecraft versions
+- **1.16.x**
+- **1.18.2**
+- **1.19[.1-2]**
+- **1.19.3**
+- **1.19.4**
+
+
+
+
### 1.9.4
- Added support for 1.19.4 Forge.
@@ -33,8 +64,6 @@ Any problems that are not reproducible on Fabric will be addressed with very low
### Become a [Patreon](https://www.patreon.com/mirinimi/membership) to gain early access
-
-
### 1.9.2
@@ -52,10 +81,6 @@ Any problems that are not reproducible on Fabric will be addressed with very low
- **1.19.3**
-
-
-
-
### 1.9.1
- Added translation for Chinese Traditional thanks to 午夜的大叔
diff --git a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt
index 64e4bfdf..21aa29e9 100644
--- a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt
+++ b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/compat/integrations/Integrations.kt
@@ -20,6 +20,7 @@
package org.anti_ad.mc.ipnext.compat.integrations
import org.anti_ad.mc.common.extensions.trySwallow
+import org.anti_ad.mc.common.vanilla.alias.Slot
object Integrations {
@@ -31,9 +32,14 @@ object Integrations {
}
+ var ___getSophisticatedMaxCount: (Slot) -> Int = { -1 }
+
+
fun init() {
trySwallow {
CarpetIntegration().init()
}
}
+
+ fun sophisticatedMaxCount(sourceSlot: Slot): Int = ___getSophisticatedMaxCount(sourceSlot)
}
diff --git a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/ingame/VanillaAccessors.kt b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/ingame/VanillaAccessors.kt
index 997d3bc6..5eb6b339 100644
--- a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/ingame/VanillaAccessors.kt
+++ b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/ingame/VanillaAccessors.kt
@@ -64,13 +64,18 @@ import org.anti_ad.mc.common.vanilla.alias.ItemStack as VanillaItemStack
// use `()` to avoid potential mapping name collision
-inline val VanillaItemStack.`(itemType)`: ItemType
+val VanillaItemStack.`(itemType)`: ItemType
get() = ItemType(item,
tag,
- { isDamageable })
+ { isDamageable },
+ stackSource = { v: ItemType ->
+ ItemStack(v, count)
+ })
+
inline val VanillaItemStack.`(itemStack)`: ItemStack
get() = if (isEmpty) ItemStack.EMPTY else ItemStack(`(itemType)`,
count)
+
inline val VanillaItemStack.`(mutableItemStack)`: MutableItemStack
get() = if (isEmpty) MutableItemStack.empty() else MutableItemStack(`(itemType)`,
count)
@@ -86,11 +91,11 @@ inline val Slot.`(id)`
inline val Slot.`(invSlot)`
get() = (this as IMixinSlot).invSlot
inline val Slot.`(itemStack)`: ItemStack
- get() = stack.`(itemStack)`
+ get() = stack.`(itemStack)`.also { it.sourceSlot = this }
inline val Slot.`(vanillaStack)`: VanillaItemStack
get() = this.stack
inline val Slot.`(mutableItemStack)`: MutableItemStack
- get() = stack.`(mutableItemStack)`
+ get() = stack.`(mutableItemStack)`.also { it.sourceSlot = this }
inline val Slot.`(inventory)`: Inventory
get() = inventory
inline val Slot.`(inventoryOrNull)`: Inventory?
diff --git a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
index 1dac749e..bd520d17 100644
--- a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
+++ b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
@@ -22,9 +22,9 @@ package org.anti_ad.mc.ipnext.item
import net.minecraft.block.ShulkerBoxBlock
import net.minecraft.entity.effect.StatusEffectType
+import net.minecraft.item.BlockItem
import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.common.extensions.ifTrue
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Enchantment
import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper
import org.anti_ad.mc.common.vanilla.alias.FoodComponent
@@ -87,8 +87,12 @@ inline val ItemType.isEmptyShulker: Boolean
inline val ItemType.maxCount: Int
get() {
val carpetEmptyShulkersStackSize = Integrations.carpetEmptyShulkersStackSize
+ val slot = sourceStack?.sourceSlot
+
return if (carpetEmptyShulkersStackSize > 1 && isEmptyShulker) {
carpetEmptyShulkersStackSize
+ } else if (slot != null && Integrations.sophisticatedMaxCount(slot) != -1) {
+ return Integrations.sophisticatedMaxCount(slot)
} else {
vanillaStack.maxCount
}
diff --git a/platforms/fabric-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/fabric-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 48fd46fb..40539813 100644
--- a/platforms/fabric-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/fabric-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -30,3 +30,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/fabric-1.18.2/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.18.2/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
index fb0de603..3a778f78 100644
--- a/platforms/fabric-1.18.2/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
+++ b/platforms/fabric-1.18.2/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
@@ -24,9 +24,9 @@ package org.anti_ad.mc.ipnext.item
import net.minecraft.block.ShulkerBoxBlock
import net.minecraft.entity.effect.StatusEffectCategory
+import net.minecraft.item.BlockItem
import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.common.extensions.ifTrue
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Enchantment
import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper
import org.anti_ad.mc.common.vanilla.alias.FoodComponent
diff --git a/platforms/fabric-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/fabric-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 48fd46fb..40539813 100644
--- a/platforms/fabric-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/fabric-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -30,3 +30,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/fabric-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
index 8dcaa2bc..4418d6c0 100644
--- a/platforms/fabric-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
+++ b/platforms/fabric-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
@@ -24,11 +24,11 @@ package org.anti_ad.mc.ipnext.item
import net.minecraft.block.ShulkerBoxBlock
import net.minecraft.entity.effect.StatusEffectCategory
+import net.minecraft.item.BlockItem
import net.minecraft.text.TranslatableTextContent
import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.common.extensions.ifTrue
import org.anti_ad.mc.common.vanilla.Vanilla
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Enchantment
import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper
import org.anti_ad.mc.common.vanilla.alias.FoodComponent
diff --git a/platforms/fabric-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/fabric-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 41669c2a..65280c47 100644
--- a/platforms/fabric-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/fabric-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -29,3 +29,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/fabric-1.19.4/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.19.4/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
index 6010ceb2..f0981086 100644
--- a/platforms/fabric-1.19.4/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
+++ b/platforms/fabric-1.19.4/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
@@ -24,11 +24,11 @@ package org.anti_ad.mc.ipnext.item
import net.minecraft.block.ShulkerBoxBlock
import net.minecraft.entity.effect.StatusEffectCategory
+import net.minecraft.item.BlockItem
import net.minecraft.text.TranslatableTextContent
import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.common.extensions.ifTrue
import org.anti_ad.mc.common.vanilla.Vanilla
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Enchantment
import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper
import org.anti_ad.mc.common.vanilla.alias.FoodComponent
diff --git a/platforms/fabric-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/fabric-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 41669c2a..65280c47 100644
--- a/platforms/fabric-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/fabric-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -29,3 +29,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/fabric-1.19/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.19/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
index d89eb6bf..84ad9153 100644
--- a/platforms/fabric-1.19/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
+++ b/platforms/fabric-1.19/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
@@ -24,9 +24,9 @@ package org.anti_ad.mc.ipnext.item
import net.minecraft.block.ShulkerBoxBlock
import net.minecraft.entity.effect.StatusEffectCategory
+import net.minecraft.item.BlockItem
import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.common.extensions.ifTrue
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Enchantment
import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper
import org.anti_ad.mc.common.vanilla.alias.FoodComponent
diff --git a/platforms/fabric-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/fabric-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 48fd46fb..40539813 100644
--- a/platforms/fabric-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/fabric-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -30,3 +30,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/forge-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/forge-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 48fd46fb..40539813 100644
--- a/platforms/forge-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/forge-1.16/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -30,3 +30,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/forge-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/forge-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 48fd46fb..40539813 100644
--- a/platforms/forge-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/forge-1.18.2/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -30,3 +30,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/forge-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/forge-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
index 01bf4838..8aeb11d9 100644
--- a/platforms/forge-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
+++ b/platforms/forge-1.19.3/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt
@@ -24,12 +24,12 @@ package org.anti_ad.mc.ipnext.item
import net.minecraft.network.chat.contents.TranslatableContents
import net.minecraft.world.effect.MobEffectCategory
+import net.minecraft.world.item.BlockItem
import net.minecraft.world.level.block.ShulkerBoxBlock
import net.minecraftforge.common.extensions.IForgeFluid
import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.common.extensions.ifTrue
import org.anti_ad.mc.common.vanilla.Vanilla
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Enchantment
import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper
import org.anti_ad.mc.common.vanilla.alias.FoodComponent
@@ -110,7 +110,6 @@ fun ItemType.vanillaStackWithCount(count: Int): VanillaItemStack =
VanillaItemStack(this.item,
count).apply { tag = this@vanillaStackWithCount.tag }
-@Suppress("DEPRECATION")
inline val ItemType.identifier: Identifier
get() = ForgeRegistries.ITEMS.getKey(item)!! // `(getIdentifier)`(item)
diff --git a/platforms/forge-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/forge-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 41669c2a..65280c47 100644
--- a/platforms/forge-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/forge-1.19.3/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -29,3 +29,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/forge-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/forge-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 41669c2a..65280c47 100644
--- a/platforms/forge-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/forge-1.19.4/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -29,3 +29,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/platforms/forge-1.19/build.gradle.kts b/platforms/forge-1.19/build.gradle.kts
index 668fea3d..b7cf723f 100644
--- a/platforms/forge-1.19/build.gradle.kts
+++ b/platforms/forge-1.19/build.gradle.kts
@@ -149,6 +149,9 @@ configurations {
dependencies {
//runtimeOnly( fg.deobf("curse.maven:iron-furnaces-237664:4009901"))
+ runtimeOnly( fg.deobf("curse.maven:sophisticated-storage-619320:4231388"))
+ runtimeOnly( fg.deobf("curse.maven:sophisticated-core-618298:4329953"))
+ runtimeOnly( fg.deobf("curse.maven:sophisticated-backpacks-422301:4329957"))
}
tasks.named("compileKotlin") {
diff --git a/platforms/forge-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt b/platforms/forge-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
index 48fd46fb..40539813 100644
--- a/platforms/forge-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
+++ b/platforms/forge-1.19/src/main/resources/assets/inventoryprofilesnext/config/rules.txt
@@ -30,3 +30,9 @@
@auto_refill_best
@default_nbt_rule
+
+@accumulated_count_descending
+ ::accumulated_count(number_order = descending)
+
+@accumulated_count_ascending
+ ::accumulated_count(number_order = ascending)
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/config/ConfigEnums.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/config/ConfigEnums.kt
index 15a97178..a7fad309 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/config/ConfigEnums.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/config/ConfigEnums.kt
@@ -31,6 +31,8 @@ enum class SortingMethod(val ruleName: String?) {
ITEM_NAME("item_name"),
ITEM_ID("item_id"),
RAW_ID("raw_id"),
+ ACCUMULATED_COUNT_DESCENDING("accumulated_count_descending"),
+ ACCUMULATED_COUNT_ASCENDING("accumulated_count_ascending"),
CUSTOM(null);
override fun toString(): String =
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/input/InventoryInputHandler.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/input/InventoryInputHandler.kt
index 4df2c549..88490268 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/input/InventoryInputHandler.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/input/InventoryInputHandler.kt
@@ -34,8 +34,8 @@ object InventoryInputHandler : IInputHandler {
override fun onInput(lastKey: Int,
lastAction: Int): Boolean {
if (!VanillaUtil.inGame()) return false
- val scr = Vanilla.screen();
- val ctr = Vanilla.container();
+ val scr = Vanilla.screen()
+ val ctr = Vanilla.container()
if (scr != null && scr is ContainerScreen<*> ) {
val screenHints = HintsManagerNG.getHints(scr.javaClass)
val containerHints = HintsManagerNG.getHints(ctr.javaClass)
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/AdvancedContainer.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/AdvancedContainer.kt
index 70b04bd2..e365b2e0 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/AdvancedContainer.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/AdvancedContainer.kt
@@ -100,6 +100,7 @@ class AdvancedContainer(private val vanillaContainer: Container,
val sandboxTracker: ItemTracker
get() = sandbox.items
+
val ItemArea.asSubTracker: SubTracker
get() = sandboxTracker.subTracker(this.slotIndices)
}
@@ -111,6 +112,7 @@ class AdvancedContainer(private val vanillaContainer: Container,
}
open inner class AdvancedContainerDsl {
+
fun AreaType.get(): ItemArea {
return getItemArea(vanillaContainer,
vanillaSlots)
@@ -135,10 +137,12 @@ class AdvancedContainer(private val vanillaContainer: Container,
companion object {
fun create(): AdvancedContainer {
- return when (val container = Vanilla.container()) {
- is CreativeContainer -> Vanilla.playerContainer()
- else -> container
- }.let { AdvancedContainer(it) }
+ val container = Vanilla.container()
+ return AdvancedContainer(if (container is CreativeContainer) {
+ Vanilla.playerContainer()
+ } else {
+ container
+ })
}
inline operator fun invoke(instant: Boolean = false,
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt
index 0dcc2471..114a5c4f 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/GeneralInventoryActions.kt
@@ -370,8 +370,8 @@ private object InnerActions {
fun doSort(sortingRule: Rule,
postAction: PostAction) = tryCatch {
- innerDoSort(sortingRule,
- postAction)
+ innerDoSort(sortingRule,
+ postAction)
}
fun innerDoSort(sortingRule: Rule,
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/ScoreBasedDualDiffCalculatorInstance.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/ScoreBasedDualDiffCalculatorInstance.kt
index 3abac0e6..f54378d9 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/ScoreBasedDualDiffCalculatorInstance.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/ScoreBasedDualDiffCalculatorInstance.kt
@@ -31,6 +31,8 @@ import org.anti_ad.mc.ipnext.inventory.sandbox.toList
import org.anti_ad.mc.ipnext.item.ItemType
import org.anti_ad.mc.ipnext.item.isEmpty
import org.anti_ad.mc.ipnext.item.maxCount
+import org.anti_ad.mc.ipnext.item.rule.CountSink
+import org.anti_ad.mc.ipnext.item.rule.CountSource
import org.anti_ad.mc.ipnext.util.MutableBucket
class ScoreBasedDualDiffCalculatorInstance(sandbox: ContainerSandbox,
@@ -206,7 +208,7 @@ object SingleType : DiffCalculatorUtil {
}
data class Slot(val n: Int,
- val g: Int) {
+ val g: Int): CountSink {
val isGoal
get() = n == g
val rank
@@ -230,6 +232,9 @@ object SingleType : DiffCalculatorUtil {
}
}
}
+
+ override fun setCountSource(source: CountSource) {
+ }
}
// notice maxCount not in hashCode/equals, only c and identities
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/SimpleDiffCalculatorInstance.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/SimpleDiffCalculatorInstance.kt
index 325061bc..6a26d131 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/SimpleDiffCalculatorInstance.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/inventory/sandbox/diffcalculator/SimpleDiffCalculatorInstance.kt
@@ -79,12 +79,10 @@ open class SimpleDiffCalculatorInstance(sandbox: ContainerSandbox,
private val CompareSlotDsl.nowMoreThanEqualGoal // = equals || nowMoreThanGoal
get() = equalsType && now.count >= goal.count
- private inline fun Iterable.filtered(
- skipEquals: Boolean = true, // notice skip equals default to true
- skipEmptyNow: Boolean = false,
- skipEmptyGoal: Boolean = false,
- predicate: CompareSlotDsl.() -> Boolean
- ): List {
+ private inline fun Iterable.filtered(skipEquals: Boolean = true, // notice skip equals default to true
+ skipEmptyNow: Boolean = false,
+ skipEmptyGoal: Boolean = false,
+ predicate: CompareSlotDsl.() -> Boolean): List {
return this.filter {
with(it) {
val skip = skipEquals && equals
@@ -186,12 +184,12 @@ open class SimpleDiffCalculatorInstance(sandbox: ContainerSandbox,
?.run { return leftClick() }
error("should not reach here")
}
- candidate.filtered { nowGoalRemaining > 0 }
- .minByOrNull { it.nowGoalRemaining }
- ?.run {
- check(nowGoalRemaining < cursorNow.count)
- return repeatRightClick(nowGoalRemaining)
- } // nowGoalRemaining should < cursorNow.count
+ candidate.filtered { nowGoalRemaining > 0 }.minByOrNull {
+ it.nowGoalRemaining
+ }?.run {
+ check(nowGoalRemaining < cursorNow.count)
+ return repeatRightClick(nowGoalRemaining)
+ } // nowGoalRemaining should < cursorNow.count
error("should not reach here")
}
}
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemStack.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemStack.kt
index bdb4a682..74839e93 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemStack.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemStack.kt
@@ -20,9 +20,12 @@
package org.anti_ad.mc.ipnext.item
+import org.anti_ad.mc.common.vanilla.alias.Slot
+
sealed class ItemStack {
abstract val itemType: ItemType
abstract val count: Int
+ abstract var sourceSlot: Slot?
operator fun component1() = itemType
operator fun component2() = count
@@ -60,7 +63,8 @@ sealed class ItemStack {
fun copyAsMutable(): MutableItemStack {
return MutableItemStack(itemType,
- count)
+ count,
+ sourceSlot)
}
companion object {
@@ -73,9 +77,17 @@ sealed class ItemStack {
}
class ImmutableItemStack(override val itemType: ItemType,
- override val count: Int) : ItemStack()
+ override val count: Int,
+ aSourceSlot: Slot? = null) : ItemStack() {
+
+ override var sourceSlot: Slot? = aSourceSlot
+}
class MutableItemStack(override var itemType: ItemType,
- override var count: Int) : ItemStack() {
+ override var count: Int,
+ aSourceSlot: Slot? = null) : ItemStack() {
+
+ override var sourceSlot: Slot? = aSourceSlot
+
companion object
}
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemType.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemType.kt
index 565b730d..a0e2ec91 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemType.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/ItemType.kt
@@ -20,24 +20,31 @@
package org.anti_ad.mc.ipnext.item
-import org.anti_ad.mc.common.vanilla.alias.BlockItem
import org.anti_ad.mc.common.vanilla.alias.Item
import org.anti_ad.mc.common.vanilla.alias.Items
import org.anti_ad.mc.common.vanilla.alias.NbtCompound
-import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.ipnext.ingame.`(keys)`
-
-
+import org.anti_ad.mc.ipnext.item.rule.CountSink
+import org.anti_ad.mc.ipnext.item.rule.CountSource
// different nbt is treated as different type, as they can't stack together
data class ItemType(val item: Item,
private val aTag: NbtCompound?,
val isDamageableFn: (() -> Boolean),
var ignoreDurability: Boolean = false,
- private val isDamageable: Boolean = isDamageableFn()) {
+ private val isDamageable: Boolean = isDamageableFn(),
+ private var stackSource: (ItemType) -> ItemStack? = { null }): CountSink {
+
+ val sourceStack: ItemStack? = stackSource(this)
val tag: NbtCompound?
+ val accumulatedCount: Int
+ get() {
+ return countSource.count(this)
+ }
+
+
init {
//if (null == aTag) Log.trace("aTag = NULL here", Exception())
tag = if (aTag == null && item != Items.AIR) NbtCompound() else aTag
@@ -94,7 +101,14 @@ data class ItemType(val item: Item,
result = 31 * result + tagHashCode()
return result
}
+
companion object {
}
+
+ private var countSource: CountSource = CountSource { _ -> 0 }
+
+ override fun setCountSource(source: CountSource) {
+ countSource = source
+ }
}
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/Rule.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/Rule.kt
index d98e2e6c..1e1be4c3 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/Rule.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/Rule.kt
@@ -25,21 +25,17 @@ import org.anti_ad.mc.ipnext.item.rule.parameter.reverse
import org.anti_ad.mc.ipnext.item.rule.parameter.sub_rule
-interface CountSource {
- fun get(itemType: ItemType): Int
+fun interface CountSource {
+ fun count(element: T): Int
}
-object DefaultCountSource: CountSource {
-
- override fun get(itemType: ItemType): Int {
- return 0
- }
-
+interface CountSink {
+ fun setCountSource(source: CountSource)
}
interface Rule : Comparator {
val arguments: ArgumentMap
- var countSource: CountSource
+
override fun compare(itemType1: ItemType,
itemType2: ItemType): Int
} // todo toString()
@@ -49,7 +45,6 @@ object EmptyRule : Rule {
override val arguments: ArgumentMap
get() = ArgumentMap()
- override var countSource: CountSource = DefaultCountSource
override fun compare(itemType1: ItemType,
itemType2: ItemType): Int {
@@ -61,8 +56,6 @@ class MutableEmptyRule : BaseRule()
abstract class BaseRule : Rule {
- override var countSource: CountSource = DefaultCountSource
-
final override val arguments = ArgumentMap()
var comparator: (ItemType, ItemType) -> Int = { _, _ -> 0 }
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/natives/DefinedNativeRules.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/natives/DefinedNativeRules.kt
index ef67ae17..2eea31fb 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/natives/DefinedNativeRules.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/item/rule/natives/DefinedNativeRules.kt
@@ -126,6 +126,9 @@ val max_damage /**/ by type(::NumberBasedRule) { it.maxDamage }
val durability /**/ by type(::NumberBasedRule) { it.durability }
val enchantments_score /**/ by type(::NumberBasedRule) { it.enchantmentsScore }.param(number_order,
DESCENDING)
+val accumulated_count /**/ by type(::NumberBasedRule) {
+ it.accumulatedCount
+}.param(number_order, DESCENDING)
// ============
// Boolean Type Rule
diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/util/Bucket.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/util/Bucket.kt
index c9e85b0c..a9a2e32d 100644
--- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/util/Bucket.kt
+++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/util/Bucket.kt
@@ -20,9 +20,12 @@
package org.anti_ad.mc.ipnext.util
-interface Bucket {
+import org.anti_ad.mc.ipnext.item.rule.CountSink
+import org.anti_ad.mc.ipnext.item.rule.CountSource
+
+interface Bucket>: CountSource {
val size: Int
- fun count(element: T): Int
+ override fun count(element: T): Int
fun contains(element: T): Boolean
fun contains(element: T,
count: Int): Boolean
@@ -34,7 +37,7 @@ interface Bucket {
fun isEmpty(): Boolean
}
-open class MutableBucket protected constructor(innerMap: Map) : Bucket { /* : MutableCollection */
+open class MutableBucket> protected constructor(innerMap: Map) : Bucket { /* : MutableCollection */
constructor() : this(mapOf())
protected open fun validateEmpty(element: T): Boolean { // determine whether the element can be added to this collection
@@ -57,6 +60,7 @@ open class MutableBucket protected constructor(innerMap: Map) : Bucke
fun add(element: T,
count: Int): Boolean {
if (validateEmpty(element) || count <= 0) return false
+ element.setCountSource(this)
innerMap[element] = count(element) + count
return true
}
diff --git a/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json b/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json
index 7847fb03..0ed7cbe2 100644
--- a/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json
+++ b/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json
@@ -375,6 +375,8 @@
"inventoryprofiles.enum.sorting_method.item_name": "Item Name",
"inventoryprofiles.enum.sorting_method.item_id": "Item ID",
"inventoryprofiles.enum.sorting_method.raw_id": "Item Numerical ID",
+ "inventoryprofiles.enum.sorting_method.accumulated_count_descending": "Item Count Descending",
+ "inventoryprofiles.enum.sorting_method.accumulated_count_ascending": "Item Count Ascending",
"inventoryprofiles.enum.sorting_method.custom": "Custom Rule",
"inventoryprofiles.enum.post_action.none": "None",
"inventoryprofiles.enum.post_action.group_in_rows": "Group In Rows",
diff --git a/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/uk_ua.json b/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/uk_ua.json
index 9eaa3a0b..24936d1b 100644
--- a/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/uk_ua.json
+++ b/shared-sources/src/main/resources/assets/inventoryprofilesnext/lang/uk_ua.json
@@ -326,7 +326,7 @@
"inventoryprofiles.config.name.save_as_profile": "Зберегти інвентар як \"Збережений\" профіль",
"inventoryprofiles.config.name.scroll_to_chest": "Прокруч. предмети від гравця до скрині",
"inventoryprofiles.config.name.scroll_to_inventory": "Прокруч. предмети від скрині до гравця",
- "inventoryprofiles.config.description.save_as_profile": "Гаряча клавіша для збереження поточного інвентарю як профілю з назвою \"Збережений\".\nВи можете використовувати Збережені профілі для створення власних.\n\n§l§cПРИМІТКА§r:\nКОЖНОГО РАЗУ, коли ви натискаєте цю кнопку, створюється новий профіль під назвою \"Збережений\".\n\Клавіші переходу на наступний/попередній профіль не переходитимуть на Збережені профілі. Також Збережені профілі не можуть бути призначені як швидкі профілі.",
+ "inventoryprofiles.config.description.save_as_profile": "Гаряча клавіша для збереження поточного інвентарю як профілю з назвою \"Збережений\".\nВи можете використовувати Збережені профілі для створення власних.\n\n§l§cПРИМІТКА§r:\nКОЖНОГО РАЗУ, коли ви натискаєте цю кнопку, створюється новий профіль під назвою \"Збережений\".\nКлавіші переходу на наступний/попередній профіль не переходитимуть на Збережені профілі. Також Збережені профілі не можуть бути призначені як швидкі профілі.",
"inventoryprofiles.config.description.next_profile": "Гаряча клавіша для переходу до наступного профілю.",
"inventoryprofiles.config.description.prev_profile": "Гаряча клавіша для переходу до попереднього профілю.",
"inventoryprofiles.config.description.profile_1": "Гаряча клавіша для зміни на швидкий профіль №1.\nВи можете налаштувати швидкі профілі на сторінці Редагування профілів.",