Skip to content

Commit

Permalink
Make registries good :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev0Louis committed Sep 9, 2024
1 parent 8a7bee3 commit 721447d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends SpellExecutor>(StructEndec<T> endec) {
public static final RegistryKey<Registry<SpellExecutorType<?>>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("spell_executor_type"));
public static final Registry<SpellExecutorType<?>> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable());
public static final Registry<SpellExecutorType<?>> REGISTRY = FabricRegistryBuilder.createSimple(REGISTRY_KEY).attribute(RegistryAttribute.SYNCED).buildAndRegister();

public static final SpellExecutorType<DefaultSpellExecutor> DEFAULT = register("default", DefaultSpellExecutor.ENDEC);
public static final SpellExecutorType<FoldingSpellExecutor> FOLDING = register("folding", FoldingSpellExecutor.ENDEC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +25,7 @@
public record FragmentType<T extends Fragment>(StructEndec<T> endec, OptionalInt color) {
public static final RegistryKey<Registry<FragmentType<?>>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("fragment_type"));
public static final Int2ObjectMap<Identifier> INT_ID_LOOKUP = new Int2ObjectOpenHashMap<>();
public static final Registry<FragmentType<?>> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) {
public static final Registry<FragmentType<?>> REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) {
@Override
public RegistryEntry.Reference<FragmentType<?>> add(RegistryKey<FragmentType<?>> key, FragmentType<?> value, RegistryEntryInfo info) {
var hash = key.getValue().hashCode();
Expand All @@ -37,7 +39,7 @@ public RegistryEntry.Reference<FragmentType<?>> add(RegistryKey<FragmentType<?>>
INT_ID_LOOKUP.put(hash, key.getValue());
return super.add(key, value, info);
}
};
}).attribute(RegistryAttribute.SYNCED).buildAndRegister();;

public static final FragmentType<TypeFragment> TYPE = register("type", TypeFragment.ENDEC, 0x66cc00);
public static final FragmentType<NumberFragment> NUMBER = register("number", NumberFragment.ENDEC, 0xddaa00);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends ManaPool>(StructEndec<T> endec) {
public static final RegistryKey<Registry<ManaPoolType<?>>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("mana_pool_type"));
public static final Registry<ManaPoolType<?>> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable());
public static final Registry<ManaPoolType<?>> REGISTRY = FabricRegistryBuilder.createSimple(REGISTRY_KEY).attribute(RegistryAttribute.SYNCED).buildAndRegister();

public static final ManaPoolType<SimpleManaPool> SIMPLE = register("simple", SimpleManaPool.ENDEC);

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dev/enjarai/trickster/spell/trick/Tricks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +42,7 @@ public class Tricks {
private static final Map<Pattern, Trick> LOOKUP = new HashMap<>();

public static final RegistryKey<Registry<Trick>> REGISTRY_KEY = RegistryKey.ofRegistry(Trickster.id("trick"));
public static final Registry<Trick> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) {
public static final Registry<Trick> REGISTRY = FabricRegistryBuilder.from(new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.stable()) {
@Override
public RegistryEntry.Reference<Trick> add(RegistryKey<Trick> key, Trick value, RegistryEntryInfo info) {
if (LOOKUP.containsKey(value.getPattern())) {
Expand All @@ -53,7 +55,7 @@ public RegistryEntry.Reference<Trick> add(RegistryKey<Trick> 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());
Expand Down

0 comments on commit 721447d

Please sign in to comment.