Jump to content

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


hbh7

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

 

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

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
    • When I came across the 'Exit Code: I got a 1 error in my Minecraft mods, so I decided to figure out what was wrong. First, I took a look at the logs. In the mods folder (usually where you'd find logs or crash reports), I found the latest.log file or the corresponding crash report. I read it through carefully, looking for any lines with errors or warnings. Then I checked the Minecraft Forge support site, where you can often find info on what causes errors and how to fix them. I then disabled half of my mods and tried running the game. If the error disappeared, it meant that the problem was with the disabled mod. I repeated this several times to find the problem mod.
  • Topics

×
×
  • Create New...

Important Information

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