Jump to content

Limited World Generation Mod


Thunderbird21

Recommended Posts

Hello all. I want to create a mod that stops the world from generating chunks after a certain number of chunks from spawn have been generated. In other words, I want to be able to create a map that is around 1000 by 1000 blocks in x and z coordinates. Since the world is generated in chunks, this will be approximately 60x60 chunks. I am using Forge 1.7.10 and have everything loaded into an Eclipse project. What I want to know is: in what class should I look to limit world generation. In what class does it specify that when the player is x blocks from the edge of the world, generate new chunks. Thanks.

Link to comment
Share on other sites

I dont know if there is any absolute way of doing what you want, but one possibility is simply to limit where the player can go

 

every server tick enum through the players and clamp there location to (-500 to 500) x and z

 

if you want the world to be a block with edges that can be fallen off , you could try using one of the populator events to clear the chunk ,

maybe a custom terrain generator (as i havnt done one yet, i cant help with that)

 

Link to comment
Share on other sites

Yea there are a number of mods that keep the player within a boundary with "invisible walls" such as worldborder, but I do want to do as you stated and have a world where players could fall off the edge and possible even build out up to 100 blocks away from the edge. I would also want a 1 block thick stone barrier around the entire thing so players can't easily gather ores, but I may just end up doing that in world edit. I haven't looked into populator events but I'll probably research it a bit. I've also started exploring the net.minecraft.world.chunk package and in the IChunkProvider interface there are calls to provide a chunk at a given value and load a chunk at a given value. If I can constrain the values going into those calls with an if statement, I may be able to stop generation outside those constrained values.

Link to comment
Share on other sites

Now would be a good time to mention that I switched over to MCP for now because Minecrat Forge makes it annoyingly hard to edit base classes and I'm not too concerned about compatibility with other mods anyway. I've been looking into the net.minecraft.world.chunk package more and under the Chunk class there's a method called populate chunk that populates a chunk if the chunk it checks is empty. If I constrain the values it checks, it may prevent chunk population beyond those values. I'll report back once I figure it out.

Link to comment
Share on other sites

So here's the code to cut off world generation after a certain number of chunks past spawn. Just as a reminder, this is under the net.minecraft.chunk package under the Chunk class. This is a rewrite of the populateChunk method:

 

public void populateChunk(IChunkProvider interface1, IChunkProvider interface2, int posX, int posY)
    {
    	//Get the spawn coordinate
    	ChunkCoordinates spawn = worldObj.getSpawnPoint();
    	
    	//These are the number of chunks to generate on each side of spawn chunk (if each is set to 0 you will get a world consisting of just the spawn chunk)
    	//Each world will have an odd number of chunks because it consists of the spawn chunk plus 2*worldChunksVariable
    	int worldXChunks = 1; //(*2+1)
    	int worldZChunks = 1; //(*2+1)
    	
    	//this if statement says if the coordinate of the x chunk its checking is within the bounds of the spawn chunk +/- worldXChunks
    	//and if the z chunk is also within its bounds, continue with world generation
    	if(posX <= (spawn.posX/16)+worldXChunks && posX >= (spawn.posX/16)-worldXChunks && posY <= (spawn.posZ/16)+worldZChunks && posY >= (spawn.posZ/16)-worldZChunks) {
    		
    		//Normal chunk generation
    		if (!this.isTerrainPopulated && interface1.chunkExists(posX + 1, posY + 1) && interface1.chunkExists(posX, posY + 1) && interface1.chunkExists(posX + 1, posY))
            {
                interface1.populate(interface2, posX, posY);
            }

            if (interface1.chunkExists(posX - 1, posY) && !interface1.provideChunk(posX - 1, posY).isTerrainPopulated && interface1.chunkExists(posX - 1, posY + 1) && interface1.chunkExists(posX, posY + 1) && interface1.chunkExists(posX - 1, posY + 1))
            {
                interface1.populate(interface2, posX - 1, posY);
            }

            if (interface1.chunkExists(posX, posY - 1) && !interface1.provideChunk(posX, posY - 1).isTerrainPopulated && interface1.chunkExists(posX + 1, posY - 1) && interface1.chunkExists(posX + 1, posY - 1) && interface1.chunkExists(posX + 1, posY))
            {
                interface1.populate(interface2, posX, posY - 1);
            }

            if (interface1.chunkExists(posX - 1, posY - 1) && !interface1.provideChunk(posX - 1, posY - 1).isTerrainPopulated && interface1.chunkExists(posX, posY - 1) && interface1.chunkExists(posX - 1, posY))
            {
                interface1.populate(interface2, posX - 1, posY - 1);
            }
    	}
    }

 

Now this code is not perfect. It seems as though somewhere else in the code the world wants to keep attempting to generate chunks past the limit and as such causes the player to glitch out when in the area where a chunk would be. If I have time between work and school this week I'll work on sorting that out so that the area around the chunk limit isn't glitchy and the player can just jump off the world and fall into the void.

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.