Wuppy’s Minecraft Forge Modding Tutorials for 1.6.2: Dimensions Part 1: Registry and WorldProvider

In this tutorial series I will show you how to add a custom dimension to Minecraft. At first this will be the most basic possible dimension, but after that there will be some customization.
The first part of the code is done in the main mod file. This is the file I will start with.


package tutorial;
importnet.minecraft.block.Block;
importnet.minecraft.block.material.Material;
importnet.minecraft.enchantment.Enchantment;
importnet.minecraft.item.Item;
importnet.minecraft.item.ItemStack;
importnet.minecraft.item.crafting.FurnaceRecipes;
importcpw.mods.fml.common.Mod;
importcpw.mods.fml.common.Mod.EventHandler;
importcpw.mods.fml.common.event.FMLInitializationEvent;
importcpw.mods.fml.common.network.NetworkMod;
importcpw.mods.fml.common.registry.GameRegistry;
importcpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = “Tutorial Mod”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial
{
       publicstaticfinal String modid = “YourName_ModName”;
      
       publicstatic Block tutorialBlock;
      
       publicstatic Item tutorialItem;
      
       EventManager eventmanager = new EventManager();
      
       @EventHandler
       publicvoidload(FMLInitializationEvent event)
       {
              tutorialBlock = newBlockTutorialBlock(500, Material.rock).setUnlocalizedName(“tutorialBlock”);
             
              GameRegistry.registerBlock(tutorialBlock, ItemTutorialBlock.class, modid + (tutorialBlock.getUnlocalizedName().substring(5)));
        LanguageRegistry.addName(new ItemStack(tutorialBlock, 1, 0), “Tutorial Block”);
        LanguageRegistry.addName(new ItemStack(tutorialBlock, 1, 1), “Nether Tutorial Block”);
             
              tutorialItem = newItemTutorial(5000).setUnlocalizedName(“tutorialItem”);
             
              LanguageRegistry.addName(new ItemStack(tutorialItem, 1, 0), “Tutorial Item”);
              LanguageRegistry.addName(new ItemStack(tutorialItem, 1, 1), “Second Tutorial Item”);
             
              GameRegistry.registerWorldGenerator(eventmanager);
             
              TutorialCrafting.loadRecipes();
       }
}

The first thing you will have to do is make a dimension id variable. You need to make this a variable, because you will be using this number quite a few times.


publicstaticintdimensionId = 8;

You should keep this number pretty low, but you can’t use 0, 1 or -1.
The next thing you need to do is add 2 lines to the load method.


DimensionManager.registerProviderType(Tutorial.dimensionId, WorldProviderTutorial.class, false);
DimensionManager.registerDimension(Tutorial.dimensionId, Tutorial.dimensionId);

The first line is to register the world provider. The first parameter is the id of the dimension. The second is the world provider and the last is a boolean whether or not the dimension should be loaded at all times. I suggest keeping this false at all times to keep the load time of the world low. The WorldProvider will be a file for the dimenson which will do several things. It will give the biome of the dimension, but it will also contain quite a few important options for the dimension.
The second line is simply twice the dimension id to register the dimension.
Now the mod file should look like this.


