From 721447d2f765afd139a52599289b2b334b10548f Mon Sep 17 00:00:00 2001 From: D1p4k <82884007+D1p4k@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:12:25 +0200 Subject: [PATCH] Make registries good :) --- .../spell/execution/executor/SpellExecutorType.java | 4 +++- .../dev/enjarai/trickster/spell/fragment/FragmentType.java | 6 ++++-- .../java/dev/enjarai/trickster/spell/mana/ManaPoolType.java | 4 +++- src/main/java/dev/enjarai/trickster/spell/trick/Tricks.java | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/enjarai/trickster/spell/execution/executor/SpellExecutorType.java b/src/main/java/dev/enjarai/trickster/spell/execution/executor/SpellExecutorType.java index b57f217a..f01fcd2d 100644 --- a/src/main/java/dev/enjarai/trickster/spell/execution/executor/SpellExecutorType.java +++ b/src/main/java/dev/enjarai/trickster/spell/execution/executor/SpellExecutorType.java @@ -4,13 +4,15 @@ import com.mojang.serialization.MapCodec; import dev.enjarai.trickster.Trickster; import io.wispforest.endec.StructEndec; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.SimpleRegistry; public record SpellExecutorType(StructEndec endec) { public static final RegistryKey>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("spell_executor_type")); - public static final Registry> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()); + public static final Registry> REGISTRY = FabricRegistryBuilder.createSimple(REGISTRY_KEY).attribute(RegistryAttribute.SYNCED).buildAndRegister(); public static final SpellExecutorType DEFAULT = register("default", DefaultSpellExecutor.ENDEC); public static final SpellExecutorType FOLDING = register("folding", FoldingSpellExecutor.ENDEC); diff --git a/src/main/java/dev/enjarai/trickster/spell/fragment/FragmentType.java b/src/main/java/dev/enjarai/trickster/spell/fragment/FragmentType.java index fa72170f..0457603f 100644 --- a/src/main/java/dev/enjarai/trickster/spell/fragment/FragmentType.java +++ b/src/main/java/dev/enjarai/trickster/spell/fragment/FragmentType.java @@ -9,6 +9,8 @@ import io.wispforest.endec.StructEndec; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.SimpleRegistry; @@ -23,7 +25,7 @@ public record FragmentType(StructEndec endec, OptionalInt color) { public static final RegistryKey>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("fragment_type")); public static final Int2ObjectMap INT_ID_LOOKUP = new Int2ObjectOpenHashMap<>(); - public static final Registry> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) { + public static final Registry> REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) { @Override public RegistryEntry.Reference> add(RegistryKey> key, FragmentType value, RegistryEntryInfo info) { var hash = key.getValue().hashCode(); @@ -37,7 +39,7 @@ public RegistryEntry.Reference> add(RegistryKey> INT_ID_LOOKUP.put(hash, key.getValue()); return super.add(key, value, info); } - }; + }).attribute(RegistryAttribute.SYNCED).buildAndRegister();; public static final FragmentType TYPE = register("type", TypeFragment.ENDEC, 0x66cc00); public static final FragmentType NUMBER = register("number", NumberFragment.ENDEC, 0xddaa00); diff --git a/src/main/java/dev/enjarai/trickster/spell/mana/ManaPoolType.java b/src/main/java/dev/enjarai/trickster/spell/mana/ManaPoolType.java index 30be91e9..f9747261 100644 --- a/src/main/java/dev/enjarai/trickster/spell/mana/ManaPoolType.java +++ b/src/main/java/dev/enjarai/trickster/spell/mana/ManaPoolType.java @@ -3,13 +3,15 @@ import com.mojang.serialization.Lifecycle; import dev.enjarai.trickster.Trickster; import io.wispforest.endec.StructEndec; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.SimpleRegistry; public record ManaPoolType(StructEndec endec) { public static final RegistryKey>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("mana_pool_type")); - public static final Registry> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()); + public static final Registry> REGISTRY = FabricRegistryBuilder.createSimple(REGISTRY_KEY).attribute(RegistryAttribute.SYNCED).buildAndRegister(); public static final ManaPoolType SIMPLE = register("simple", SimpleManaPool.ENDEC); diff --git a/src/main/java/dev/enjarai/trickster/spell/trick/Tricks.java b/src/main/java/dev/enjarai/trickster/spell/trick/Tricks.java index 4861de4e..2302a7d0 100644 --- a/src/main/java/dev/enjarai/trickster/spell/trick/Tricks.java +++ b/src/main/java/dev/enjarai/trickster/spell/trick/Tricks.java @@ -25,6 +25,8 @@ import dev.enjarai.trickster.spell.trick.raycast.RaycastEntityTrick; import dev.enjarai.trickster.spell.trick.tree.*; import dev.enjarai.trickster.spell.trick.vector.*; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.SimpleRegistry; @@ -40,7 +42,7 @@ public class Tricks { private static final Map LOOKUP = new HashMap<>(); public static final RegistryKey> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("trick")); - public static final Registry REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) { + public static final Registry REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) { @Override public RegistryEntry.Reference add(RegistryKey key, Trick value, RegistryEntryInfo info) { if (LOOKUP.containsKey(value.getPattern())) { @@ -53,7 +55,7 @@ public RegistryEntry.Reference add(RegistryKey key, Trick value, R LOOKUP.put(value.getPattern(), value); return super.add(key, value, info); } - }; + }).attribute(RegistryAttribute.SYNCED).buildAndRegister(); // Functions public static final ExecuteTrick EXECUTE = register("execute", new ExecuteTrick());