Modding 1.4.7: Custom Dimension Part 6: WorldProvider

In this tutorial I will show you how to create the WorldProvider class. All of the code in this tutorial will be done in that file, but this is the mod file I will start with.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityEggInfo;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.DimensionManager;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

static int startEntityId = 300;

public static int dimension = 20;

public static Block portal;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();

portal = new BlockPortalTutorial(251, 1).setBlockName(“portal”);
GameRegistry.registerBlock(portal, “Wuppy29_Portal”);
LanguageRegistry.addName(portal, “Custom Portal”);

EntityRegistry.registerModEntity(EntityTutorial.class, “Tutorial”, 1, this, 80, 3, true);

EntityRegistry.addSpawn(EntityTutorial.class, 10, 2, 4, EnumCreatureType.monster, BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.forest);

LanguageRegistry.instance().addStringLocalization(“entity.Tutorial_Tutorialmod.Tutorial.name”, “Tutorial”);

registerEntityEgg(EntityTutorial.class, 0x7A65CF, 0x4DF200);

DimensionManager.registerProviderType(dimension, WorldProviderTutorial.class, false);
DimensionManager.registerDimension(dimension, dimension);
}

public static int getUniqueEntityId()
{
do
{
startEntityId++;
}
while(EntityList.getStringFromID(startEntityId) != null);

return startEntityId;
}

public static void registerEntityEgg(Class <? extends Entity> entity, int primaryColor, int secondaryColor)
{
int id = getUniqueEntityId();
EntityList.IDtoClassMapping.put(id, entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor));
}
}


If you have something like this you will have an error under the WorldProvider file. To fix that simply hover your mouse over it and click Create class. When you do that you will get a file that looks like this.


package tutorial;

public class WorldProviderTutorial {

}


Now you should make it extend WorldProvider. Click the import or press Ctrl, Shift, O. After that you will get an error under your WorldProviderTutorial. To fix that hover your mouse over it and click add unimplemented methods. This will add a method that is called getDimensionName. Replace the null with a pair of quotation marks, remove the comment and the @Override. Once you have done all these things you will get a file that looks like this.


package tutorial;

import net.minecraft.world.WorldProvider;

public class WorldProviderTutorial extends WorldProvider
{
public String getDimensionName() 
{
return “Tutorial”;
}
}


For this tutorial I will make a very basic WorldProvider. In later tutorials I will also show you how to change the file directory name, remove snow and a lot of other things.
There are 3 important methods you will have to add to this file. The first one is really easy.


public boolean canRespawnHere()
{
return true;
}


This is true if the player can respawn in this dimension. If it is false you go back into the overworld when you die.
The next method you will need looks like this.


public void registerWorldChunkManager()
{
this.worldChunkMgr = new WorldChunkManagerHell(BiomeGenBase.beach, 0.8F, 0.1F);
this.dimensionId = Tutorial.dimension;
}


The first line of code adds the WorldChunkManager to the dimension. This file handles biome placement, temperature and rain. In this tutorial we will use the Hell chunk manager with only 1 biome in it, because it’s really hard to make a dimension with more than 1 biome in it.
The first parameter in here is the biome you want to use. For this tutorial it will simply be the beach biome from vanilla Minecraft. In a later tutorial there will also be custom biomes.
The second parameter is the temperature. This will manage ice.
The last parameter is the rain. The higher this is the higher the chance for rain. In this case I will make a dimension without a lot of rain.
The second line of code in here simply sets the dimension id for this file equal to the dimension id used earlier in the mod file.
The last method you have to add to this file looks like this.


@Override
public IChunkProvider createChunkGenerator()
{
return new ChunkProviderTutorial(worldObj, worldObj.getSeed(), true);
}


This method returns the ChunkProvider for this dimension. This is a very important method and the ChunkProvider is a very important file, because it handles pretty much all the generation.
It’s so important that I have added the @Override above it. This simply checks if the method name is the same as with the extended file. If it isn’t it will give you an error, but this is good, because this is an important method. If you find yourself having this error you will have to look in the WorldProvider file for the right new method or just leave a message at the forums or email me at wuppy29@gmail.com.
The whole file should now look something like this.


package tutorial;

import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.WorldChunkManagerHell;
import net.minecraft.world.chunk.IChunkProvider;

public class WorldProviderTutorial extends WorldProvider
{
public void registerWorldChunkManager()
{
this.worldChunkMgr = new WorldChunkManagerHell(BiomeGenBase.beach, 0.8F, 0.1F);
this.dimensionId = Tutorial.dimension;
}

public String getDimensionName() 
{
return “Tutorial”;
}

public boolean canRespawnHere()
{
return true;
}

@Override
public IChunkProvider createChunkGenerator()
{
return new ChunkProviderTutorial(worldObj, worldObj.getSeed(), true);
}
}


In the next tutorial we will be creating the ChunkProvider which is the last file required to have a working dimension. After that there will be a lot of customization tutorials.

The source code will be avaliable at the end of the last tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">