Jump to content

Help with adding a new item


SusiKette

Recommended Posts

I'm done writing the code to add a new item which as far as I'm concerned should be correct, but I'm still getting errors in few class files. The errors as far as I know are for things that are included with forge, so I'm not sure how to fix them.

 

1. The preInit from the following code is underlined and gives this message: "The method preInit(FMLPreInitializationEvent) is undefined for the type CommonProxy". The same error is in the init and postInit variants as well. There are no errors in the CommonProxy class file either, but I can add it if it's needed.

	@EventHandler
	public static void preInit(FMLPreInitializationEvent event) {
		proxy.preInit(event);
	}

 

2. The getRegistry() gives the following error "The method getRegistry() is undefined for the type RegistryEvent<Item>".

	@SubscribeEvent
	public static void onItemRegister(RegistryEvent<Item> event) {
		event.getRegistry().registerAll(ItemInit.ITEMS.toArray(new Item[0]));
	}

 

3. The getRegistryName() gives the following error "The method getReristryName() is undefined for the type ClientProxy".

	@Override
	public void registerItemRenderer(Item item, int meta, String id) {
		ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item, getReristryName(), id));
	}

 

I'm not sure how common there kinds of errors are, so I'm not sure how much information is needed. Let me know if you need more information on something.

Link to comment
Share on other sites

46 minutes ago, SusiKette said:

1. The preInit from the following code is underlined and gives this message: "The method preInit(FMLPreInitializationEvent) is undefined for the type CommonProxy". The same error is in the init and postInit variants as well. There are no errors in the CommonProxy class file either, but I can add it if it's needed.

You have copied code from someone else. Your CommonProxy class does not contain a preInit(FMLPreInitalizationEvent event) function, yet you are trying to call it. Of course there is no error in the CommonProxy class, this function doesn't exist and there's no reason that your CommonProxy thinks it should.  This is the same reasing calling Math.CalculatePie() throws an error. There is also no reason this method should exist either: anything you might do in your common proxy you can do in your main mod class. See Code Style Problem #2.

46 minutes ago, SusiKette said:

3. The getRegistryName() gives the following error "The method getReristryName() is undefined for the type ClientProxy".

item.getRegistryName(), you somehow inserted a comma instead of a period, because that function takes 2 parameters.

Additionally, you should only be calling this code during the ModelRegistrationEvent.

Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

You have copied code from someone else. Your CommonProxy class does not contain a preInit(FMLPreInitalizationEvent event) function, yet you are trying to call it. Of course there is no error in the CommonProxy class, this function doesn't exist and there's no reason that your CommonProxy thinks it should.  This is the same reasing calling Math.CalculatePie() throws an error. There is also no reason this method should exist either: anything you might do in your common proxy you can do in your main mod class. See Code Style Problem #2.

item.getRegistryName(), you somehow inserted a comma instead of a period, because that function takes 2 parameters.

Additionally, you should only be calling this code during the ModelRegistrationEvent.

I was following a tutorial, so I did things the same way they did. They did edit the video, so I'm not sure if they accidentally edited out the part where they added preInit etc. to CommonProxy. Do I really need those functions in CommonProxy anyways? If not, I'm assuming I can just delete the "proxy.preInit(event);" lines.

 

Also, I'm getting different error after changing the comma to period in item.getRegistryName(). It's on the same place but this time it says "The method getReristryName() is undefined for the type Item"

Link to comment
Share on other sites

1 hour ago, SusiKette said:

The method getReristryName() is undefined for the type Item"

You have a typo.

 

1 hour ago, SusiKette said:

Do I really need those functions in CommonProxy anyways? If not, I'm assuming I can just delete the "proxy.preInit(event);" lines.

2 hours ago, Draco18s said:

There is also no reason this method should exist either: anything you might do in your common proxy you can do in your main mod class. See Code Style Problem #2.

 

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thanks for the help so far :)

Assuming I understood what was in the link (I'm not a native English speaker, so I might derp sometimes :p), the lines I mentioned are not needed.

The only error that still remains it the second one in the original post.

 

And as a last kinda unrelated note, I kinda wish Eclipse had some sort of spell check to avoid these kinds of errors from happening ^^;;

Edited by SusiKette
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



×
×
  • Create New...

Important Information

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