Skip to content

Commit

Permalink
Fixed villager bookmarks.
Browse files Browse the repository at this point in the history
Fixed item comparison when durability is ignored.
  • Loading branch information
blackd committed Aug 3, 2024
1 parent d0ef843 commit a186e5f
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 69 deletions.
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
* in when inventory is opened `left control + left click`
* in game `left control + r`

- Villager bookmarks now support cost items with changed components. This is useful with some shop plugins.

#### fixes
- fixed bug where non-stackable damageable items will not be moved or dropped properly
- fixed issue where non-stackable damageable items will not be moved or dropped properly
- fixed issue where item highlight won't work properly for damageable items
- fixed issue where auto refill won't work properly for damageable items
- fixed issue that made villager bookmarks ignore the resulting item components

#### Forge and NeoForge versions are now considered stable

Expand Down
2 changes: 1 addition & 1 deletion platforms/fabric-1.21/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ modrinth {
versionName.set("IPN $mod_version for $mod_loader $minecraft_version_string")
this.changelog.set(project.rootDir.resolve("description/out/pandoc-release_notes.md").readText())
loaders.add(mod_loader)
//loaders.add("quilt")
loaders.add("quilt")
dependencies.set(
mutableListOf(
ModDependency("P7dR8mSH", "required"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.anti_ad.mc.ipnext.item

import com.mojang.serialization.Codec
import org.anti_ad.mc.alias.component.ComponentChanges
import org.anti_ad.mc.alias.component.ComponentType
import org.anti_ad.mc.alias.component.DataComponentTypes
import org.anti_ad.mc.alias.component.type.DyedColorComponent
Expand All @@ -43,6 +44,7 @@ import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.ipnext.ingame.`(itemType)`
import org.anti_ad.mc.ipnext.item.NbtUtils.compareTo
import java.util.*
import java.util.function.*
import kotlin.Comparator

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -253,4 +255,6 @@ object ComponentUtils {

return newLevels
}

fun ComponentChanges.`(withRemovedIf)`(predicate: Predicate<ComponentType<*>>): ComponentChanges = this.withRemovedIf(predicate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ inline val ItemType.searchItemStack: VanillaItemStack
}

inline val ItemType.vanillaStack: VanillaItemStack
get() = VanillaItemStack(this.item, 1, this@vanillaStack.tag) // nbt was tag
get() {
val tag = ComponentMapImpl(this@vanillaStack.tag)
tag.changes = this@vanillaStack.changes
return VanillaItemStack(this.item, 1, tag)
}

fun ItemType.vanillaStackWithCount(count: Int): VanillaItemStack =
VanillaItemStack(this.item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,15 @@ object NbtUtils {
target: NbtElement): List<NbtElement> {
return trySwallow(listOf()) { nbtPath.get(target) }
}

fun NbtElement?.nullIfEmpty(): NbtElement? {
return if (this == null) {
null
}
else if (this is NbtCompound && this.isEmpty || this is NbtList && this.isEmpty()) {
null
} else {
this
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.anti_ad.mc.ipnext.item

import com.mojang.serialization.Codec
import org.anti_ad.mc.alias.component.ComponentChanges
import org.anti_ad.mc.alias.component.ComponentType
import org.anti_ad.mc.alias.component.DataComponentTypes
import org.anti_ad.mc.alias.component.type.DyedColorComponent
Expand All @@ -43,6 +44,7 @@ import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.ipnext.ingame.`(itemType)`
import org.anti_ad.mc.ipnext.item.NbtUtils.compareTo
import java.util.*
import java.util.function.*
import kotlin.Comparator

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -253,4 +255,6 @@ object ComponentUtils {

return newLevels
}

fun ComponentChanges.`(withRemovedIf)`(predicate: Predicate<ComponentType<*>>): ComponentChanges = this.forget(predicate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,15 @@ object NbtUtils {
target: NbtElement): List<NbtElement> {
return trySwallow(listOf()) { nbtPath.get(target) } // func_218071_a() = get()
}

fun NbtElement?.nullIfEmpty(): NbtElement? {
return if (this == null) {
null
}
else if (this is NbtCompound && this.isEmpty || this is NbtList && this.isEmpty()) {
null
} else {
this
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.anti_ad.mc.ipnext.item

import com.mojang.serialization.Codec
import org.anti_ad.mc.alias.component.ComponentChanges
import org.anti_ad.mc.alias.component.ComponentType
import org.anti_ad.mc.alias.component.DataComponentTypes
import org.anti_ad.mc.alias.component.type.DyedColorComponent
Expand All @@ -43,6 +44,7 @@ import org.anti_ad.mc.ipnext.Log
import org.anti_ad.mc.ipnext.ingame.`(itemType)`
import org.anti_ad.mc.ipnext.item.NbtUtils.compareTo
import java.util.*
import java.util.function.*
import kotlin.Comparator

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -253,4 +255,6 @@ object ComponentUtils {

return newLevels
}

fun ComponentChanges.`(withRemovedIf)`(predicate: Predicate<ComponentType<*>>): ComponentChanges = this.forget(predicate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,16 @@ object NbtUtils {
target: NbtElement): List<NbtElement> {
return trySwallow(listOf()) { nbtPath.get(target) } // func_218071_a() = get()
}

fun NbtElement?.nullIfEmpty(): NbtElement? {
return if (this == null) {
null
}
else if (this is NbtCompound && this.isEmpty || this is NbtList && this.isEmpty()) {
null
} else {
this
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ import kotlinx.serialization.Transient
import org.anti_ad.mc.alias.nbt.NbtElement

import org.anti_ad.mc.ipnext.item.NbtUtils
import org.anti_ad.mc.ipnext.item.NbtUtils.nullIfEmpty

@Serializable
data class VillagerTradeData(val resultItem: String,
val priceItem1: String,
val priceItem2: String? = null,
val resultItemNBT: String? = null) {
val resultItemNBT: String? = null,
val priceItem1NBT: String? = null,
val priceItem2NBT: String? = null) {
@Transient
val nbt: NbtElement? = resultItemNBT?.let { NbtUtils.parseNbt(it) }
val resultNbt: NbtElement? = resultItemNBT?.let { NbtUtils.parseNbt(it).nullIfEmpty() }
@Transient
val price1Nbt: NbtElement? = priceItem1NBT?.let { NbtUtils.parseNbt(it).nullIfEmpty() }
@Transient
val price2Nbt: NbtElement? = priceItem2NBT?.let { NbtUtils.parseNbt(it).nullIfEmpty() }
}
Loading

0 comments on commit a186e5f

Please sign in to comment.