HarryTechReviews Posted February 17, 2019 Share Posted February 17, 2019 No idea why but I have a ResourceLocationException when registering my item. Any help is appreciated Stacktrace [18:51:09.439] [Client thread/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Caught exception during event RegistryEvent.Register<minecraft:items> dispatch for modid tutorialmod java.lang.ExceptionInInitializerError: null at harry.tutorialmod.TutorialMod$RegistryEvents.registerItems(TutorialMod.java:46) ~[main/:?] at net.minecraftforge.eventbus.ASMEventHandler_1_RegistryEvents_registerItems_Register.invoke(.dynamic) ~[?:?] at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:79) ~[eventbus-0.6.0-service.jar:?] at net.minecraftforge.eventbus.EventBus.post(EventBus.java:249) ~[eventbus-0.6.0-service.jar:?] at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:105) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:25.0] at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_201] at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_201] at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:100) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.fml.ModList.lambda$dispatchSynchronousEvent$4(ModList.java:111) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at java.util.ArrayList.forEach(ArrayList.java:1257) ~[?:1.8.0_201] at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:111) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.fml.ModList.lambda$static$0(ModList.java:82) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:72) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:146) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:814) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:134) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:52) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraft.client.Minecraft.init(Minecraft.java:411) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraft.client.Minecraft.run(Minecraft.java:344) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraft.client.main.Main.main(SourceFile:144) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201] at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:19) [modlauncher-0.9.4.jar:?] at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:35) [modlauncher-0.9.4.jar:?] at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-0.9.4.jar:?] at cpw.mods.modlauncher.Launcher.run(Launcher.java:58) [modlauncher-0.9.4.jar:?] at cpw.mods.modlauncher.Launcher.main(Launcher.java:44) [modlauncher-0.9.4.jar:?] at net.minecraftforge.userdev.UserdevLauncher.main(UserdevLauncher.java:77) [forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] Caused by: net.minecraft.util.ResourceLocationException: Non [a-z0-9/._-] character in path of location: tutorialmod:tutorialItem at net.minecraft.util.ResourceLocation.<init>(SourceFile:38) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraft.util.ResourceLocation.<init>(SourceFile:47) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.registries.GameData.checkPrefix(GameData.java:833) ~[forge-1.13.2-25.0.13_mapped_snapshot_20180921-1.13.jar:?] at net.minecraftforge.registries.ForgeRegistryEntry.setRegistryName(ForgeRegistryEntry.java:45) ~[?:?] at net.minecraftforge.registries.ForgeRegistryEntry.setRegistryName(ForgeRegistryEntry.java:52) ~[?:?] at harry.tutorialmod.items.ItemBase.<init>(ItemBase.java:13) ~[?:?] at harry.tutorialmod.init.ItemInit.<clinit>(ItemInit.java:14) ~[?:?] ... 31 more ItemBase public class ItemBase extends Item { public ItemBase(String name) { super(new Item.Properties()); setRegistryName(new ResourceLocation(ModConfig.MODID, name)); ItemInit.ITEMS.add(this); } } ItemInit public class ItemInit { public static final List<Item> ITEMS = new ArrayList<Item>(); public static final Item tutorialItem = new ItemBase("tutorialItem"); } Main Class @Mod(ModConfig.MODID) public class TutorialMod { private static final Logger LOGGER = LogManager.getLogger(ModConfig.MODID); public TutorialMod() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { LOGGER.info("Setup method registered. (This is what used to be preInit)"); } private void clientRegistries(final FMLClientSetupEvent event) { LOGGER.info("Client registries registered. This is for all things that are client side only."); } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().registerAll((Item[]) ItemInit.ITEMS.toArray()); LOGGER.info("Items registered."); } @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { LOGGER.info("Blocks registered."); } } } Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted February 17, 2019 Share Posted February 17, 2019 (edited) 18 minutes ago, HarryTechReviews said: ItemBase Dont use ItemBase, there is already an ItemBase, it's called Item. 18 minutes ago, HarryTechReviews said: public static final Item tutorialItem = new ItemBase("tutorialItem"); Don't use static initializers, ever. Instantinate your stuff directly in the appropriate registry event. As for the error itself - read it. It tells you what's wrong right there, in the exception message. 18 minutes ago, HarryTechReviews said: Caused by: net.minecraft.util.ResourceLocationException: Non [a-z0-9/._-] character in path of location: tutorialmod:tutorialItem All registry names must be lowercase. They may include numbers from 0 to 9 and characters like ., _ and -. Nothing else is allowed and you have a capital I in there. Edited February 17, 2019 by V0idWa1k3r Quote Link to comment Share on other sites More sharing options...
HarryTechReviews Posted February 17, 2019 Author Share Posted February 17, 2019 9 minutes ago, V0idWa1k3r said: Dont use ItemBase, there is already an ItemBase, it's called Item. Don't use static initializers, ever. Instantinate your stuff directly in the appropriate registry event. As for the error itself - read it. It tells you what's wrong right there, in the exception message. All registry names must be lowercase. They may include numbers from 0 to 9 and characters like ., _ and -. Nothing else is allowed and you have a capital I in there. Thanks for your help with the error. What's wrong with ItemBase? It's just a class that I can use to make all of my items do something, rather than having to individually do it for every item. Thanks for the help with the static stuff though, I'll change that now Quote Link to comment Share on other sites More sharing options...
V0idWa1k3r Posted February 17, 2019 Share Posted February 17, 2019 6 minutes ago, HarryTechReviews said: What's wrong with ItemBase? It's just a class that I can use to make all of my items do something, rather than having to individually do it for every item. It prevents you from overriding other classes. Say you want to create a custom elytra - well, you have to override ItemElytraWings(or whatever it's called) since minecraft uses a lot of instanceof checks. With your ItemBase though you can't. And now you have to duplicate your code for no good reason. It is not needed. You are just creating extra classes for no good reason. Why do you need it? Everything is now passed to the constructor via the corresponding Properties object and setRegistryName already returns you your object so you can chain it. It serves no purpose apart from enforcing cargo-cult programming. In general you shouldn't abuse inheritance just to write less code, that's not what inheritance is for. If you really need it create a helper method: public static <T extends IForgeRegistryEntry<T>> T setCommonParameters(T object, String registryName) { return object.setRegistryName(new ResourceLocation(TestMod.MODID, registryName)); } // In your registry handler event.getRegistry().register(setCommonParameters(new Item(new Item.Properties()), "test_item")); But even this is not needed since you can just do event.getRegistry().register(new Item(new Item.Properties().group(GroupsRef.GROUP_TEST_MOD)).setRegistryName(NAME_VOID_INGOT)); 1 Quote Link to comment Share on other sites More sharing options...
HarryTechReviews Posted February 17, 2019 Author Share Posted February 17, 2019 4 minutes ago, V0idWa1k3r said: It prevents you from overriding other classes. Say you want to create a custom elytra - well, you have to override ItemElytraWings(or whatever it's called) since minecraft uses a lot of instanceof checks. With your ItemBase though you can't. And now you have to duplicate your code for no good reason. It is not needed. You are just creating extra classes for no good reason. Why do you need it? Everything is now passed to the constructor via the corresponding Properties object and setRegistryName already returns you your object so you can chain it. It serves no purpose apart from enforcing cargo-cult programming. In general you shouldn't abuse inheritance just to write less code, that's not what inheritance is for. If you really need it create a helper method: public static <T extends IForgeRegistryEntry<T>> T setCommonParameters(T object, String registryName) { return object.setRegistryName(new ResourceLocation(TestMod.MODID, registryName)); } // In your registry handler event.getRegistry().register(setCommonParameters(new Item(new Item.Properties()), "test_item")); But even this is not needed since you can just do event.getRegistry().register(new Item(new Item.Properties().group(GroupsRef.GROUP_TEST_MOD)).setRegistryName(NAME_VOID_INGOT)); Thanks for the clarification Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.