|
| 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 | +} |
0 commit comments