カーソルを向けているentityに持っているだけでダメージを与える、というアイテムを作っているのですが、
カーソルを向けているentityを取得するコードが探しても見つかりません。(ネームタグのクラスを探しましたが良く分からず・・・)
ダメージはattackEntityFromで与えようと思っています。
この方法が難しいようでしたら、
playerに触れた、もしくはplayerを中心とした半径1ブロックにいるentityに
ダメージを与えるでもかまいません。(これも探しましたが結局分からず)
以下きたないソースと元ネタです。よろしく御願いします。
インポート等は省略しています。
- コード: 全て選択
public class KokiriSword extends ItemSword {
public KokiriSword(ToolMaterial toolMaterial) {
super(toolMaterial);
this.setCreativeTab(Main.tabKaiseimod);
this.setUnlocalizedName("KokiriSword");
this.setTextureName("kaiseimod:kokiri_sword");
}
public boolean onEntitySwing(EntityLivingBase entity, ItemStack stack) {
World world = entity.worldObj;
if(!world.isRemote)
{
//NBTタグを取得します。
NBTTagCompound nbt = stack.getTagCompound();
if(nbt == null)
{
nbt = new NBTTagCompound();
stack.setTagCompound(nbt);
}
nbt.setInteger("SwingCnt", 1);
nbt.setBoolean("Yuuyo", false);
System.out.println("swing");
}
return false;
}
public void onUpdate(ItemStack itemStack, World world, Entity entity, int slot, boolean isHeld) {
if(!world.isRemote)
{
//NBTタグを取得します。
NBTTagCompound nbt = itemStack.getTagCompound();
if(nbt == null)
{
nbt = new NBTTagCompound();
itemStack.setTagCompound(nbt);
}
if (nbt.getInteger("SwingCnt") >= 1) {
nbt.setInteger("SwingCnt", nbt.getInteger("SwingCnt") + 1);
System.out.println("残像剣待機");
}
if (nbt.getInteger("SwingCnt") >= 5) {
System.out.println("残像剣猶予");
nbt.setBoolean("Yuuyo", true);
}
if (nbt.getInteger("SwingCnt") == 11) {
System.out.println("残像剣終わり");
nbt.setInteger("SwingCnt", 0);
nbt.setBoolean("Yuuyo", false);
}
if (nbt.getBoolean("Zanzou")) {
EntityPlayer player = (EntityPlayer) entity;
//player.swingItem();//なぐれない
System.out.println("残像");
//ここにダメージを入れたい
}
}
}
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
if(!world.isRemote)
{
//NBTタグを取得します。
NBTTagCompound nbt = itemStack.getTagCompound();
if(nbt == null)
{
nbt = new NBTTagCompound();
itemStack.setTagCompound(nbt);
}
nbt.setBoolean("Zanzou", false);
System.out.println("残像false");
if (nbt.getBoolean("Yuuyo")) {
nbt.setBoolean("Zanzou", true);
System.out.println("残像true");
} else {
nbt.setInteger("SwingCnt", 0);
nbt.setBoolean("Yuuyo", false);
System.out.println("猶予じゃない");
}
}
return itemStack;
}
}
元ネタは、ゼルダの伝説時のオカリナ/ムジュラの仮面のバグ技 残像剣。
盾突きをした後にAボタンアクションをすると剣のダメージが連続で出続ける、というもの。
盾突きをした後にAボタンアクションをすると剣のダメージが連続で出続ける、というもの。