Jump to content

Recommended Posts

Posted

I have been working on making a config file for my mod(doing just ID's at the moment). When I go to load the the game it just says slot 0 is already taken... when trying to add...

 

Theses are my declarations.

 
public static int denseCoalOreID;
public static int titaniumOreID;

 

These are the initializers

int denseCoalOre = config.getBlock(Configuration.CATEGORY_BLOCK, "Dense Coal Ore", 500).getInt();
int titaniumOreID = config.getBlock(Configuration.CATEGORY_BLOCK, "Titanium Ore ID", 501).getInt();

 

Them being used in the assigning the ID

Block denseCoalOre = new denseCoalOre(denseCoalID, Material.rock); //the rest of the attribute are in its class.
Block titanium = new titanium(titaniumOreID, Material.rock);//same with this one.

 

This is there error

java.lang.IllegalArgumentException: Slot 0 is already occupied by bigbaddevil7.supernova.blocks.denseCoalOre@302ff81c when adding bigbaddevil7.supernova.blocks.titanium@1d4a0efb

 

 

 

Also Since I'm only learning I knew this exact thing was going to happen, but my main class became massive. What would be the best way to setup the main class, or what is the more common method of organizing the class.

 

This my main class. Even I know its not pretty site which is why I'm asking for suggestions. I've looked at open source mods on the site but I understand it better when someone explains it.

Here is a pastebin as well http://pastebin.com/w67VexAC

 

  Reveal hidden contents

 

 

Posted
  On 2/25/2014 at 2:30 AM, bigbaddevil6 said:

Theses are my declarations.

 
public static int denseCoalOreID;
public static int titaniumOreID;

 

These are the initializers

int denseCoalOre = config.getBlock(Configuration.CATEGORY_BLOCK, "Dense Coal Ore", 500).getInt();
int titaniumOreID = config.getBlock(Configuration.CATEGORY_BLOCK, "Titanium Ore ID", 501).getInt();

 

Them being used in the assigning the ID

Block denseCoalOre = new denseCoalOre(denseCoalID, Material.rock); //the rest of the attribute are in its class.
Block titanium = new titanium(titaniumOreID, Material.rock);//same with this one.

 

You misspelled your denseCoreOreID in 2 different places. You got no compile errors because you redeclared the IDs as local variables. Newly declared variable of type int always get a value of 0. And the int value of Block is also 0.

 

You are declaring an entirely new variable every you put a type before a variable name at the beginning of an instruction:

int denseCoalID;
static int denseCoalOre;
int denseCoalOreID = blahBlahBlah;

All of the above represent completely separate and unassociated variables.

 

Posted

damn my fingers always getting in my way... Ok besides my poor typing skills. When ever I go to just make the preInit int titaniumOreID = config.getBlock(Configuration.CATEGORY_BLOCK, "Titanium Ore ID", 501).getInt(); it wont allow me to pass the information to the load Block titanium = new titanium(titaniumOreID, Material.rock); it wont pass even though I see it done in the tutorial. Says it cannot be resolved to variable.

Posted

It's not just the misspellings that have you stymied. You are not referring to the ID you have set up previously to hold the ID:

config.load();
        int titaniumOreID = config.getBlock(Configuration.CATEGORY_BLOCK, "Titanium Ore ID", 501).getInt();

Here you are assigning the ID to a completely separate variable. Not the class variable you set up here:

public static CreativeTabs tabSupernova = new CreativeTabs("supernova")
    {
        @SideOnly(Side.CLIENT)
        public int getTabIconItemIndex()
        {
            return SuperNova.oxidizerIdle.blockID;
        }
    };
    
    public static int titaniumOreID;

 

The first variable above is a method local variable. It is not visible and doesn't even exist outside the Preinit method. The second variable above is a class variable. It exists forever. It was never used or initialized in your code. Two separate variable with the same name, but different scopes. It might help you to learn java programming before delving too deeply into modding.

Posted

I understand the difference between a local and global variable. Which is why I'm getting so confused. I can send you a old part of this code that works fine and have everything defined but but lets say I went back to the way this use to be and got rid of all the dupes that I've put in trying to understand the confusion here. The tutorial i am following calls for the

int titaniumOreID = config.getBlock(Configuration.CATEGORY_BLOCK, "Titanium Ore ID", 501).getInt();

 

as is, it doesn't have the

public static int titaniumOreID;

above the class, which how all mine were defined. Old Code http://pastebin.com/X8csMtLj

 

But the confusion came when preInit class defines all the int titaniumOreID = config.getBlock and then passes it to the load class in the tutorial. Isn't that defined variable local to the preInit and won't be seen by the load class. Yet I'm looking at the tutorial do it and when I go to do it gives me the exact syntax error I would expect to get.

Posted

I'd use config.get instead of config.getBlock. It has the same parameters and you can just add it to the category CATEGORY_BLOCK in it. And I'd use your

 

public static int titaniumOreID;

 

because then it's static and can be used by other classes and methods.

 

Oh and don't add

 

int

 

before "titaniumOreID" when you define it. That should work and have no syntax errors then.

 

Hope that helped!

 

 

-Mitchellbrine

 

  Quote

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

  Quote
I don't want your charity, I want your information
Posted

Is this what you had in mind?

 

 

  Reveal hidden contents

 

 

It works except for anything that called for a blockID for example my postInit it gives me a null pointer along with anything else that calls for it. Is there something special I have to do for that? I would have thought that the .blockID would have been set to what I gave it in the constructor of the block class. Or is it something else?

Posted

Something is still null. Is there any more information in the crash?

-Mitchellbrine

 

  Quote

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

  Quote
I don't want your charity, I want your information
Posted

Yes, that style is workable for your purposes.

 

However, you are again declaring local Blocks in your Initialization method. Stop doing that! Do not start the instruction with a type declarator (like "Block ..."). That only creates a new and separate variable that no other method has access to.

 

 

  Reveal hidden contents

 

 

However, be aware that most of the time, the scope of the IDs you get from a config file should last as long as the mod container. That is why the IDs are usually declared in the class (outside any method). If you need to refer to the IDs from another of your classes, you cannot do it easily with the method you've chosen.

 

My suggestion, is learn to use class fields. Do not redeclare local variables with the same names. That is very confusing. But, if you must do it, use "this.variable" for the class field and just "variable" for the local variable (most often a parameter).

 

Example:

@Mod( ... )
public class Modone {
    private static final String CATEGORY_BLOCK = "block";
    int myOreBlockID;
    Block myOreBlock;

    @SubscribeEvent
    public static void Preinit(FMLPreinitializationEvent ev) {
        Configuration config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
        myOreBlockID = config.get(CATEGORY_BLOCK, "Titanium Ore ID", 501).getInt();
        myOreBlock = new MyOre(myOreBlockID,Material.rock);
        .
        :
        config.save();
        GameRegistry.registerBlock(myOreBlock, .... yadda yadda yadda );
    }

 

Notice how the IDs and Blocks are uninitialized fields of the class. I did not use a 'type ID' before any of the setting instructions, so the instructions referred to the fields already declared. That is what I am attempting to teach you.

 

Posted

I'd recommend Configuration.getBlock as it searchs for a free block id.

Also, it is unecessary to make the id as fields, since you already have the blocks themselves, and they keep the info through block.blockID. Same goes for items.

Posted

Ok... new day different outlook hopefully. So firstly the method I shown was how I was shown to set it up and it worked so I never questioned it. I have setup the file how you suggested now.

 

Here is the section I redid.

 

  Reveal hidden contents

 

 

Did I do it properly? If so then how do the other classes get a hold of the information? The tutorial shown doing the public static Block below the post init, but isn't that the same thing I did just in a different spot. Do you have a good reference where I can learn of the class fields? As far as I'm aware of I've heard people mention it in tutorials but never explained it in detail.

 

Posted

Pretty good, except for CFP and CT, again you specified an initializing declaration (NOT AN ASSIGNMENT). You want to only do assignment if you want your data to persist as long as the mod does.

 

And, you still need to register all of your blocks, items, handlers, etc.

 

I'll leave that as an exercise for you.

 

As to your question about visibility, you chose to specify that your fields are only visible to the package it is in. To do otherwise you must include a visibility modifier before the type specifier. Public or Private 0are the ones you want to look at. There is also Protected (which is like private, except subclasses can see them, too.)

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.