Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Commit f3b23a8

Browse files
committed
feat: add option to use Bukkit's item comparison
1 parent 63b86da commit f3b23a8

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ dependencies {
2424

2525
compileOnly(kotlin("stdlib")) // loaded through library loader
2626
compileOnly(kotlin("reflect")) // loaded through library loader
27-
compileOnlyAndTestImpl("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
27+
compileOnlyAndTestImpl("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
2828
compileOnlyAndTestImpl("com.github.slimefun:Slimefun4:experimental-SNAPSHOT")
2929
compileOnly("net.guizhanss:SlimefunTranslation:e6da231617")
3030
compileOnly("com.github.schntgaispock:SlimeHUD:1.3.0")
3131
compileOnly("com.github.SlimefunGuguProject:InfinityExpansion:bebf0bd0f9")
3232
compileOnly("com.github.VoperAD:SlimeFrame:8af2379a01")
3333
compileOnly("net.guizhanss:InfinityExpansion2:8d3e6c40f6")
3434
implementation("org.bstats:bstats-bukkit:3.1.0")
35-
implementation("net.guizhanss:guizhanlib-all:2.4.0-SNAPSHOT")
35+
implementation("net.guizhanss:guizhanlib-all:2.5.0")
3636
implementation("net.guizhanss:guizhanlib-kt-all:0.2.0")
3737

3838
testImplementation(kotlin("test"))
@@ -95,14 +95,14 @@ bukkit {
9595
tasks.runServer {
9696
downloadPlugins {
9797
// Slimefun
98-
url("https://blob.build/dl/Slimefun4/Dev/latest")
98+
url("https://builds.guizhanss.com/api/download/SlimefunGuguProject/Slimefun4/master/latest")
9999
// SlimeHUD
100100
url("https://blob.build/dl/SlimeHUD/Dev/latest")
101101
// GuizhanCraft for testing convenient
102102
url("https://builds.guizhanss.com/api/download/ybw0014/GuizhanCraft/master/latest")
103103
}
104104
jvmArgs("-Dcom.mojang.eula.agree=true")
105-
minecraftVersion("1.20.6")
105+
minecraftVersion("1.21.11")
106106
}
107107

108108
tasks.test {

src/main/kotlin/net/guizhanss/fastmachines/core/services/ConfigService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ConfigService(plugin: FastMachines) {
1515
lateinit var fmTickRate: ConfigField<Int>
1616
lateinit var fmUseEnergy: ConfigField<Boolean>
1717
lateinit var fmRequireSfResearch: ConfigField<Boolean>
18+
lateinit var fmUseBukkitItemComparison: ConfigField<Boolean>
1819

1920
private val config = addonConfig(plugin, "config.yml") {
2021
autoUpdate = boolean("auto-update", true)
@@ -24,6 +25,7 @@ class ConfigService(plugin: FastMachines) {
2425
fmTickRate = int("fast-machines.tick-rate", 10, 5, 600)
2526
fmUseEnergy = boolean("fast-machines.use-energy", true)
2627
fmRequireSfResearch = boolean("fast-machines.require-sf-research", false)
28+
fmUseBukkitItemComparison = boolean("fast-machines.use-bukkit-items", false)
2729
}
2830

2931
init {

src/main/kotlin/net/guizhanss/fastmachines/utils/items/ItemExt.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package net.guizhanss.fastmachines.utils.items
44

55
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun
6+
import net.guizhanss.fastmachines.FastMachines
67
import net.guizhanss.fastmachines.core.items.ItemWrapper
78
import net.guizhanss.guizhanlib.minecraft.utils.MinecraftVersionUtil
89
import org.bukkit.inventory.ItemStack
@@ -32,11 +33,16 @@ fun ItemWrapper?.isSimilarTo(other: ItemStack?, checkLore: Boolean = false): Boo
3233
// null check
3334
if (this == null || other == null) return false
3435

36+
// bukkit item comparison
37+
if (FastMachines.configService.fmUseBukkitItemComparison.value) {
38+
return baseItem.isSimilar(other)
39+
}
40+
3541
// type check
3642
if (baseItem.type != other.type) return false
3743
if (baseItem.type.isAir || other.type.isAir) return false
3844

39-
// meta check
45+
// has meta check
4046
if (baseItemMeta == null || !other.hasItemMeta()) {
4147
return (baseItemMeta != null) == other.hasItemMeta()
4248
}
@@ -146,7 +152,7 @@ private fun ItemMeta.quickNotEquals(other: ItemMeta): Boolean {
146152
}
147153

148154
if (this is PotionMeta && other is PotionMeta) {
149-
if (MinecraftVersionUtil.isAtLeast(20, 5)) {
155+
if (MinecraftVersionUtil.isAtLeast(1, 20, 5)) {
150156
if (this.basePotionType != other.basePotionType) return true
151157
} else {
152158
if (this.basePotionData != other.basePotionData) return true

src/main/resources/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ fast-machines:
2424
# Whether crafting a Slimefun item needs it to be unlocked first.
2525
require-sf-research: false
2626

27+
# Whether to use ItemStack's own isSimilar to compare items.
28+
use-bukkit-item-comparison: false
29+
2730
# Print debug messages.
2831
debug: false

src/test/kotlin/net/guizhanss/fastmachines/core/items/ItemWrapperTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.junit.jupiter.api.BeforeEach
77
import org.mockbukkit.mockbukkit.MockBukkit
88
import kotlin.test.Test
99
import kotlin.test.assertEquals
10-
import kotlin.test.assertTrue
1110

1211
class ItemWrapperTest {
1312

@@ -33,11 +32,11 @@ class ItemWrapperTest {
3332
val wrapper1 = ItemWrapper.of(ItemStack(Material.DIAMOND, 32))
3433
val wrapper2 = ItemWrapper.of(ItemStack(Material.DIAMOND, 32))
3534

36-
assertTrue(wrapper1 == wrapper2)
35+
assertEquals(wrapper1, wrapper2)
3736

3837
val wrapper3 = ItemWrapper.of(ItemStack(Material.GOLD_INGOT, 32))
3938
val wrapper4 = ItemWrapper.of(ItemStack(Material.GOLD_INGOT, 16))
4039

41-
assertTrue(wrapper3 == wrapper4)
40+
assertEquals(wrapper3, wrapper4)
4241
}
4342
}

0 commit comments

Comments
 (0)