提供: Minecraft Modding Wiki
移動先: 案内検索

この記事は"Minecraft Forge Universal 13.19.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.EventBusSubscriber;
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)
@EventBusSubscriber
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.11-13.19.0.2130,)";

    /**
     * 起動出来るMinecraft本体のバージョン。記法はMavenのVersion Range Specificationを検索すること。
     */
    public static final String MOD_ACCEPTED_MC_VERSIONS = "[1.11]";

    /**
     * 追加したいポーションのインスタンスを保持。
     */
    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
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.Potion;
import net.minecraft.util.text.TextComponentString;

import javax.annotation.Nonnull;

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

    @Override
    public void performEffect(@Nonnull EntityLivingBase entityLivingBaseIn, int p_76394_2_){
        entityLivingBaseIn.sendMessage(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;
    }
    */
}

解説

以前とは違い、登録用イベントが発火されるようになった。……のだが、順序が良くないため、Modで登録されたポーションをポーションタイプで登録するのには向いていない。
よって、1.9と同じ方法である。変更点はほぼない。
LangやModel用Jsonについては過去のチュートリアルを参照のこと。