package tutorial;
importnet.minecraft.block.Block;
importnet.minecraft.block.material.Material;
importnet.minecraft.item.Item;
importnet.minecraft.item.ItemStack;
importnet.minecraftforge.common.DimensionManager;
importcpw.mods.fml.common.Mod;
importcpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
importcpw.mods.fml.common.network.NetworkMod;
importcpw.mods.fml.common.registry.GameRegistry;
importcpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = “Tutorial Mod”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial
{
       publicstaticfinal String modid = “YourName_ModName”;
      
       publicstatic Block tutorialBlock;
      
       publicstatic Item tutorialItem;
      
       publicstaticintdimensionId = 8;
      
       EventManager eventmanager = new EventManager();
      
       @EventHandler
       publicvoidload(FMLInitializationEvent event)
       {
              tutorialBlock = newBlockTutorialBlock(500, Material.rock).setUnlocalizedName(“tutorialBlock”);
             
              GameRegistry.registerBlock(tutorialBlock, ItemTutorialBlock.class, modid + (tutorialBlock.getUnlocalizedName().substring(5)));
        LanguageRegistry.addName(new ItemStack(tutorialBlock, 1, 0), “Tutorial Block”);
        LanguageRegistry.addName(new ItemStack(tutorialBlock, 1, 1), “Nether Tutorial Block”);
             
              tutorialItem = newItemTutorial(5000).setUnlocalizedName(“tutorialItem”);
             
              LanguageRegistry.addName(new ItemStack(tutorialItem, 1, 0), “Tutorial Item”);
              LanguageRegistry.addName(new ItemStack(tutorialItem, 1, 1), “Second Tutorial Item”);
             
              GameRegistry.registerWorldGenerator(eventmanager);
             
              TutorialCrafting.loadRecipes();
             
              DimensionManager.registerProviderType(Tutorial.dimensionId, WorldProviderTutorial.class, false);
              DimensionManager.registerDimension(Tutorial.dimensionId, Tutorial.dimensionId);
       }
}

Right now you will have an error under WorldProviderTutorial. To fix that hover your mouse over it and click create class. Then make that file extend WorldProvider, import and add unimplemented methods. You should get a file that looks like this.


package tutorial;
importnet.minecraft.world.WorldProvider;
publicclassWorldProviderTutorial extends WorldProvider
{
       @Override
       public String getDimensionName()
       {
              returnnull;
       }
}

Now change the method from returning null into returning a String with whatever the name of your dimension should be. For me it will be called “Tutorial”.
There are a couple of methods you have to add to get a working dimension. First of all you will need the registerWorldChunkManager method which should look like this.


publicvoid registerWorldChunkManager()
{
       this.worldChunkMgr = newWorldChunkManagerHell(BiomeGenBase.desertHills, 0.8F, 0.1F);
       this.dimensionId = Tutorial.dimensionId;
}

The first line sets several things for the dimension. The WorldChunkManager takes care of which biomes generate where and it also manages rain and temperature (snow or rain). The first parameter is the biome the whole dimension will have. The second parameter is the temperature and the last is how often it will rain. 0.1F being very little and 1.0F being very often.
The second line you will just have to copy over again to make sure that the dimension works properly.

There is one more method you will need to get the dimension to work. This is the createChunkGenerator method. It should look like this.


public IChunkProvider createChunkGenerator()
{
       returnnew ChunkProviderTutorial(worldObj, worldObj.getSeed(), true);
}

The ChunkProvider is one of the most important files in all of the dimension code. It’s also very big so we won’t cover that in this tutorial. In there will be the code for the generation of stone, bedrock and lakes, but it will also be the place where you can find the code for caves, ravines, dungeons and many other things. The line has to be exactly the same for you as in this tutorial except for of course the name of the file.

The whole WorldProvider file should now look like this.


package tutorial;
importnet.minecraft.world.WorldProvider;
importnet.minecraft.world.biome.BiomeGenBase;
importnet.minecraft.world.biome.WorldChunkManagerHell;
importnet.minecraft.world.chunk.IChunkProvider;
publicclassWorldProviderTutorial extends WorldProvider
{
       publicvoidregisterWorldChunkManager()
       {
              this.worldChunkMgr = newWorldChunkManagerHell(BiomeGenBase.desertHills, 0.8F, 0.1F);
              this.dimensionId = Tutorial.dimensionId;
       }
      
       public IChunkProvider createChunkGenerator()
       {
              returnnew ChunkProviderTutorial(worldObj, worldObj.getSeed(), true);
       }
      
       @Override
       public String getDimensionName()
       {
              return“Tutorial”;
       }
}

There are many more methods that you may want to add to this file, but for now we will keep it to the basics. Once we have a working dimension I will show you how to add all kinds of customization to it.

Right now you will have an error under ChunkProviderTutorial. We will fix that in the next tutorial by creating that file.

You can download the source code and the assets folder over here.

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="">