diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-01 17:48:53 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-01 17:48:53 +0200 |
commit | 0fe5e487922a6ff50b9c415b9384157fbd64b2b5 (patch) | |
tree | e62cb4b9abea80d144d95a7bd2e0114088944587 /src/main/kotlin/moe/nea/potatocrime/registry | |
download | potato-crimes-0fe5e487922a6ff50b9c415b9384157fbd64b2b5.tar.gz potato-crimes-0fe5e487922a6ff50b9c415b9384157fbd64b2b5.tar.bz2 potato-crimes-0fe5e487922a6ff50b9c415b9384157fbd64b2b5.zip |
Initial commit
Diffstat (limited to 'src/main/kotlin/moe/nea/potatocrime/registry')
-rw-r--r-- | src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt | 37 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt | 24 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt new file mode 100644 index 0000000..2e5fa5f --- /dev/null +++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt @@ -0,0 +1,37 @@ +package moe.nea.potatocrime.registry + +import com.mojang.serialization.Codec +import moe.nea.potatocrime.PotatoCrime +import moe.nea.potatocrime.item.ContrabandItem +import net.minecraft.component.DataComponentType +import net.minecraft.item.Item +import net.minecraft.network.codec.PacketCodecs +import net.minecraft.registry.Registries +import net.minecraft.registry.Registry +import net.minecraft.util.Identifier + +object PotatoRegistry { + private val delayedRegistries = mutableListOf<() -> Unit>() + fun registerAll() { + delayedRegistries.forEach { it.invoke() } + } + + private fun <U, T : U> register(registry: Registry<U>, name: String, t: T): T { + delayedRegistries.add { + Registry.register(registry, Identifier(PotatoCrime.modId, name), t) + } + return t + } + + private fun <T : Item> item(name: String, t: T): T = register(Registries.ITEM, name, t) + private fun <T> dataComponent(name: String, block: (DataComponentType.Builder<T>) -> DataComponentType.Builder<T>) = + register( + Registries.DATA_COMPONENT_TYPE, name, + block(DataComponentType.builder()).build() + ) + + val contraband = item("contraband", ContrabandItem()) + val contrabandData = dataComponent("contraband_data") { + it.codec(Codec.INT).packetCodec(PacketCodecs.VAR_INT) + } +}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt new file mode 100644 index 0000000..062c88d --- /dev/null +++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt @@ -0,0 +1,24 @@ +package moe.nea.potatocrime.registry + +import net.minecraft.text.MutableText +import net.minecraft.text.Text + +object PotatoTranslations { + val allTranslations = mutableListOf<PT>() + + data class PT(val name: String, val default: String) { + fun format(vararg params: String): MutableText { + return Text.translatable(translationKey, *params) + } + + val translationKey = "potato-crime.text.$name" + + init { + allTranslations.add(this) + } + } + + val noCarrotsToDeposit = PT("no-carrots", "No carrots to deposit.") + val contrabandFillText = PT("fill-level", "Hidden carrots: %s/1000.") + +}
\ No newline at end of file |