0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[minecraft][Forge] ItemとBlockに情報を付与する [modding]

0
Last updated at Posted at 2016-04-07

はじめに

動作環境

  1. minecraftForge 1.7.10
  2. intelliJ 15.0.3

やりたかったこと

こんなの
some informationの部分の実装

スクリーンショット 2016-04-07 17.35.50.png
スクリーンショット 2016-04-07 17.35.59.png

コード部分

アイテムとブロックで実装が異なる。

  • 最初は簡単なItemから

ItemにはもともとaddInformationというメソッドが存在するので、それをOverrideしてつかう。以下を情報を追加したいItemのクラスに追加する。

myitem.java
    @Override
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean b)
    {
        list.add("some information");
    }
  • 次に複雑になるBlockでのaddInformationの方法について

BlockにはaddInformationのメソッドはないので、Blockのクラスだけでは実現することができない。

ではどこにブロックのaddInformationが可能な箇所があるのか??

ItemBlockというものが存在する。

ということで、新しいJavaClassを作成。
名前はなんでもいいですが、ここではCustomItemBlockとする。
作成したクラスを以下のように書き換えてください。

CustomItemBlock.java
@SideOnly(Side.CLIENT)
public class CustomItemBlock extends ItemBlock
{
    public CustomItemBlock(Block block)
    {
        super(block);
    }

    public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4)
    {
        list.add("some information");
    }
}

複数のブロックに対して、情報を表示したい場合はその都度、クラスを作る。

最後にregisterにひと工夫加える。

ExampleBlock.java
GameRegistry.registerBlock(myblock, CustomItemBlock.class, "myblock");

これで情報を付与したブブロックの登録ができる!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?