Modding 1.4.7: Custom Dimension Part 3: DimensionRegistry

In this tutorial I will show you how to register your dimension with forge. This code is done in the mod file. This is the 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 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 
{
public static Block tutorialBlock;
public static Block portal;

@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

static int startEntityId = 300;

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

tutorialBlock = new BlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);
portal = new BlockPortalTutorial(251, 1).setBlockName(“portal”);

GameRegistry.registerBlock(tutorialBlock, “Wuppy29_TutorialBlock”);
GameRegistry.registerBlock(portal, “Wuppy29_Portal”);

LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
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);
}

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));
}
}


The first thing you will have to do is create a variable that can be used at several locations. You don’t have to do this, but it will make it a lot easier and it will remove some possible bugs.
So add a line like this right below the proxy.


public static int dimension = 20;


The number you set it to will be the number of the dimension.  I suggest keeping this number somewhere under 30, because of compatibility with Mystcraft.
Now you have to add this line of code inside of the load method.


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


The first parameter in this line is the id for the second parameter. In this case 20, because that is what we set dimension to.
The second parameter is the WorldProvider which will be used for that dimension. Make sure you get that .class on the end.
The last parameter is if the world should stay loaded when the player isn’t in there. I suggest keeping this at false, because it will really slow down the game. The nether, end and overworld also aren’t loaded when there isn’t a player in it.

The second line of code you will have to add to your mod file looks like this.


DimensionManager.registerDimension(dimension, dimension);


This line of code will check if there is a WorldProvider class that has been set to the id in the first parameter. You have done this in the line above.
The second parameter is the actual dimension id.

The mod file should now look something like this.


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 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 
{
public static Block tutorialBlock;
public static Block portal;

@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

static int startEntityId = 300;
public static int dimension = 20;

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

tutorialBlock = new BlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);
portal = new BlockPortalTutorial(251, 1).setBlockName(“portal”);

GameRegistry.registerBlock(tutorialBlock, “Wuppy29_TutorialBlock”);
GameRegistry.registerBlock(portal, “Wuppy29_Portal”);

LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
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));
}
}


You will have an error under the WorldProviderTutorial, but that is normal. We will fix that in the next tutorial by creating the WorldProvider class.
In the next tutorial I will show you how to add a very important method to the Block file. After that I will create the WorldProvider class.
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="">