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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Turning the Tables: My Journey to Reclaim Stolen Bitcoins with Expert Help. When my Bitcoin wallet was hacked and my entire cryptocurrency portfolio was stolen, I felt utterly devastated and hopeless. Having worked hard to build up my digital assets, the sudden loss was gut-wrenching. It felt like my financial future had been ripped away in an instant, leaving me overwhelmed by a sense of betrayal and despair. In my search for help, I discovered TECH CYBER FORCE Recovery, a renowned cybersecurity firm specializing in cryptocurrency recovery. I was met with professionalism and empathy from my first contact with them. The team demonstrated a steadfast commitment to helping me retrieve my stolen Bitcoins. They understood the emotional toll of my situation and approached my case with genuine concern. TECH CYBER FORCE Recovery swung into action immediately, leveraging its extensive expertise in blockchain forensics and hacker tracking techniques. Their process was meticulous. They analyzed my transaction history, followed the digital trail left by the hackers, and worked diligently to pinpoint the location of the stolen funds. I was impressed by their technical prowess; they employed advanced cryptographic methods and strategic negotiations with the perpetrators, all while keeping me informed about their progress. The recovery process was complex and fraught with challenges. However, the tenacity displayed by the team was truly awe-inspiring. They navigated cryptocurrency crime's murky and ever-evolving landscape with skill and determination. After a series of strategic moves, they managed to recover the majority of my Bitcoins successfully.  
    • I removed giacomos_hud, oculus, (dont know what you mean with iris), enhanced_boss_bars, epicfight and essential.  Server still doesnt want to boot. new logs after removing: https://pastebin.com/LuM2PFtN I dont quite understand the "server side" and "client side" difference..
    • There are client side only mods in your server files   Remove giacomos_hud, oculus, iris, enhanced_boss_bars and epicfight You can keep these mods in your client Maybe also remove essentials
    • Here is my Log with java 17: https://pastebin.com/RPdWSjwq
    • Been working on creating a server for this mod, but i keep getting this error over and over again.  I have tried updating/changing the Forge launcher, Removing/replacing the ops.json and whitelist.json folders, and removing certain mods. Crash report log: https://pastebin.com/Bu046cVq Debug.log https://pastebin.com/7hKm40ke Latest.log https://pastebin.com/nCRLUH3b any help would be great thanks!
  • Topics

×
×
  • Create New...

Important Information

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