提供: Minecraft Modding Wiki
2016年4月7日 (木) 14:52時点におけるModderKina (トーク | 投稿記録)による版 (作った。不親切。)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

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

Wood pickaxe.png
初心者向けのチュートリアルです。
C none.png
Potionに関係のあるチュートリアルです。

EntityLivingBaseに付与できるポーションの追加方法。
PotionTypeも追加することで、自動的に追加したポーションのポーション瓶、ポーション矢、滞留ポーションがクリエイティブインベントリに追加される。

ポーションの追加[編集]

ソースコード[編集]

  • SampleMod.java
package com.example.potion;

import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = SampleMod.MOD_ID,
        name = SampleMod.MOD_NAME,
        version = SampleMod.MOD_VERSION,
        dependencies = SampleMod.MOD_DEPENDENCIES,
        acceptedMinecraftVersions = SampleMod.MOD_ACCEPTED_MC_VERSIONS,
        useMetadata = true)
public class SampleMod{
    /** ModID文字列 */
    public static final String MOD_ID = "samplemod";
    /** MOD名称 */
    public static final String MOD_NAME = "SampleMod";
    /** MODのバージョン */
    public static final String MOD_VERSION = "0.0.1";
    /** 前に読み込まれるべき前提MODをバージョン込みで指定 */
    public static final String MOD_DEPENDENCIES = "required-after:Forge@[1.9-12.16.0.1853,)";
    /** 起動出来るMinecraft本体のバージョン。記法はMavenのVersion Range Specificationを検索すること。 */
    public static final String MOD_ACCEPTED_MC_VERSIONS = "[1.9]";
    /** 追加したいポーションのインスタンスを保持。 */
    public static Potion samplepotion;
    public static PotionType samplepotiontype;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event){
        //ポーションの登録。登録文字列はMOD内で被らなければ何でも良い。
        samplepotion = new SamplePotion();
        GameRegistry.register(samplepotion,new ResourceLocation(MOD_ID,"sample"));
        //ポーションタイプの登録。登録文字列はMOD内で被らなければ何でも良い。
        samplepotiontype = new PotionType("sample",new PotionEffect(samplepotion));
        GameRegistry.register(samplepotiontype,new ResourceLocation(MOD_ID,"sample"));
    }
}
  • SamplePotion.java
package com.example.potion;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.Potion;
import net.minecraft.util.text.TextComponentString;

public class SamplePotion extends Potion{
    public SamplePotion(){
        super(false, 0xFFFFFF);
        setPotionName("sample");/*Potionの内部名を指定*/
    }

    @Override
    public void performEffect(EntityLivingBase entityLivingBaseIn, int p_76394_2_){
        entityLivingBaseIn.addChatMessage(new TextComponentString("You Are Performed"));
    }

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

    @Override
    public boolean isReady(int duration, int amplifier){
        return true;
    }

    /*
    ポーションのアイコンを表示する際に実装する。
    @Override
    public int getStatusIconIndex(){
        //Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));//ポーションのアイコンのテクスチャの場所を指定する。
        return super.getStatusIconIndex();
    }

    @Override
    public boolean hasStatusIcon(){
        return true;
    }
    */
}