【マイクラ】summon して fireball を投げる

コマンド の summon で fireball を召喚して投げられることがわかった。


summon fireball ~ ~ ~ {ExplosionPower:4,Motion:[0.0,0.0,3.0]}

Motion で、投げる方向の設定ができるが、その値の求め方がイマイチわからない。

とりあえず、X軸、Y軸、Z軸、それぞれの 始点(自プレーヤーの位置)から終点(ターゲットのブロック位置)までのベクトルを求めてみた。

public Vector getMotion(Block b,Player p){

    int sx = p.getLocation().getBlockX();
    int sy = p.getLocation().getBlockY();
    int sz = p.getLocation().getBlockZ();

    int ex = b.getLocation().getBlockX();
    int ey = b.getLocation().getBlockY();
    int ez = b.getLocation().getBlockZ();

    double mx = ex - sx;
    double my = ey - sy;
    double mz = ez - sz;

    int max = maximum((int)(Math.abs(mx)),(int)Math.abs(my),(int)Math.abs(mz));

    if(mx != 0 && m != 0) mx = mx / max;
    if(my != 0 && m != 0) my = my / max;
    if(mz != 0 && m != 0) mz = mz / max;

    if(mx != 0) mx = mx * 3;
    if(my != 0) my = my * 3;
    if(mz != 0) mz = mz * 3;

    Vector v = new Vector();
    v.setX(mx);
    v.setY(my);
    v.setZ(mz);

    return v;
}

public int maximum( int a, int b, int c )
{
    int ans;
    ans = a;
    if ( ans < b ) ans = b;
    if ( ans < c ) ans = c;
    return ans;
}

しかし、Motion の 値が10を超えるとスピードが速すぎて見えなくなるので、

3つの軸の中で、一番大きい軸をベースにして、その値が最大で 3.0 になるようにした。

他の2軸は 3.0以下になるということ。

使い方はこちら。

Vector v = getMotion(targetBlock,targetPlayer);
cmd("summon fireball ~ ~ ~ {ExplosionPower:4,Motion:[" + v.getX() + "," + v.getY() + "," + v.getZ() + "]}");