From c3fc180e68b20dfeb24cb7adfcc7b3ff794ae71e Mon Sep 17 00:00:00 2001 From: jimchen5209 Date: Wed, 12 Jun 2024 14:24:53 +0800 Subject: [PATCH] refactor: change nbt naming style to snake to match minecraft style --- src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt | 6 +++--- src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt | 4 ++-- src/main/kotlin/one/oktw/galaxy/item/Tool.kt | 4 ++-- src/main/kotlin/one/oktw/galaxy/item/Weapon.kt | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt b/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt index bcc6c7cf8..a3e9e7d4c 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt @@ -52,11 +52,11 @@ abstract class CustomItem(override val identifier: Identifier, private val baseI abstract fun getName(): Text? open fun writeCustomNbt(nbt: NbtCompound) { - nbt.putString("CustomItemIdentifier", identifier.toString()) + nbt.putString("custom_item_identifier", identifier.toString()) } open fun readCustomNbt(nbt: NbtCompound): CustomItem { - require(nbt.getString("CustomItemIdentifier") == identifier.toString()) + require(nbt.getString("custom_item_identifier") == identifier.toString()) return this } @@ -75,7 +75,7 @@ abstract class CustomItem(override val identifier: Identifier, private val baseI writeCustomNbt(galaxyNbt) apply(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT) { component -> component.apply { nbt -> - nbt.put("GalaxyData", galaxyNbt) + nbt.put("galaxy_data", galaxyNbt) } } }.also { if (cacheable) cacheItemStack = it.copy() } diff --git a/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt b/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt index 0dad44e18..dea27c17e 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt @@ -27,13 +27,13 @@ import net.minecraft.util.Identifier object CustomItemHelper { fun getNbt(itemStack: ItemStack): NbtCompound { val galaxyData = (itemStack.get(DataComponentTypes.CUSTOM_DATA) ?: NbtComponent.DEFAULT).copyNbt() - return galaxyData.getCompound("GalaxyData") + return galaxyData.getCompound("galaxy_data") } fun getItem(itemStack: ItemStack): CustomItem? { val customNbt = getNbt(itemStack) - return customNbt.getString("CustomItemIdentifier")?.let(Identifier::tryParse) + return customNbt.getString("custom_item_identifier")?.let(Identifier::tryParse) ?.let(CustomItem.registry::get) ?.run { readCustomNbt(customNbt) } } diff --git a/src/main/kotlin/one/oktw/galaxy/item/Tool.kt b/src/main/kotlin/one/oktw/galaxy/item/Tool.kt index 6dba40fe0..b21c1627b 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Tool.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Tool.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2023 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -39,6 +39,6 @@ class Tool private constructor(id: String, modelData: Int, private val name: Str override fun writeCustomNbt(nbt: NbtCompound) { super.writeCustomNbt(nbt) - nbt.put("ToolData", NbtCompound().apply { putUuid("id", MathHelper.randomUuid()) }) + nbt.put("tool_data", NbtCompound().apply { putUuid("id", MathHelper.randomUuid()) }) } } diff --git a/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt b/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt index 7351ec435..580aa78bd 100644 --- a/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt +++ b/src/main/kotlin/one/oktw/galaxy/item/Weapon.kt @@ -1,6 +1,6 @@ /* * OKTW Galaxy Project - * Copyright (C) 2018-2022 + * Copyright (C) 2018-2024 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -61,6 +61,6 @@ class Weapon private constructor(id: String, modelData: Int, private val name: S override fun writeCustomNbt(nbt: NbtCompound) { super.writeCustomNbt(nbt) - nbt.put("WeaponData", NbtCompound().apply { putUuid("id", MathHelper.randomUuid()) }) + nbt.put("weapon_data", NbtCompound().apply { putUuid("id", MathHelper.randomUuid()) }) } }