下面列出了org.bukkit.block.BlockFace#getModX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected int process(User user, BlockPlaceEvent event)
{
final BlockFace placedFace = event.getBlock().getFace(event.getBlockAgainst());
final Vector placedVector = new Vector(placedFace.getModX(), placedFace.getModY(), placedFace.getModZ());
// If greater than 90
if (user.getPlayer().getLocation().getDirection().angle(placedVector) > MAX_ANGLE) {
if (++user.getScaffoldData().angleFails >= this.violationThreshold) {
message = "Scaffold-Verbose | Player: " + user.getPlayer().getName() + " placed a block with a suspicious angle.";
return 3;
}
}
else if (user.getScaffoldData().angleFails > 0) {
user.getScaffoldData().angleFails--;
}
return 0;
}
public static Vector getDirection(BlockFace face) {
int modX = face.getModX();
int modY = face.getModY();
int modZ = face.getModZ();
Vector direction = new Vector(modX, modY, modZ);
if (modX != 0 || modY != 0 || modZ != 0) {
direction.normalize();
}
return direction;
}
public static Vector getDirection(BlockFace face) {
int modX = face.getModX();
int modY = face.getModY();
int modZ = face.getModZ();
Vector direction = new Vector(modX, modY, modZ);
if (modX != 0 || modY != 0 || modZ != 0) {
direction.normalize();
}
return direction;
}
@EventHandler
public void onLiquidPlacePickup(PlayerBucketEmptyEvent e) {
if (e != null) {
BlockFace bf = e.getBlockFace();
Vector v = new Vector(bf.getModX(), bf.getModY(), bf.getModZ());
ChunkEventHelper.handleBlockEvent(e.getPlayer(), e.getBlockClicked().getLocation().add(v).getChunk(), e);
}
}
@EventHandler
public void onLiquidPlacePickup(PlayerBucketFillEvent e) {
if (e != null) {
BlockFace bf = e.getBlockFace();
Vector v = new Vector(bf.getModX(), bf.getModY(), bf.getModZ());
ChunkEventHelper.handleBlockEvent(e.getPlayer(), e.getBlockClicked().getLocation().add(v).getChunk(), e);
}
}
public BlockFace getFace(final Block block) {
BlockFace[] values = BlockFace.values();
for (BlockFace face : values) {
if ((this.getX() + face.getModX() == block.getX()) &&
(this.getY() + face.getModY() == block.getY()) &&
(this.getZ() + face.getModZ() == block.getZ())
) {
return face;
}
}
return null;
}
@Override
public BlockFace getFace(Block block) {
BlockFace[] directions = BlockFace.values();
for(int i = 0; i < directions.length; ++i) {
BlockFace face = directions[i];
if(this.getX() + face.getModX() == block.getX() && this.getY() + face.getModY() == block.getY() && this.getZ() + face.getModZ() == block.getZ()) {
return face;
}
}
return null;
}
static BlockVector getRelative(BlockVector pos, BlockFace face) {
return new BlockVector(
pos.getBlockX() + face.getModX(),
pos.getBlockY() + face.getModY(),
pos.getBlockZ() + face.getModZ());
}
public static BlockVector getRelative(BlockVector pos, BlockFace face) {
return new BlockVector(pos.getBlockX() + face.getModX(),
pos.getBlockY() + face.getModY(),
pos.getBlockZ() + face.getModZ());
}
public void selectFrame(ItemFrame start) {
Location pos1 = start.getLocation().clone();
Location pos2 = start.getLocation().clone();
BlockFace facing = start.getFacing();
int planeX = facing.getModX() == 0 ? 1 : 0;
int planeY = facing.getModY() == 0 ? 1 : 0;
int planeZ = facing.getModZ() == 0 ? 1 : 0;
ItemFrame[][] res = find(pos1, pos2, facing);
Location tmp;
while (true) {
if (res != null) {
frames = res;
}
tmp = pos1.clone().subtract(planeX, planeY, planeZ);
if ((res = find(tmp, pos2, facing)) != null) {
pos1 = tmp;
continue;
}
tmp = pos2.clone().add(planeX, planeY, planeZ);
if ((res = find(pos1, tmp, facing)) != null) {
pos2 = tmp;
continue;
}
tmp = pos1.clone().subtract(planeX, 0, planeZ);
if ((res = find(tmp, pos2, facing)) != null) {
pos1 = tmp;
continue;
}
tmp = pos2.clone().add(planeX, 0, planeZ);
if ((res = find(pos1, tmp, facing)) != null) {
pos2 = tmp;
continue;
}
tmp = pos1.clone().subtract(0, 1, 0);
if ((res = find(tmp, pos2, facing)) != null) {
pos1 = tmp;
continue;
}
tmp = pos2.clone().add(0, 1, 0);
if ((res = find(pos1, tmp, facing)) != null) {
pos2 = tmp;
continue;
}
break;
}
}