Jump to content

Changing language files on runtime


Black

Recommended Posts

Good Evening,

 

I am currently working on a mod that adds a tree that grows spawn eggs for each mob with spawneggs in the game at runtime.

Why? Well, just to learn java as I come from C++ and vb.net and to have some fun.

 

However the following problem presented itself to me and I seem, at least up to this point, incapable of solving it.

As I simply check the EntityList.entityEggs HashMap and change the colour and

statistics of the BaseTree based on the Itemdamage, I do not know all the names before compile time.

Or to be frank, I cannot know them, as it generates a tree for any mob of any mod that is added.

 

With the change to 1.7.2/1.7.10 you can name objects by means of language files.

And unfortunately I have never worked with those before so I don't know how to change them in runtime.

I searched quite vehemently but either I am as blind as a blind goat, or I didn't find anything worthwhile.

 

The only current possibility I see is writing to the file by means of a FileWriter

and hoping I can get the minecraft source code to reload the names after I adjusted them.

If necessary by overwriting one or two classes.

But, I am reluctant to do so and am wondering if Mojang or forge implemented a method

I overlooked to do so without the need of a feature that would normally be used for saving.

 

Most likely the solution is quite obvious and should that indeed be the case my apologies for the trouble.

 

Greetings,

Black

 

P.S.: I suggest adding the word 'Mojang' to the spell list as it currently suggests I change it to the word 'Mekong'.

Link to comment
Share on other sites

I don't understand from your description why you'd want to change the lang files. It sounds like you just want to read them, and are worried that there are multiple mods that may have additional entities?

 

All entities, including from multiple mods are in the registry.  So you can read back all the names from there (either unlocalized, which would include info on which mod it came from, or localized which would have the human-location-friendly names).

 

Or maybe you can explain why you feel you need to change anything in lang files to do this.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I don't understand from your description why you'd want to change the lang files. It sounds like you just want to read them, and are worried that there are multiple mods that may have additional entities?

 

You're understanding me incorrectly, I'm basically creating new blocks on runtime by means of itemdamage, or mob id if you prefer.

Basically I take one mob from the EntityEggs HashMap, take the spawnegg colour for that mob and apply it to the block together with the mobid.

That way I can have a block for every mob that is added.

 

All entities, including from multiple mods are in the registry.  So you can read back all the names from there (either unlocalized, which would include info on which mod it came from, or localized which would have the human-location-friendly names).

 

That might be true but that still doesn't answer my question. I need to be able to name my own blocks, which I do not know the name of yet before compile time because they are made on basis of those mods/mobs that are added. And the way I understand lang files is that you have to add the names beforehand which I cannot use since I need to add them once the game is running.

 

Let me tell you a simple example: Mod A adds a mob called 'Golem'. In turn, my mod creates a woodlog for that mob, with the colours of its spawn egg. And should name it Golemwood Log. In the old code I could do that simply by running

 

LanguageRegistry.addName(new ItemStack(BaseLog, 1, Egg.spawnedID), EntityName + "wood Log");

 

with EntityName being the name gotten from the entity.

 

But I am quite unclear as how to do this with the language files.

Link to comment
Share on other sites

Okay, the best way to solve this is to associate the entity to the block when created using the entity's lang files.  This would avoid creating a block lang file.

 

So you could @Override the getLocalizedName() in your block that return the block name with field that captures the entity name when you create the block.

 

Does that make sense as an approach for your needs?  Basically read all the entities in the registry and create block instances for each for a block class that has field you set to localized name of the entity, and your custom block code overrides the method to return that name.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.



×
×
  • Create New...

Important Information

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