Java 以Bukkit中的玩家方向获取相对于区块和相对区块的区块 以Bukkit中的玩家方向获取相对于区块和相对区块的区块

Java 以Bukkit中的玩家方向获取相对于区块和相对区块的区块 以Bukkit中的玩家方向获取相对于区块和相对区块的区块,java,minecraft,bukkit,Java,Minecraft,Bukkit,你好,我正在为一个Bukkit问题挣扎。 所以,基本上,我是想让这个街区在另一个街区的右边。但我想让球员们看到,在任何方向上,另一个右边的方块也在球员的右边。我的意思是我想让玩家看到第一个区块左边的区块,但是从玩家那里,而不是从服务器技术位置系统 由于图像比文本解释得更好,以下是一些图像: 只是一个普通街区 结果I除外:一个新的方块被排除在玩家看到的正常方块右侧 一种方法是获得玩家面对的方向(使用玩家的偏航),然后使用该方向获得正确的方块面: Player p; Block b; Locat

你好,我正在为一个Bukkit问题挣扎。 所以,基本上,我是想让这个街区在另一个街区的右边。但我想让球员们看到,在任何方向上,另一个右边的方块也在球员的右边。我的意思是我想让玩家看到第一个区块左边的区块,但是从玩家那里,而不是从服务器技术位置系统

由于图像比文本解释得更好,以下是一些图像:

只是一个普通街区

结果I除外:一个新的方块被排除在玩家看到的正常方块右侧

一种方法是获得玩家面对的方向(使用玩家的
偏航
),然后使用该方向获得正确的方块面:

Player p;
Block b;

Location l = p.getLocation();
float yaw = l.getYaw();

// Make sure yaw is in the range 0 to 360
while(yaw < 0){yaw+=360;}
yaw = yaw % 360;

// The player's yaw is their rotation in the world,
// so, we can use that to get the right face of a block!
BlockFace rightFace;

// if the player is facing SE to SW
if(yaw < 45 || yaw >= 315){
    rightFace = BlockFace.EAST;
}

// if the player is facing SW to NW
else if(yaw < 135){
    rightFace = BlockFace.SOUTH;
}

// if the player is facing NW to NE
else if(yaw < 225){
    rightFace = BlockFace.WEST;
}

// if the player is facing NE to SE
else if(yaw < 315){
    rightFace = BlockFace.NORTH;
}
您也可以使用类似于此的代码来获取相对于播放器的块的前面、后面或左边的块-只需将您设置的
rightFace
更改为上面的值即可


我还没有机会测试这个,但它应该可以工作

一种方法是获得玩家面对的方向(使用玩家的
偏航
),然后使用该方向获得正确的方块面:

Player p;
Block b;

Location l = p.getLocation();
float yaw = l.getYaw();

// Make sure yaw is in the range 0 to 360
while(yaw < 0){yaw+=360;}
yaw = yaw % 360;

// The player's yaw is their rotation in the world,
// so, we can use that to get the right face of a block!
BlockFace rightFace;

// if the player is facing SE to SW
if(yaw < 45 || yaw >= 315){
    rightFace = BlockFace.EAST;
}

// if the player is facing SW to NW
else if(yaw < 135){
    rightFace = BlockFace.SOUTH;
}

// if the player is facing NW to NE
else if(yaw < 225){
    rightFace = BlockFace.WEST;
}

// if the player is facing NE to SE
else if(yaw < 315){
    rightFace = BlockFace.NORTH;
}
您也可以使用类似于此的代码来获取相对于播放器的块的前面、后面或左边的块-只需将您设置的
rightFace
更改为上面的值即可

我还没有机会测试这个,但它应该可以工作