Jump to content

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


Recommended Posts

Posted

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

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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

Posted

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.

Posted

Ok, so problem 1 is solved. Now i just need to figure out how to construct blocks in preInit... Can anyone help me with that? I cant seem to figure it out... :(

Posted

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

}

Posted

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.

Posted

:( 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?

Posted

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);

}

Posted

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

Posted

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.

Posted

Found it I think!

 

Took me a while but check you're constructor.

I think all the pre-init methods are inside the constructor's }!

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

Posted

"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

Posted

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

Posted

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.

Posted

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

Posted

My original thought was to import it, but it does not give a quickfix to.... Which led me to believe that was not it. I will google where the class is located to manually import it. Yeah that sounds awesome. What/where/when is that? All the teaching i have had is tutorials, youtube, a website dedicated to teaching java, and some examples. The rest I learned/taught myself. So something like that would be awesome. Can you send me a link? :D

Posted

It's no wonder eclispe can't find it, I can't either!

 

Using CTRL+SHIFT+T opens up the type search window ;)

There's no such class.

I guess it's meant to be self made or something? check the tutorial you got it from :)

 

 

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

Posted

Yeah that's kinda how I started with C++ a few years back, until I found some more structured courses!

 

Heres the link:

http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111

 

After finishing it you can find two others, the CS106B deals with Sorting Alogaritms and that's quite useful to learn! After that you could take a look into CS107 which is more advance and will give you some insight into how programming languages work and how they are converted into assembly etc.

 

I really do recommend watching CS106A before you mod any more, because after it you will probably be a lot faster at modding since you can solve most problems on you're own and in just a few minutes compared to being frustrated and blind searching for hours ;)

 

 

 

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

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.