Skip to content

Commit

Permalink
refactor: change nbt naming style to snake
Browse files Browse the repository at this point in the history
to match minecraft style
  • Loading branch information
jimchen5209 committed Jun 12, 2024
1 parent f22e725 commit c3fc180
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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() }
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/item/CustomItemHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/item/Tool.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()) })
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/one/oktw/galaxy/item/Weapon.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()) })
}
}

0 comments on commit c3fc180

Please sign in to comment.