提供: Minecraft Modding Wiki
移動先: 案内検索
(ソースコード)
39行目: 39行目:
 
     public EntitySample(World world) {
 
     public EntitySample(World world) {
 
         super(world);
 
         super(world);
         //bうろうろ移動するAIの追加
+
         // うろうろ移動するAIの追加
 
this.tasks.addTask(1, new EntityAIWander(this, 1.0D));
 
this.tasks.addTask(1, new EntityAIWander(this, 1.0D));
 
// 見回すAIの追加
 
// 見回すAIの追加
78行目: 78行目:
 
package mods.entity;
 
package mods.entity;
  
public class RenderSample extends RenderSheep {
+
public class RenderSample extends Render {
     public RenderSample(
+
    public static final ResourceLocation texture = new ResourceLocation("entity:textures/entity/sample.png");
 +
     public RenderSample() {
 +
        super(new ModelSample(), 1.0f);
 +
    }
 +
 
 +
    public ResourceLocation getTexture() { return texture; }
 +
}
 +
</source>
 +
 
 +
*ModelSample.java
 +
<source lang="java">
 +
package mods.entity;
 +
 
 +
public class ModelSample extends Model {
 +
    ModelRenderer bottom;
 +
    ModelRenderer base;
 +
    ModelRenderer top;
 +
 
 +
    public ModelSample() {
 +
        bottom = new ModelRenderer(this);
 +
    }
 
}
 
}
 
</source>
 
</source>

2014年11月30日 (日) 13:44時点における版

この記事は"Minecraft Forge Universal 9.10.0.871~"を前提MODとしています。

Stone pickaxe.png
中級者向けのチュートリアルです。
C entity.png
Entityに関係のあるチュートリアルです。

このページは、編集中です。

MOBの追加

EntityLivingを継承して、MOBを追加します。 モデルやAIも実装します

ソースコード

  • SampleEntityCore.java
package mods.entity;

import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;

@Mod(modid = "SampleEntity", name = "SampleEntity", version = "1.0.0")
public class SampleEntityCore {
    @EventHandler
    public void init(FMLInitialization event) {
        EntityRegistry.registerModEntity(EntitySample.class, "SampleEntity, 0, this, 250, 1, false);
        EntityRegistry.addSpawn(EntitySample.class, 20, 1, 4, EnumCreatureType.creature, BiomeGenBase.plains);
        if(FMLCommonHandler.instance().getSide() == Side.CLIENT) {
		RenderingRegistry.registerEntityRenderingHandler(EntitySample.class, new RenderSample());
        }
}
  • EntitySample.java
package mods.entity;

public class EntitySample extends EntityLiving {
    public EntitySample(World world) {
        super(world);
        	// うろうろ移動するAIの追加
		this.tasks.addTask(1, new EntityAIWander(this, 1.0D));
		// 見回すAIの追加
		this.tasks.addTask(2, new EntityAILookIdle(this));
    }

    @Override
    public boolean isAIEnabled() { return true; }

    @Override
    public String getLivingSound() { return /* MOBが生きている時の音のファイルパスを返す。 */ ; }

    @Override
    public String getHurtSound() { return /* MOBがダメージを受けた時の音のファイルパスを返す。 */ ; }

    @Override
    public String getDeathSound() { return /* MOBが死亡した時の音のファイルパスを返す。*/ ; }

    /*
    * このMobが動いているときの音のファイルパスを返す.
    * 引数のblockはMobの下にあるBlock.
    */
    @Override
    protected void func_145780_a(int x, int y, int z, Block block)
    {
	this.playSound("mob.skeleton.step", 0.15F, 1.0F);
    }

   @Override
    public EnumCreatureAttribute getCreatureAttribute() { return EnumCreatureAttribute.UNDEFINED; }

    @Override
    public Item getDropItem() { return /* ドロップするアイテム */ ; }
}
  • RenderSample.java
package mods.entity;

public class RenderSample extends Render {
    public static final ResourceLocation texture = new ResourceLocation("entity:textures/entity/sample.png");
    public RenderSample() {
        super(new ModelSample(), 1.0f);
    }

    public ResourceLocation getTexture() { return texture; }
}
  • ModelSample.java
package mods.entity;

public class ModelSample extends Model {
    ModelRenderer bottom;
    ModelRenderer base;
    ModelRenderer top;

    public ModelSample() {
        bottom = new ModelRenderer(this);
    }
}