Jump to content

Recommended Posts

Posted

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.");
		}
	}
}

 

Posted (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 by V0idWa1k3r
Posted
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

Posted
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.

 

  1. 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.
  2. 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.
  3. 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));

 

  • Like 1
Posted
4 minutes ago, V0idWa1k3r said:
  1. 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.
  2. 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.
  3. 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

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

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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