Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved!] Problems with mod (Ore Generation, error at startup)


hbh7
 Share

Recommended Posts

Note: This is solved now, solutions "in a nutshell" follow the problem.

 

Hello, i'm having some problems with my mod, as you probably know from the title.

 

Problem 1:

When i create ores that i want to spawn in the overworld, only the first one that i made will generate. Currently i have 3 ores, but only 1 will generate in the world. I plan to make more, if, i can get more than 1 to spawn. The code for the 3 ores is pretty much the same, i'm not sure if the similarity is the problem, or something else, but i hope someone else knows how to fix this, because i'm clueless... I spend hours on the internet looking for a solution but haven't found one.

 

Code:

TopazOreWorldGeneration (This is the only one that generates an ore out of the 3 ores i have)

http://paste.minecraftforge.net/view/embed/07c5a1e1

 

YellowTopazOreWorldGeneration (All other ores look like this, so i only included this one.)

http://paste.minecraftforge.net/view/embed/5be712db

 

I'm not sure if this is helpful or not, but its in my main class that deals with the ore generation.

 

public static TopazOreWorldGeneration Genworld = new TopazOreWorldGeneration();

public static YellowTopazOreWorldGeneration Genworld1 = new YellowTopazOreWorldGeneration();

 

Solution: Instead of having one class that generates all the ores, i had a separate class for each ore i wanted to generate.

 

Problem 2:

Whenever i run my mod in eclipse and out of eclipse, i get a message in the console that says, "[WARNING] [ForgeModLoader] The mod FMLMod:hbhbtm{1.0} is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event. " I'm wondering what i can do to fix this. Here is the code for the blocks that i think is causing the message.

  GameRegistry.registerBlock(TopazOre, "TopazOre");

GameRegistry.registerBlock(YellowTopazOre, "YellowTopazOre");

 

I'm not sure what to change it to to fix this.

 

If you can help me, thanks in advance!

 

Solution: I needed to use PreInit, and Init to register the blocks at the proper time. More details are in replies below

Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Ok, some cleanup:

1) You don't need a new IWorldGenerator for each ore, you can generate all ores from one.

2) You need to register your IWorldGenerators (GameRegistry.registerWorldGenerator)

3) Don't construct your block directly, (Block foo = new BlockFoo()), construct them in PreInit.

Link to comment
Share on other sites

Ok, some cleanup:

1) You don't need a new IWorldGenerator for each ore, you can generate all ores from one.

2) You need to register your IWorldGenerators (GameRegistry.registerWorldGenerator)

3) Don't construct your block directly, (Block foo = new BlockFoo()), construct them in PreInit.

 

Ok thanks, i will try it out. For #1, how would you go about doing that? I am not sure what to change to do that.

 

Edit: Removing the gameregistry.registerworldgenerator causes no ores to generate at all. And the game crashes if i remove the Topazore = new BlockTopazOre... etc. I'm not sure if i know what you mean by all this...

Link to comment
Share on other sites

Ok thanks, i will try it out. For #1, how would you go about doing that? I am not sure what to change to do that.

In your IWorldGenerator you generate one ore. Just generate multiple ones... It's probably not even more than copying the stuff over from one IWorldGenerator to the other (which is not the nice way to do this, but I doubt you have the java knowledge to do it properly).
Edit: Removing the gameregistry.registerworldgenerator causes no ores to generate at all.
Where did I say you should do that?

I said you need to register them.

And the game crashes if i remove the Topazore = new BlockTopazOre... etc. I'm not sure if i know what you mean by all this...

Of course it does... I didn't say you should remove it. I said you should construct it later (=in PreInit). Do you know what constructing means?
Link to comment
Share on other sites

I'm fairly new at this, so I'm not 100% sure on what I'm doing... So that's why it seems like it... I'm pretty sure I know what you mean for #1. For #2, now that you pointed that out, i see you are right. I read that over many times and each time i thought you said you didn't have to, i see now that's not what you said, sorry about that. For #3, i thought you meant don't do that, as in remove it. My mistake, sorry about that. I have a fair idea on what it means, I'm just not too sure how to construct it in preint... I will look into it.

Link to comment
Share on other sites

any number of basic modding tutorials should be able to show you how to set this up. if i'm understanding the problem correctly. even the outdated tutorials. google is good, and so is youtube.

 

imports

@Mod
@NetworkMod

public class mainModClass
{
//===blocks/ores===
public static Block oreBlock;

//===Event Manager===
public static EventManager eventManager = new EventManager();

@PreInit
public void preInit(FMLPreInitializationEvent event)
{
oreBlock = new modBlock(oreBlockID, Material.rock).setUnlocalizedName("oreBlock");
}

@Init
public void load(FMLInitializationEvent event)
{
	//===Register World===
GameRegistry.registerWorldGenerator(eventManager);
}

}

Link to comment
Share on other sites

You'd be surprised how much i looked.... But for some reason, they still had the error when I tried them... When i try this, i get errors on preInit(void is an invalid type for the variable preInit), and load(void is an invalid type for the variable load). At the end of the public void load(FMLInitializationEvent event) and  public void preInit(FMLPreInitializationEvent event), it gives this error, (Syntax error on token ")", ; expected). This is similar to what i get on the other tutorials...

 

The game also crashes with these errors:(similar errors with other tutorials)

java.lang.Error: Unresolved compilation problems:

void is an invalid type for the variable preInit

syntax error on token "(", ; expected

Syntax error on token ")", ; expected

void is an invalid type for the variable load

syntax error on token "(", ; expected

Duplicate local variable event

Syntax error on token ")", ; expected

 

I honestly have no idea whats wrong with this... but that's what i get when i follow the tutorials. I originally thought it was because they were old, so i'm asking here. If anyone has any idea why i'm getting these problems, I would be very grateful for help.

