您好,我正在开发一个基于 minecraft 源代码的 minecraft 机器人,我需要编写一个 fly to block 方法……但是我的方法似乎有故障,我不知道为什么。我错过了什么吗?(抱歉命名含糊,Local表示它是函数的局部值,局部向量实际上存储在数组中)
private void flyTo(int x, int y, int z,double posX,double posY,double posZ) {
double xLocal = posX;
double yLocal = posY;
double zLocal = posZ;
while(xLocal!=x &&yLocal!=y&&zLocal!=z){
double[] v = new double[3];
v[0] = x-xLocal;
v[1] = y-yLocal;
v[2] = z-zLocal;
double magxz = Math.sqrt(Math.pow(v[0], 2)+Math.pow(v[2], 2));
if(magxz>0.6D){
double scaler = 0.6D/magxz;
v[0] *= scaler;
v[2] *= scaler;
}
if(Math.abs(v[1])>1){
if(v[1]>0){
v[1]=1;
}else{
v[1]=-1;
}
}
xLocal+=v[0];
yLocal+=v[1];
zLocal+=v[2];
mc.getSendQueue().addToSendQueue(new Packet11PlayerPosition((double)xLocal,(double)yLocal,yLocal+0.83,(double)zLocal,false));
mc.getSendQueue().processReadPackets();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}