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/PotatoRegistry.kt | |
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/PotatoRegistry.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt | 37 |
1 files changed, 37 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 |