Link to comment
Share on other sites

If you're in minecraft 1.6.*, replace the @Init and @PreInit with @EventHandler.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

:( Still doesn't work, even with that change. With that, errors on startup are:

java.lang.Error: Unresolved compilation problems:

EventManager cannot be resolved to a type

Illegal modifier for parameter eventManager; only final is permitted

EventManager cannot be resolved to a type

void is an invalid type for the variable preInit

Syntax error on token "(", ; expected

Syntax error on token ")", ; expected

void is an invalid type for the variable load

Syntax error on token "(", ; expected

Duplicate local variable event

Syntax error on token ")", ; expected

 

....No idea what i am doing wrong, i typed it like you guys showed, but it still gives these errors... Any idea what i'm doing wrong?

Link to comment
Share on other sites

This is what i have.

//--------------//

//Block Registry//

//--------------//

public static EventManager eventManager = new EventManager();

@EventHandler

public void preInit(FMLInitializationEvent event)

{

GameRegistry.registerBlock(TopazOre, "TopazOre");

GameRegistry.registerBlock(YellowTopazOre, "YellowTopazOre");

GameRegistry.registerBlock(EnigmaOre, "EnigmaOre");

GameRegistry.registerBlock(EnigmaBlock, "EnigmaBlock");

GameRegistry.registerBlock(TopazBlock, "TopazBlock");

GameRegistry.registerBlock(YellowTopazBlock, "YellowTopazBlock");

GameRegistry.registerBlock(JasperBlock, "JasperBlock");

GameRegistry.registerBlock(JadeBlock, "JadeBlock");

GameRegistry.registerBlock(RainbowBlock, "RainbowBlock");

GameRegistry.registerBlock(OnyxBlock, "OnyxBlock");

GameRegistry.registerBlock(PlatinumBlock, "PlatinumBlock");

GameRegistry.registerBlock(JasperOre, "JasperOre");

GameRegistry.registerBlock(JadeOre, "JadeOre");

GameRegistry.registerBlock(OnyxOre, "OnyxOre");

GameRegistry.registerBlock(PlatinumOre, "PlatinumOre");

GameRegistry.registerBlock(AuroraCrystalOre, "AuroraCrystalOre");

}

//-------------------------------//

//Registering The World Generator//

//-------------------------------//

@EventHandler

public void load(FMLInitializationEvent event)

{

GameRegistry.registerWorldGenerator(Genworld);

}

Link to comment
Share on other sites

Look at this line:

 

public void preInit(FMLInitializationEvent event)

 

 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

that bunch of errors makes me think of a wrongly placed { } or ; something along those lines.

if you show someone the whole class then it would be possible to detect the error.

 

edit: maybe larsgerrits spotted the error for you already  ;)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Ok, i fixed the typing like larsgerrits pointed out, it got rid of one of the errors. But the other ones remain. I would show the whole class, except for 2 things. 1. Its about 550 lines, a lot to go through... 2. Its only when i have that code in that it gives errors, if i comment out the preinit and init stuff, public static EventManager eventManager = new EventManager();

@EventHandler

public void preInit(FMLPreInitializationEvent event)

{

*code*

}

and

@EventHandler

public void load(FMLInitializationEvent event)

{

*code*

}

Then it works fine, which leads me to believe its not misplaced {}'s, and i have tried putting ;'s where eclipse tells me to, but it doesn't help. But if you/anyone really wants to look through all of it, here it is, http://paste.minecraftforge.net/view/0d008a02.

Link to comment
Share on other sites

"Did my explanations confuse you?" yes... a bit... " if you need clarifications, don't be afraid to ask me to do so!" ok, would you mind clarifying a bit? I do not really know what you mean by that. They aren't in any brackets({}) that i can see, unless you are referring to the 2 }'s at the end, which have been there as long as i can remember... I don't really know what the 1st one goes to, but I know the last one closes the "public class hbhbtm {" at the beginning...

 

I am moving things around now, I will post results in about 5-10 mins in an edit.

 

Edit: Moving PreInit and Init in between the last 2 brackets seemed to clear up most of the errors, except 1. In the line, "public static EventManager eventManager = new EventManager();".(Underlined words are underlined in eclipse) There are 2 errors. If moused over, they both have the message "EventManager cannot be resolved to a type". It doesn't give any options that i think are helpful...

Updated code: http://paste.minecraftforge.net/view/8e72d532

Link to comment
Share on other sites

No it doesn't and I'm sorry if it sounds rude but it sounds like you need a simple course in java basics? :)

 

The constructor cannot (not can any other method) contain method declerations.

That's the reason for the error, Eclipse thinks you are stating a variable named preInit since it knows you can't declear a method inside another method, therefore it expects a ";" and throws an error when it sees a "(" instead :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

I probably do... its been a while since I have had any sort of java tutorial, so I guess i forgot some things. Your explanation clears things up perfectly, that all makes sense (probably because I learned this at one point in time), I see what I have done wrong. But what I still ( :( ) don't understand is what to do with the EventManager underlining I described a few reply's ago.

Link to comment
Share on other sites

That's just the fact that it has no idea what and where EventManager is.

You need to import it from someplace, there's probably a quickfix to import it :)

 

I got something better than tutorials, I got a whole university course in java (Beginner level, no worries even tough it IS a proffesional university course it's made for non-programmers to get started with programming!)

It contains EVERYTHING the actual students recieved with regards to handouts and assignments.

All is video recorded and the proffessor is a fun guy :) They also give you their own eclipse version so you can do the first assignment in their special language thingy!

 

Does it sound interesting? I did know the java basics but I still found them worthwhile to watch.

 

If you guys dont get it.. then well ya.. try harder...

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

 Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.