Posted January 13, 20214 yr 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.
January 13, 20214 yr Author 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)
January 13, 20214 yr Author 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 January 13, 20214 yr by monkeysHK
January 13, 20214 yr Author 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()); } }
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.