Skip to content

Commit

Permalink
Added support for sorting by accumulated item count.
Browse files Browse the repository at this point in the history
  • Loading branch information
blackd committed Apr 1, 2023
1 parent 5422359 commit 7c4b000
Show file tree
Hide file tree
Showing 34 changed files with 202 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaCompile>().configureEach {
options.isFork = true
Expand Down
37 changes: 31 additions & 6 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
<!-- latest begin -->

### 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**

<!-- latest end -->
<!-- rest begin -->

### 1.9.4

- Added support for 1.19.4 Forge.
Expand Down Expand Up @@ -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

<!-- latest end -->


### 1.9.2

Expand All @@ -52,10 +81,6 @@ Any problems that are not reproducible on Fabric will be addressed with very low
- **1.19.3**


<!-- latest end -->

<!-- rest begin -->

### 1.9.1

- Added translation for Chinese Traditional thanks to 午夜的大叔
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -31,9 +32,14 @@ object Integrations {
}


var ___getSophisticatedMaxCount: (Slot) -> Int = { -1 }


fun init() {
trySwallow {
CarpetIntegration().init()
}
}

fun sophisticatedMaxCount(sourceSlot: Slot): Int = ___getSophisticatedMaxCount(sourceSlot)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions platforms/forge-1.19/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -111,6 +112,7 @@ class AdvancedContainer(private val vanillaContainer: Container,
}

open inner class AdvancedContainerDsl {

fun AreaType.get(): ItemArea {
return getItemArea(vanillaContainer,
vanillaSlots)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ private object InnerActions {

fun doSort(sortingRule: Rule,
postAction: PostAction) = tryCatch {
innerDoSort(sortingRule,
postAction)
innerDoSort(sortingRule,
postAction)
}

fun innerDoSort(sortingRule: Rule,
Expand Down
Loading

0 comments on commit 7c4b000

Please sign in to comment.