提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
10行目: | 10行目: | ||
import java.util.List; | import java.util.List; | ||
− | public class ItemTNTRemote extends Item | + | public class ItemTNTRemote extends Item { |
− | { | ||
public int posx,posy,posz; | public int posx,posy,posz; | ||
− | + | ItemHoge(int id){ | |
− | |||
super(id); | super(id); | ||
//スタック不可能にする。 | //スタック不可能にする。 | ||
25行目: | 23行目: | ||
//1.3.xのみメソッド名がtryPlaceIntoWorldなので注意 | //1.3.xのみメソッド名がtryPlaceIntoWorldなので注意 | ||
@Override | @Override | ||
− | public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int side) | + | public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int side){ |
− | + | if(!world.isRemote){ | |
− | if(!world.isRemote) | ||
− | |||
//NBTタグを取得します。 | //NBTタグを取得します。 | ||
NBTTagCompound nbt = itemstack.getTagCompound(); | NBTTagCompound nbt = itemstack.getTagCompound(); | ||
− | if(nbt == null) | + | if(nbt == null){ |
− | |||
nbt = new NBTTagCompound(); | nbt = new NBTTagCompound(); | ||
itemstack.setTagCompound(nbt); | itemstack.setTagCompound(nbt); | ||
} | } | ||
//対象ブロックがTNTの場合は位置を記録し、それ以外の場合は着火処理を行う。 | //対象ブロックがTNTの場合は位置を記録し、それ以外の場合は着火処理を行う。 | ||
− | if(world.getBlockId(x, y, z) == Block.tnt.blockID) | + | if(world.getBlockId(x, y, z) == Block.tnt.blockID){ |
− | |||
nbt.setInteger("PosX", x); | nbt.setInteger("PosX", x); | ||
nbt.setInteger("PosY", y); | nbt.setInteger("PosY", y); | ||
nbt.setInteger("PosZ", z); | nbt.setInteger("PosZ", z); | ||
− | } | + | }else{ |
− | |||
− | |||
onItemRightClick(itemstack, world, entityplayer); | onItemRightClick(itemstack, world, entityplayer); | ||
} | } | ||
53行目: | 45行目: | ||
//空中を右クリックした場合に呼ばれます。 | //空中を右クリックした場合に呼ばれます。 | ||
@Override | @Override | ||
− | public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) | + | public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer){ |
− | + | if(!world.isRemote){ | |
− | if(!world.isRemote) | ||
− | |||
NBTTagCompound nbt = itemstack.getTagCompound(); | NBTTagCompound nbt = itemstack.getTagCompound(); | ||
if(nbt == null) | if(nbt == null) | ||
63行目: | 53行目: | ||
posy = nbt.getInteger("PosY"); | posy = nbt.getInteger("PosY"); | ||
posz = nbt.getInteger("PosZ"); | posz = nbt.getInteger("PosZ"); | ||
− | if(world.getBlockId(posx, posy, posz) == Block.tnt.blockID) | + | if(world.getBlockId(posx, posy, posz) == Block.tnt.blockID){ |
− | |||
Block.tnt.onBlockDestroyedByPlayer(world, posx, posy, posz, 1); | Block.tnt.onBlockDestroyedByPlayer(world, posx, posy, posz, 1); | ||
world.setBlockWithNotify(posx, posy, posz, 0); | world.setBlockWithNotify(posx, posy, posz, 0); | ||
75行目: | 64行目: | ||
@Override | @Override | ||
public void addInformation(ItemStack itemstack, List list) | public void addInformation(ItemStack itemstack, List list) | ||
− | + | { | |
NBTTagCompound nbt = itemstack.getTagCompound(); | NBTTagCompound nbt = itemstack.getTagCompound(); | ||
if(nbt == null) | if(nbt == null) | ||
84行目: | 73行目: | ||
posz = nbt.getInteger("PosZ"); | posz = nbt.getInteger("PosZ"); | ||
list.add("[" + posx + "," + posy + "," + posz + "]"); | list.add("[" + posx + "," + posy + "," + posz + "]"); | ||
− | + | } | |
} | } | ||
93行目: | 82行目: | ||
<source lang="java"> | <source lang="java"> | ||
NBTTagCompound nbt = itemstack.getTagCompound(); | NBTTagCompound nbt = itemstack.getTagCompound(); | ||
− | if(nbt == null) | + | if(nbt == null){ |
− | { | ||
nbt = new NBTTagCompound(); | nbt = new NBTTagCompound(); | ||
itemstack.setTagCompound(nbt); | itemstack.setTagCompound(nbt); | ||
103行目: | 91行目: | ||
**なのでnullが返ってきた場合は、新しくNBTタグを作成し、アイテムに登録します。 | **なのでnullが返ってきた場合は、新しくNBTタグを作成し、アイテムに登録します。 | ||
<source lang="java"> | <source lang="java"> | ||
− | if(world.getBlockId(x, y, z) == Block.tnt.blockID) | + | if(world.getBlockId(x, y, z) == Block.tnt.blockID){ |
− | { | ||
nbt.setInteger("PosX", x); | nbt.setInteger("PosX", x); | ||
nbt.setInteger("PosY", y); | nbt.setInteger("PosY", y); | ||
nbt.setInteger("PosZ", z); | nbt.setInteger("PosZ", z); | ||
− | } | + | }else{ |
− | else | ||
− | { | ||
onItemRightClick(itemstack, world, entityplayer); | onItemRightClick(itemstack, world, entityplayer); | ||
} | } | ||
117行目: | 102行目: | ||
===onItemRightClick=== | ===onItemRightClick=== | ||
<source lang="java"> | <source lang="java"> | ||
+ | NBTTagCompound nbt = itemstack.getTagCompound(); | ||
NBTTagCompound nbt = itemstack.getTagCompound(); | NBTTagCompound nbt = itemstack.getTagCompound(); | ||
if(nbt == null) | if(nbt == null) |