The first part of the code is done in the main mod file. This is the file I will start with.
package tutorial;
import
net.minecraft.block.Block;
import
net.minecraft.block.material.Material;
import
net.minecraft.enchantment.Enchantment;
import
net.minecraft.item.Item;
import
net.minecraft.item.ItemStack;
import
net.minecraft.item.crafting.FurnaceRecipes;
import
cpw.mods.fml.common.Mod;
import
cpw.mods.fml.common.Mod.EventHandler;
import
cpw.mods.fml.common.event.FMLInitializationEvent;
import
cpw.mods.fml.common.network.NetworkMod;
import
cpw.mods.fml.common.registry.GameRegistry;
import
cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = "Tutorial
Mod",
version = "1.0")
@NetworkMod(clientSideRequired =
true, serverSideRequired
= false)
public class Tutorial
{
public static final String modid = "YourName_ModName";
public static Block tutorialBlock;
public static Item tutorialItem;
EventManager
eventmanager = new EventManager();
@EventHandler
public void
load(FMLInitializationEvent event)
{
tutorialBlock = new
BlockTutorialBlock(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 = new
ItemTutorial(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.
public static int dimensionId =
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;
import
net.minecraft.block.Block;
import
net.minecraft.block.material.Material;
import
net.minecraft.item.Item;
import
net.minecraft.item.ItemStack;
import
net.minecraftforge.common.DimensionManager;
import
cpw.mods.fml.common.Mod;
import
cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import
cpw.mods.fml.common.network.NetworkMod;
import
cpw.mods.fml.common.registry.GameRegistry;
import
cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = "Tutorial
Mod",
version = "1.0")
@NetworkMod(clientSideRequired =
true, serverSideRequired
= false)
public class Tutorial
{
public static final String modid = "YourName_ModName";
public static Block tutorialBlock;
public static Item tutorialItem;
public static int dimensionId = 8;
EventManager
eventmanager = new EventManager();
@EventHandler
public void
load(FMLInitializationEvent event)
{
tutorialBlock = new
BlockTutorialBlock(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 = new
ItemTutorial(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;
import
net.minecraft.world.WorldProvider;
public class
WorldProviderTutorial extends WorldProvider
{
@Override
public String
getDimensionName()
{
return null;
}
}
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.
public void registerWorldChunkManager()
{
this.worldChunkMgr = new
WorldChunkManagerHell(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()
{
return new 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;
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.desertHills, 0.8F, 0.1F);
this.dimensionId = Tutorial.dimensionId;
}
public IChunkProvider
createChunkGenerator()
{
return new 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.
When you are done you can go back to the tutorial list over here.

Geen opmerkingen:
Een reactie posten