Jump to content

Problem with Replacing Vanilla Blocks


monkeysHK

Recommended Posts

Hello. I have been trying to register my own class NBTNoteBlock to the block registry with key note_block in "minecraft" but I got an error. I don't know what was wrong. It would be appreciated if someone could provide a fix. Code is provided below.

 

Error I got was:

[16:41:11] [Render thread/ERROR] [minecraft/Util]: No data fixer registered for note_block
[16:41:11] [Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Can not register to a locked registry. Modder should use Forge Register methods.

 

First few lines in the main mod file:

// The value here should match an entry in the META-INF/mods.toml file
@Mod("nbaddons")
public class nbaddons {
    // Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "nbaddons";

    public nbaddons() {
        Registration.register(); // <-- Registers stuff, see Registration.java

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }
  ...

 

First few lines in Registration.java

@Mod.EventBusSubscriber(modid = nbaddons.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class Registration {

    public static final DeferredRegister<Block> VANILLA_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");

    public static void register() {
        VANILLA_BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        NBTNoteBlock.register(); // <-- The block class itself. See NBTNoteBlock.java
    ...

 

First few lines in NBTNoteBlock.java

public class NBTNoteBlock extends NoteBlock {

    //public static Block NOTEBLOCK;
    public static final RegistryObject<Block> NOTEBLOCK = Registration.VANILLA_BLOCKS.register(
            "note_block", () -> new NBTNoteBlock(AbstractBlock.Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(0.8F)));

    public NBTNoteBlock(Properties properties) {
        super(properties);
    }

    public static void register() {}; // <-- register() is called just to initialize the constant NOTEBLOCK, as mentioned in the tutorial I watched.

 

Link to comment
Share on other sites

 Still getting the same error.

 

New Registration.java

    public static final DeferredRegister<Block> VANILLA_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");
    public static final RegistryObject<Block> NOTEBLOCK = Registration.VANILLA_BLOCKS.register(
            "note_block", () -> new NBTNoteBlock(AbstractBlock.Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(0.8F)));


    public static void register() {
        VANILLA_BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

 

Full Stacktrace:

[20:48:27] [Render thread/ERROR] [minecraft/Util]: No data fixer registered for note_block
[20:48:27] [Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Can not register to a locked registry. Modder should use Forge Register methods.
	Index: 2
	Listeners:
		0: NORMAL
		1: ASM: net.minecraftforge.registries.DeferredRegister$EventDispatcher@260f306 handleEvent(Lnet/minecraftforge/event/RegistryEvent$Register;)V
		2: ASM: net.minecraftforge.registries.DeferredRegister$EventDispatcher@70ea9d57 handleEvent(Lnet/minecraftforge/event/RegistryEvent$Register;)V
java.lang.IllegalStateException: Can not register to a locked registry. Modder should use Forge Register methods.
	at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:56)
	at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:72)
	at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:40)
	at net.minecraft.util.registry.Registry.register(Registry.java:474)
	at net.minecraft.util.registry.Registry.register(Registry.java:470)
	at com.mhk.nbaddons.blocks.NoteBlockTileEntity.register(NoteBlockTileEntity.java:53)
	at com.mhk.nbaddons.setup.Registration.lambda$static$1(Registration.java:30)
	at net.minecraftforge.registries.DeferredRegister.lambda$register$0(DeferredRegister.java:124)
	at net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:200)
	at net.minecraftforge.registries.DeferredRegister.access$000(DeferredRegister.java:61)
	at net.minecraftforge.registries.DeferredRegister$EventDispatcher.handleEvent(DeferredRegister.java:172)
	at net.minecraftforge.eventbus.ASMEventHandler_1_EventDispatcher_handleEvent_Register.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297)
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120)
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:121)
	at java.util.concurrent.CompletableFuture$AsyncRun.run$$$capture(CompletableFuture.java:1640)
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java)
	at net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:56)
	at net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:40)
	at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243)
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:230)
	at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:196)
	at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$1(ClientModLoader.java:103)
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:123)
	at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:103)
	at net.minecraft.client.Minecraft.<init>(Minecraft.java:442)
	at net.minecraft.client.main.Main.main(Main.java:149)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105)

 

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

You have not shown this class.

Oops... I omitted the class because I thought I would not need it for the discussion. Here is the full Registration.java.

    public static final DeferredRegister<Block> VANILLA_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");
    public static RegistryObject<Block> NOTEBLOCK = VANILLA_BLOCKS.register(
            "note_block", () -> new NBTNoteBlock(AbstractBlock.Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(0.8F)));
    
    public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, nbaddons.MOD_ID);
    public static RegistryObject<TileEntityType<?>> NOTEBLOCK_TE = Registration.TILE_ENTITIES.register(
            "note_block", () -> NoteBlockTileEntity.register("note_block", TileEntityType.Builder.create(NoteBlockTileEntity::new, Blocks.NOTE_BLOCK)));
    
    public static void register() {
            VANILLA_BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
            TILE_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

NoteBlockTileEntity.java:53 (I copied some lines from TileEntityType::register)

    public static  <T extends TileEntity> TileEntityType<T> register(String key, TileEntityType.Builder<T> builder) {
        Type<?> type = Util.attemptDataFix(TypeReferences.BLOCK_ENTITY, key);
        return Registry.register(Registry.BLOCK_ENTITY_TYPE, key, builder.build(type));
    }

 

Edited by monkeysHK
Link to comment
Share on other sites

Oh yes that was exactly the problem. Spent a little more time on documentation and figured it out. Thank you so much!

 

Code that works.

@Mod.EventBusSubscriber(modid = nbaddons.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class Registration {
    public static final DeferredRegister<Block> VANILLA_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, "minecraft");
    public static RegistryObject<Block> NOTEBLOCK = VANILLA_BLOCKS.register(
            "note_block", () -> new NBTNoteBlock(AbstractBlock.Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(0.8F)));

    public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, nbaddons.MOD_ID);
    public static RegistryObject<TileEntityType<NoteBlockTileEntity>> NOTEBLOCK_TE = TILE_ENTITIES.register(
            "note_block", () -> TileEntityType.Builder.create(NoteBlockTileEntity::new, Blocks.NOTE_BLOCK).build(null));

    public static void register() {
        VANILLA_BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        TILE_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }
}
Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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