Skip to content

Commit 777524c

Browse files
committed
integrated item registry tests
1 parent 55c74b6 commit 777524c

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Minosoft
3+
* Copyright (C) 2020-2025 Moritz Zwerger
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8+
*
9+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
10+
*
11+
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
12+
*/
13+
14+
package de.bixilon.minosoft.data.registries.items
15+
16+
import de.bixilon.kutil.cast.CastUtil.unsafeCast
17+
import de.bixilon.kutil.exception.Broken
18+
import de.bixilon.kutil.json.JsonObject
19+
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfile
20+
import de.bixilon.minosoft.data.registries.item.items.DurableItem
21+
import de.bixilon.minosoft.data.registries.item.items.Item
22+
import de.bixilon.minosoft.data.registries.item.items.pixlyzer.PixLyzerItem
23+
import de.bixilon.minosoft.data.registries.registries.PixLyzerUtil
24+
import de.bixilon.minosoft.data.registries.registries.Registries
25+
import de.bixilon.minosoft.protocol.versions.Version
26+
import de.bixilon.minosoft.util.KUtil.toResourceLocation
27+
import de.bixilon.minosoft.util.logging.Log
28+
29+
object VerifyIntegratedItemRegistry {
30+
31+
private fun compareDurability(pixlyzer: PixLyzerItem, integrated: Item, errors: StringBuilder) {
32+
if (pixlyzer.maxDurability > 0 != integrated is DurableItem) {
33+
errors.append("Durability ability: ${pixlyzer.identifier}")
34+
return
35+
}
36+
if (pixlyzer.maxDurability == 0) return
37+
integrated as DurableItem
38+
if (pixlyzer.maxDurability != integrated.maxDurability) {
39+
errors.append("Durability mismatch: ${pixlyzer.identifier}. e=${pixlyzer.maxDurability}, a=${integrated.maxDurability}")
40+
}
41+
}
42+
43+
44+
private fun compare(pixlyzer: PixLyzerItem, integrated: Item, errors: StringBuilder) {
45+
compareDurability(pixlyzer, integrated, errors)
46+
}
47+
48+
fun verify(registries: Registries, version: Version) {
49+
val error = StringBuilder()
50+
val data = PixLyzerUtil.loadPixlyzerData(ResourcesProfile(), version)["items"]!!.unsafeCast<Map<String, JsonObject>>()
51+
52+
for ((id, value) in data) {
53+
if (value["class"] == "AirBlock") {
54+
continue
55+
}
56+
val identifier = id.toResourceLocation()
57+
val integrated = registries.item[identifier] ?: Broken("Item $id does not exist in the registry?")
58+
if (integrated is PixLyzerItem) {
59+
// useless to compare
60+
continue
61+
}
62+
val parsed = PixLyzerItem.deserialize(registries, identifier, value).unsafeCast<PixLyzerItem>()
63+
64+
parsed.postInit(registries)
65+
parsed.inject(registries)
66+
67+
68+
compare(parsed, integrated, error)
69+
}
70+
71+
72+
if (error.isEmpty()) {
73+
return
74+
}
75+
error.removePrefix("\n")
76+
Log.ERROR_PRINT_STREAM.println(error)
77+
throw AssertionError("Does not match, see above!")
78+
}
79+
}

src/integration-test/kotlin/de/bixilon/minosoft/data/registries/versions/registries/pixlyzer/PixLyzerLoadingTest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Minosoft
3-
* Copyright (C) 2020-2023 Moritz Zwerger
3+
* Copyright (C) 2020-2025 Moritz Zwerger
44
*
55
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
66
*
@@ -14,6 +14,7 @@
1414
package de.bixilon.minosoft.data.registries.versions.registries.pixlyzer
1515

1616
import de.bixilon.minosoft.data.registries.blocks.factory.VerifyIntegratedBlockRegistry
17+
import de.bixilon.minosoft.data.registries.items.VerifyIntegratedItemRegistry
1718
import de.bixilon.minosoft.data.registries.versions.registries.RegistryLoadingTest
1819
import de.bixilon.minosoft.test.ITUtil
1920
import org.testng.annotations.Test
@@ -26,7 +27,11 @@ abstract class PixLyzerLoadingTest(version: String) : RegistryLoadingTest(versio
2627
this._registries = ITUtil.loadPixlyzerData(version)
2728
}
2829

29-
fun testBlockIntegrated() {
30+
fun `blocks integrated`() {
3031
VerifyIntegratedBlockRegistry.verify(registries, version)
3132
}
33+
34+
fun `items integrated`() {
35+
VerifyIntegratedItemRegistry.verify(registries, version)
36+
}
3237
}

src/main/java/de/bixilon/minosoft/data/container/stack/properties/DurabilityProperty.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ data class DurabilityProperty(
4141
private const val DAMAGE_TAG = "Damage"
4242

4343
fun of(item: Item, nbt: MutableJsonObject): DurabilityProperty {
44+
assert(item is DurableItem && item.maxDurability > 0)
4445
item as DurableItem
4546

4647
val durability = nbt.remove(DAMAGE_TAG)?.toInt()?.let { item.maxDurability - it } ?: item.maxDurability

src/main/java/de/bixilon/minosoft/data/registries/item/items/armor/materials/NetheriteArmor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ abstract class NetheriteArmor(resourceLocation: ResourceLocation) : ArmorItem(re
6464

6565
open class NetheriteHelmet(resourceLocation: ResourceLocation = this.identifier) : NetheriteArmor(resourceLocation), HelmetItem {
6666
override val defense: Int get() = 3
67-
override val maxDurability get() = 275
67+
override val maxDurability get() = 407
6868

6969
companion object : ItemFactory<NetheriteHelmet> {
7070
override val identifier = minecraft("netherite_helmet")

src/main/java/de/bixilon/minosoft/data/registries/item/items/pixlyzer/PixLyzerItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Minosoft
3-
* Copyright (C) 2020-2023 Moritz Zwerger
3+
* Copyright (C) 2020-2025 Moritz Zwerger
44
*
55
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
66
*
@@ -32,7 +32,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
3232
open class PixLyzerItem(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>) : Item(resourceLocation), DurableItem, StackableItem, TintedBlock {
3333
override val rarity: Rarities = data["rarity"]?.toInt()?.let { Rarities[it] } ?: Rarities.COMMON
3434
override val maxStackSize: Int = data["max_stack_size"]?.toInt() ?: 64
35-
override val maxDurability: Int = data["max_damage"]?.toInt() ?: 1
35+
override val maxDurability: Int = data["max_damage"]?.toInt() ?: 0
3636
val isFireResistant: Boolean = data["is_fire_resistant"]?.toBoolean() ?: false
3737
override val translationKey: ResourceLocation = data["translation_key"]?.toResourceLocation() ?: super.translationKey
3838
override var tintProvider: TintProvider? = null

0 commit comments

Comments
 (0)