原文地址: http://minecraftmodding.wikkii.com/wiki/Making_an_new_entity_using_modloader_(Penguin)
PS:为方便大家使用,所有关键位置均使用中英双语翻译。
- package net.minecraft.src;
- import java.util.*;
- import java.util.Map;
- public class mod_Penguin extends BaseMod
- {
-
- public mod_Penguin()
- {
- ModLoader.RegisterEntityID(EntityPenguin.class, "Penguin", ModLoader.getUniqueEntityId()); //This registers the entity
-
- ModLoader.AddSpawn("Penguin", 3, EnumCreatureType.creature,new BiomeGenBase[] {
- BiomeGenBase.iceDesert,
- BiomeGenBase.taiga,
- BiomeGenBase.tundra
- });
-
-
- }
-
- // RENDERERS
- public void AddRenderer(Map map)
- {
- map.put(EntityPenguin.class, new RenderPenguin(new ModelPenguin(), 0.5F)); // this assigns the Entity class to the renderer and model class.
- }
- public String Version()
- {
- return "Penguin Mod 1.0"; //this can be whatever you like
- }
- }
- ModLoader.AddSpawn(java.lang.String entityName, int weightedProb, lg spawnList, new BiomeGenBase[] { biomes })
[/spoiler]
这一段代码是将该生物添加至Minecraft的生成名单中,其中
"WeightedPro"代表着该生物的生成几率。
"SpawnList"代表生物种类
- EnumCreatureType.creature 为动物(典型生物:猪)
- EnumCreatureType.monster 为敌人(典型生物:僵尸)
- ENumCreatureType.watercreature 为水生生物(典型生物:墨鱼)
- BiomeGenBase.savanna 热带草原
- BiomeGenBase.swampland 沼泽
- BiomeGenBase.shrubland 灌木林地
- BiomeGenBase.plains 平原
- BiomeGenBase.iceDesert 冰漠
- BiomeGenBase.taiga 针叶林
- BiomeGenBase.forest 森林
- BiomeGenBase.seasonalForest 季节性森林
- BiomeGenBase.rainforest 雨林
- BiomeGenBase.desert 沙漠
[/spoiler]
实体文件决定了该生物所使用的材质、声音、AI、掉落物以及其他您所希望实现的功能
- package net.minecraft.src;
- public class EntityPenguin extends EntityAnimals
- {
- public EntityPenguin(World world)
- {
- super(world);
- texture = "Penguin/Penguin.png"; //this set the texture the mobs going to use
- setSize(1.5F, 1.9F); // this sets the HIT AREA of the mob.
- }
- public void writeEntityToNBT(NBTTagCompound nbttagcompound)
- {
- super.writeEntityToNBT(nbttagcompound); // this saves the mob to disk
- }
- public void readEntityFromNBT(NBTTagCompound nbttagcompound)
- {
- super.readEntityFromNBT(nbttagcompound); // this loads the mob from disk
- }
- protected String getLivingSound()
- {
- return null; //Living sound of the mob
- }
- protected String getHurtSound()
- {
- return null; //Hurt sound of the mob
- }
- protected String getDeathSound()
- {
- return null; //Death sound of the mob
- }
- protected float getSoundVolume()
- {
- return 0.4F;
- }
- protected int getDropItemId()
- {
- return 0; //this is the item id of the drop for example Item.porkchop.shiftedIndex
- }
- }
- package net.minecraft.src;
- public class RenderPenguin extends RenderLiving
- {
- public RenderPenguin(ModelBase modelbase, float f)
- {
- super(modelbase, f);
- }
- public void func_177_a(EntityPenguin entitypenguin, double d, double d1, double d2,
- float f, float f1)
- {
- super.doRenderLiving(entitypenguin, d, d1, d2, f, f1);
- }
- public void doRenderLiving(EntityLiving entityliving, double d, double d1, double d2,
- float f, float f1)
- {
- func_177_a((EntityPenguin)entityliving, d, d1, d2, f, f1);
- }
- public void doRender(Entity entity, double d, double d1, double d2,
- float f, float f1)
- {
- func_177_a((EntityPenguin)entity, d, d1, d2, f, f1);
- }
- }