提供: Minecraft Modding Wiki
移動先: 案内検索
1行目: 1行目:
 
{{前提MOD|reqmod="Minecraft Forge Universal"}}
 
{{前提MOD|reqmod="Minecraft Forge Universal"}}
 
{{チュートリアル難易度|difficulty=1|clear=none}}
 
{{チュートリアル難易度|difficulty=1|clear=none}}
{{チュートリアルカテゴリー|difficulty=0|type=Item|clear=none}}
+
{{チュートリアルカテゴリー|difficulty=1|type=Item|clear=none}}
{{チュートリアルカテゴリー ‎|type=Block|difficulty=0}}
+
{{チュートリアルカテゴリー ‎|type=Block|difficulty=1}}
  
  

2016年2月10日 (水) 15:01時点における版

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

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


この記事は http://forum.minecraftuser.jp/viewtopic.php?f=39&t=29948 での質問の結果を流用しており、
コード内のコメントを削除されていて、解説として不適切です。
修正されるまで参考にしないで下さい。

チェストにアイテムを入れる

今回は右クリックされると、一つ上のチェスト(インベントリを持つTileEntity) にアイテムを入れる。

package sample;

//import省略

public class chestinitem extends Block {
@SideOnly(Side.CLIENT)
    private IIcon TopIcon;

    @SideOnly(Side.CLIENT)
    private IIcon SideIcon;

public open() {
        super(Material.rock);
        //省略
    }
@Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float posX, float posY, float posZ){
if (!world.isRemote)
            {
               Block block = world.getBlock(x, y+1, z);
               int meta = world.getBlockMetadata(x, y+1, z);


               if (block.hasTileEntity(meta))
               {
                  TileEntity tile = world.getTileEntity(x, y+1, z);

                  if (tile != null)
                  {

                     if (tile instanceof IInventory)
                     {
                        IInventory inventory = (IInventory)tile;


                        for (int pl = 0; pl < inventory.getSizeInventory(); ++pl)
                        {
                           ItemStack itemstack = inventory.getStackInSlot(pl);


                           if (itemstack == null)
                           {


                              inventory.setInventorySlotContents(pl, new ItemStack(items.diamond));//ダイヤを一個入れる
                              return true;

                           }
                        }
                     }
                  }
               }
            }

解説

変数plにTileEntity毎のインベントリ情報を入れ、
空いているスロットに入れている。