最新版 |
編集中の文章 |
24行目: |
24行目: |
| @EventHandler | | @EventHandler |
| public void init(FMLInitialization event) { | | public void init(FMLInitialization event) { |
− | EntityRegistry.registerModEntity(EntitySample.class, "SampleEntity", 0, this, 250, 1, false); | + | EntityRegistry.registerModEntity(EntitySample.class, "SampleEntity, 0, this, 250, 1, false); |
| EntityRegistry.addSpawn(EntitySample.class, 20, 1, 4, EnumCreatureType.creature, BiomeGenBase.plains); | | EntityRegistry.addSpawn(EntitySample.class, 20, 1, 4, EnumCreatureType.creature, BiomeGenBase.plains); |
| if(FMLCommonHandler.instance().getSide() == Side.CLIENT) { | | if(FMLCommonHandler.instance().getSide() == Side.CLIENT) { |
36行目: |
36行目: |
| package mods.entity; | | package mods.entity; |
| | | |
− | import net.minecraft.block.Block;
| + | public class EntitySample extends EntityLiving { |
− | import net.minecraft.entity.EnumCreatureAttribute;
| |
− | import net.minecraft.entity.EntityLiving;
| |
− | import net.minecraft.entity.ai.EntityAIWander;
| |
− | import net.minecraft.entity.ai.EntityAILookIdle;
| |
− | import net.minecraft.init.Items;
| |
− | import net.minecraft.item.Item;
| |
− | import net.minecraft.world.World;
| |
− | | |
− | | |
− | public class EntitySample extends EntityCreature { | |
| public EntitySample(World world) { | | public EntitySample(World world) { |
| super(world); | | super(world); |
− | // うろうろ移動するAIの追加 | + | //bうろうろ移動するAIの追加 |
| this.tasks.addTask(1, new EntityAIWander(this, 1.0D)); | | this.tasks.addTask(1, new EntityAIWander(this, 1.0D)); |
| // 見回すAIの追加 | | // 見回すAIの追加 |
88行目: |
78行目: |
| package mods.entity; | | package mods.entity; |
| | | |
− | import net.minecraft.client.renderer.entity.RenderBiped;
| + | public class RenderSample extends RenderSheep { |
− | import net.minecraft.entity.EntityLiving;
| + | public RenderSample( |
− | import net.minecraft.util.ResourceLocation;
| |
− | | |
− | public class RenderSample extends Render { | |
− | public static final ResourceLocation texture = new ResourceLocation("entity:textures/entity/sample.png");
| |
− | public RenderSample() {
| |
− | // 引数:(ModelBase以降を継承したクラスのインスタンス、影の大きさ)
| |
− | super(new ModelSample(), 0.6f);
| |
− | }
| |
− | | |
− | public ResourceLocation getEntityTexture(EntityLiving entity) { return texture; }
| |
− | }
| |
− | </source>
| |
− | | |
− | *ModelSample.java
| |
− | <source lang="java">
| |
− | package mods.entity;
| |
− | | |
− | import net.minecraft.client.model.ModelBase;
| |
− | import net.minecraft.client.model.ModelRenderer;
| |
− | | |
− | public class ModelSample extends ModelBase {
| |
− | // モデルの直方体を代入する変数
| |
− | ModelRenderer bottom;
| |
− | ModelRenderer base;
| |
− | ModelRenderer top;
| |
− | | |
− | public ModelSample() {
| |
− | super();
| |
− | // テクスチャの縦と横のサイズ
| |
− | textureWidth = 32;
| |
− | textureHeight = 64;
| |
− | // モデルの形を作る
| |
− | base = new ModelRenderer(0, 14);
| |
− | base.addBox(0F, 0F, 0F, 10, 8, 10);
| |
− | | |
− | bottom = new ModelRenderer(32, 2);
| |
− | bottom.addBox(1F, 8F, 1F, 8, 8, 8);
| |
− | | |
− | top = new ModelRenderer(40, 18);
| |
− | top.addBox(2F, 16F, 2F, 6, 8, 6);
| |
− | }
| |
− | | |
− | @Override
| |
− | public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { | |
− | // 描画
| |
− | base.render(f5);
| |
− | bottom.render(f5);
| |
− | top.render(f5);
| |
− | }
| |
− | }
| |
− | </source>
| |
− | | |
− | ===解説===
| |
− | *SampleEntityCore.java
| |
− | このModのエントリクラス。
| |
− | *EntitySample.java
| |
− | うろついたり、見回したりする程度のAIを追加している。
| |
− | *RenderSample.java
| |
− | 追加するMobの描画クラス。
| |
− | *ModelSample.java
| |
− | コンストラクタで、モデルの各直方体の大きさ、 回転軸、角度を決める。
| |
− | <source lang="java">
| |
− | ModelRenderer base;
| |
− | | |
− | public ModelSample() {
| |
− | base = new ModelRenderer(0, 0); // 引数:(テクスチャ画像の始点のX座標、テクスチャ画像の始点のY座標)
| |
− | base.addBox(0f, 0f, 0f, 1, 1, 1,); // 大きさの定義。引数:(始X, 始Y, 始Z, 終X, 終Y, 終Z)
| |
− | base.setRotationPoint(0.5f, 0.5f, 0.5f); // 回転軸の定義。引数:(X, Y, Z)
| |
− | base.rotateAngleX = 45f;
| |
− | base.rotateAngleZ = 45f; // X軸とZ軸方向に45度ずつ回転
| |
| } | | } |
| </source> | | </source> |