Jump to content

[Easy question] Execute function post-world generation?


foul_owl

Recommended Posts

Hi folks,

 

I'm just starting off modding, so I have an easy question for you all. I would like to set a block at arbitrary coordinates (say 0,80,0) to an arbitrary value. (say, block of emerald, or id 133)

 

I've been following the tutorials here:

http://www.minecraftforge.net/wiki/Basic_Modding

 

But I'm not seeing any information on how to set a block post-world generation. I've also taken a look at the Ruins mod source code, and discovered the setBlock function there.

 

I'm 99% sure that setBlock shouldn't go in preInit, load, or postInit, because I'm assuming those functions are just relating to loading the mod. We need to call setBlock after the world has already been generated.

 

I basically just need to know how and when to call setBlock, and how to reference the current world in setBlock.

 

Thanks folks!!  :)

Link to comment
Share on other sites

You can do setBlock whenever you have access to the world object, and some position you want to place it.

If you don't want it during world gen, then the better question is when do you want it? :)

 

Also all Entities have a worldObj field for the world they are currently in, this includes the player.

So you have access to a reference to a world most of the time :)

When a player uses an item for example, you know the player, so you know the world hes in.

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

Link to comment
Share on other sites

Sorry, I realized I should have been more specific. :)

 

I basically want to set a block as the last stage of world generation. Ie, after the world has generated, but before anything else has happened.

 

I'm just not sure what function to define and use in my Generic class ( ie, from http://www.minecraftforge.net/wiki/Basic_Modding )

 

Thanks!

Link to comment
Share on other sites

You could use the terrain gen events and do it in the last step of the generation?

I dunno what it would be tbh, but hey have you actually tested just using the world generator?

It does happen after the caves and shit. Alternatively I guess you could perhaps use the BiomeDectorator? :P

 

Why does it need to be last?

For most cases the world generation method which is used for custom structures by many mods should suffice:)

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

Link to comment
Share on other sites

I wanted it to be last as I wanted to ensure that my block wasn't overwritten with another block.

 

I'll google biome decorator and see what I can find there.

 

My issue is that the Forge tutorials are currently not extensive enough to allow me to see how to proceed. However, I did just find this:

 

http://wuppy29.blogspot.nl/2012/08/modding-ore-generation.html

 

So I will look that over and see if I can use that.

 

An example here would be awesome, it might actually make for a good tutorial to go along with the rest of the Forge tutorials, ie, "Here's how you set a single block".

 

Thanks!

Link to comment
Share on other sites

Ok cool. I thinking something like "First vanilla minecraft decides where to place all blocks, once that step is done, then I can determine what blocks to change". That is what I meant by "post-world generation" :P

 

IIRC there's like four steps:

 

1) Terrain

2) Features (ravines, caves)

3) Decoration (trees, flowers)

4) Structures (villages, mineshafts)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

That makes sense.

 

I would like to perform a setBlock() as soon as step 4 finishes, but before anything else is done.

 

How would I do this? If I could see a code snippet, it would be much appreciated, particularly as I am brand new to this.

 

As another option, I would be down to execute a setBlock() when a key is pressed, ie, the "j" key. (Hardcoded for now, but of course I understand that is bad practice haha)

 

Thanks!

Link to comment
Share on other sites

You can't wait for step 4 to finish, technically.  At best you can do your stuff IN step 4.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yes...but that's a lot of work for a single setblock

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It wouldn't be possible to execute a setBlock from a keypress?

 

First learn how to do something on a keypress, there's a tutorial for that over at the minecraft forums.

Also learn how to work with packets, since Input is client side, while setting a block must be done on the server side (it can be done on both sides, but it MUST be done on the server in order to affect the world as the server is the boss of everything ;) )

 

Then you can do on key pressed -> packet to server -> packet handled on server side -> do the setBlock.

 

 

For your original question, I doubt it's possible to guarantee that it happens last during the world gen.

But if you do it during the 4th stage it would be small chances of it getting overwritten by something else.

 

Is this a block which only needs to be generated once during the very start of the game, near spawn for example?

 

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.

Announcements



×
×
  • Create New...

Important Information

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