使い方と制約
ResourceKeyは種類・レジストリID・正規化コンポーネントを含みます。量はResourceStackに置きます。同じIDでもコンポーネントが違えば別資源です。
ResourceKey
package dev.nebulastorage.api.resource
private val namespacedId = Regex("[a-z0-9_.-]+:[a-z0-9/._-]+")
data class ResourceTypeId(val value: String) {
init { require(namespacedId.matches(value)) { "Invalid resource type: $value" } }
companion object {
@JvmField val ITEM = ResourceTypeId("nexus_storage:item")
@JvmField val FLUID = ResourceTypeId("nexus_storage:fluid")
@JvmField val ENERGY = ResourceTypeId("nexus_storage:energy")
}
}
/**
* [components] is a canonical, immutable identity supplied by the resource codec.
* Empty components identify an unconfigured resource; display names are never identity.
*/
data class ResourceKey @JvmOverloads constructor(val type: ResourceTypeId, val id: String, val components: String = "") {
init { require(namespacedId.matches(id)) { "Invalid resource identifier: $id" } }
}
/** [amount] counts strictly positive integral units of [key]'s type, never display-scaled values. */
data class ResourceStack(val key: ResourceKey, val amount: Long) {
init { require(amount > 0) { "Resource amount must be positive" } }
}
ソース
src/main/kotlin/dev/nebulastorage/api/resource/ResourceKey.kt; editorial/ja.json
43b4d12d69e6033c24fa8c39dac383ef2429b446