Modding 1.4.7: Adding a custom mob to Dungeons

In this tutorial I will show you how to add a custom mob to the Dungeons without editing any source code. This can be any kind of mob and for this tutorial I will be using the EntityTutorial mob. All of the code has to be added in your mod file. This is the file I will start with.

package tutorial;

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.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;
      
       @Init
       public void load(FMLInitializationEvent event)
       {
             proxy.registerRenderThings();
            
             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));
       }
}

To add your custom mob to the vanilla dungeons without editing any file you can simply use this line of code.

DungeonHooks.addDungeonMob("Tutorial", 50);

You will have to add this line inside of the load method and you will have to import net.minecraftforge.common.DungeonHooks.
There are 2 parameters in this method. The first one is the name of the mob. This has to be exactly the same as the second parameter from your registerModEntity line. If you make it any different it will not work.
The second parameter in the addDungeonMob method is the rarity. The chance for zombies is 200 and for skeletons and spiders 100. The higher the number the more often you will see it in the dungeon.
The whole file should now look like this.

package tutorial;

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.DungeonHooks;
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.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;
      
       @Init
       public void load(FMLInitializationEvent event)
       {
             proxy.registerRenderThings();
            
             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);
      
             DungeonHooks.addDungeonMob("Tutorial", 50);
       }
      
       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));
       }
}


When you are done you should go back to the tutorials list here.

1 opmerking:

  1. ROBLOX is driven by a growing player base of over 300,000 creator players who generate an infinite variety of highly immersive experiences.

    These experiences range from 3D multi-player games and contests, to interactive adventures where friends can take on new personas imagining what it would be like to be a dinosaur, a miner in a quarry or an astronaut out in space.

    BeantwoordenVerwijderen