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.
When you are done you should go back to the tutorials list here.
I've done all with your tutorials but Minecraft crashes. The text that console prints ia here: http://pastebin.com/NbSZjiKE
BeantwoordenVerwijderenI see that's something wrong with dimension registry (2013-01-11 15:52:57 [INFO] [STDERR] java.lang.IllegalArgumentException: Failed to register dimension for id 3, One is already registered). What do I have to correct? Code of the main class: http://pastebin.com/EGey6Vcm
The first thing you should do is try to use another number.
VerwijderenThe second thing you need to do is use System.out.println("something"); in the dimension code part. If you see it more than once in the console that's your problem.
After that I wouldn't really know what is wrong.
I tried to use another ids (4, 10, 42, 256, 98725968928743) but it's still crashing :(
Verwijderen'DimensionManager cannot be resolved' comes up when I try and use it. What should I replace it with?
VerwijderenWhen i type in : DimensionManager.registerProviderType(dimension, WorldProviderTutorial.class, false);
BeantwoordenVerwijderenthere comes : The method registerProviderType(int, Class, boolean) in the type DimensionManager is not applicable for the arguments (int, Class, boolean)
Complete your dimension, it's fixed for me.
VerwijderenWhen I step in my Portal, it says "Shutting down internal server..." Then crashes. It says:
BeantwoordenVerwijderen"Caused by: java.lang.ClassCastException: net.minecraft.client.entity.EntityClientPlayerMP cannot be cast to net.minecraft.entity.player.EntityPlayerMP"
in the Console. So if you can help me, it will be great...
When i build a portal with my block and light it on fire the portal block doesn't show up. Can you help me?
BeantwoordenVerwijderenPortal File Code: http://pastebin.com/8RGGM22c
Mod File Code: http://pastebin.com/BMcZMGeW