Jump to content

How do I add my custom Registry to RegistryManager.ACTIVE? Is it possible?


Recommended Posts

Posted

Currently I'm storing Spells by creating a custom DeferredRegister as outlined by https://forge.gemwire.uk/wiki/Registration:

public static final ResourceKey<Registry<Spell>> SPELL = createRegistryKey("spell");
    private static <T> ResourceKey<Registry<T>> createRegistryKey(String p_259572_) {
        return ResourceKey.createRegistryKey(new ResourceLocation(MOD_ID, p_259572_));
    }

    public static final DeferredRegister<Spell> SPELL_REGISTRY = DeferredRegister.create(SPELL, MOD_ID);
    public static final RegistryBuilder builder = new RegistryBuilder<Spell>();
    public static final Supplier<IForgeRegistry<Spell>> SPELL_REGISTRY_SUPPLIER = SPELL_REGISTRY.makeRegistry(()->builder);

However, this doesn't add the Register to RegistryManager.ACTIVE.

 

I saw this post:

But new RegistryBuilder<>().create() no longer exists.

 

The reason I want to access my Registry through ACTIVE is because I could then use ResourceArgument for my debug command instead of creating a new ArgumentType, and because I want to be able to access my supplier by ResourceKey.

 

Any tips would be much appreciated, tysm.

 

Posted

Please don't post snippets in the forum. We need to see the full code to reproduce/understand your problem.

 

Guess mode enabled (I shouldn't have to guess):

You don't have something like:

SPELL_REGISTRY.register(FMLJavaModLoadingContext.get().getModEventBus())

somewhere in your mod constructor or a method called from it.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

My bad, here's the constructor. I already have SPELL_REGISTRY.register(bus), so I don't think that's the issue

package runecraft.core;

import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.logging.LogUtils;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.inventory.MenuType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
import net.minecraftforge.registries.RegistryManager;
import net.minecraftforge.server.command.ModIdArgument;
import org.slf4j.Logger;

import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.DeferredRegister;

import runecraft.api.AllMenuTypes;
import runecraft.common.commands.SpellArgumentType;
import runecraft.events.CommandEventHandler;
import runecraft.events.ModClientEvents;
import runecraft.events.RuneToolEventHandler;
import runecraft.events.SpellEventHandler;
import runecraft.client.screen.RuneForgeScreen;
import runecraft.common.spell.Spell;
import runecraft.init.*;

import java.util.function.Supplier;

@Mod(value = Runecraft.MOD_ID)
public class Runecraft {
    public static final String MOD_ID = "runecraft";
    public static final DeferredRegister<Block> BLOCK_REGISTER = DeferredRegister.create(Registries.BLOCK, MOD_ID);
    public static final DeferredRegister<Item> ITEM_REGISTER = DeferredRegister.create(Registries.ITEM, MOD_ID);
    public static final DeferredRegister<MenuType<?>> MENU_REGISTER = DeferredRegister.create(Registries.MENU, MOD_ID);
    public static final DeferredRegister<EntityType<?>> ENTITY_REGISTER = DeferredRegister.create(Registries.ENTITY_TYPE, MOD_ID);
    public static final DeferredRegister<ArgumentTypeInfo<?, ?>> ARGUMENT_TYPE_REGISTER = DeferredRegister.create(Registries.COMMAND_ARGUMENT_TYPE, MOD_ID);

    // RUNES REGISTRIES
    public static final ResourceKey<Registry<Spell>> SPELL = createRegistryKey("spell");
    private static <T> ResourceKey<Registry<T>> createRegistryKey(String p_259572_) {
        return ResourceKey.createRegistryKey(new ResourceLocation(MOD_ID, p_259572_));
    }

    public static final DeferredRegister<Spell> SPELL_REGISTRY = DeferredRegister.create(SPELL, MOD_ID);
    public static final RegistryBuilder builder = new RegistryBuilder<Spell>();
    public static final Supplier<IForgeRegistry<Spell>> SPELL_REGISTRY_SUPPLIER = SPELL_REGISTRY.makeRegistry(()->builder);
    public static final SpellRecipeRegistry SPELL_RECIPE_REGISTRY = new SpellRecipeRegistry();


    public static final Logger LOGGER = LogUtils.getLogger();

    public static Runecraft instance;

    public Runecraft() {
        instance = this;
        IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();

        MinecraftForge.EVENT_BUS.register(new SpellEventHandler());
        MinecraftForge.EVENT_BUS.register(new RuneToolEventHandler());


        bus.addListener(this::commonSetup);
        bus.addListener(this::clientSetup);

        BLOCK_REGISTER.register(bus);
        ITEM_REGISTER.register(bus);
        MENU_REGISTER.register(bus);
        SPELL_REGISTRY.register(bus);
        ENTITY_REGISTER.register(bus);
        ARGUMENT_TYPE_REGISTER.register(bus);

        //TODO Move to AllArgumentTypes Class
        ARGUMENT_TYPE_REGISTER.register("spell",
                ()-> ArgumentTypeInfos.registerByClass(SpellArgumentType.class,
                        SingletonArgumentInfo.contextFree(SpellArgumentType::spellArg)));

        ModBlocks.setup();
        ModItems.setup();
        ModMenus.setup();
        ModSpells.setup();
        ModEntityTypes.setup();

    }

    private void commonSetup(final FMLCommonSetupEvent event) {
        event.enqueueWork(ModPacketHandler::setup);
    }

    private void clientSetup(FMLClientSetupEvent event) {
        event.enqueueWork(
                // Assume RegistryObject<MenuType<MyMenu>> MY_MENU
                // Assume MyContainerScreen<MyMenu> which takes in three parameters
                () -> MenuScreens.register(AllMenuTypes.RUNE_FORGE.get(), RuneForgeScreen::new)
        );
    }







}
Posted
Quote

Please don't post snippets in the forum. We need to see the full code to reproduce/understand your problem.

The "full code" means put the minimum amount of code on github so we can reproduce your problem.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.