org.bukkit.block.Block.isEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.bukkit.block.Block.isEmpty()方法的一些代码示例,展示了Block.isEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.isEmpty()方法的具体详情如下:
包路径:org.bukkit.block.Block
类名称:Block
方法名:isEmpty

Block.isEmpty介绍

[英]Checks if this block is empty.

A block is considered empty when #getType() returns Material#AIR.
[中]检查此块是否为空。
当#getType()返回Material#AIR时,块被视为空。

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public Location getFixedSpawnLocation(World world, Random random) {
  while (true) {
    int x = random.nextInt(128) - 64;
    int y = 128 * 3 / 4;
    int z = random.nextInt(128) - 64;
    if (world.getBlockAt(x, y, z).isEmpty()) {
      while (world.getBlockAt(x, y - 1, z).isEmpty() && y > 0) {
        y--;
      }
      return new Location(world, x, y, z);
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public boolean canSpawn(World world, int x, int z) {
  Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
  return !block.isLiquid() && !block.isEmpty() && !noSpawnFloors.contains(block.getType());
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  public void decorate(World world, Random random, Chunk source) {
    if (random.nextInt(type == Material.STATIONARY_WATER ? 4 : 8) == 0) {
      int sourceX = (source.getX() << 4) + random.nextInt(16);
      int sourceZ = (source.getZ() << 4) + random.nextInt(16);
      int sourceY = random
        .nextInt(type == Material.STATIONARY_WATER ? 256 : random.nextInt(248) + 8);
      if (type == Material.STATIONARY_LAVA && (sourceY >= world.getSeaLevel()
        || random.nextInt(10) > 0)) {
        return;
      }
      while (world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() && sourceY > 5) {
        sourceY--;
      }
      if (sourceY >= 5) {
        new Lake(type).generate(world, random, sourceX, sourceY, sourceZ);
      }
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    Block thisBlock;
    do {
      thisBlock = world.getBlockAt(sourceX, sourceY, sourceZ);
      sourceY--;
    } while ((thisBlock.isEmpty() || thisBlock.getType() == Material.LEAVES) && sourceY > 0);
    sourceY++;
    boolean succeeded = false;
    for (int i = 0; i < 128; i++) {
      int x = sourceX + random.nextInt(8) - random.nextInt(8);
      int z = sourceZ + random.nextInt(8) - random.nextInt(8);
      int y = sourceY + random.nextInt(4) - random.nextInt(4);

      Block block = world.getBlockAt(x, y, z);
      Material blockTypeBelow = block.getRelative(BlockFace.DOWN).getType();
      if (y < 255 && block.getType() == Material.AIR && (
          blockTypeBelow == Material.GRASS || blockTypeBelow == Material.DIRT)) {
        BlockState state = block.getState();
        state.setType(Material.LONG_GRASS);
        state.setData(grassType);
        state.update(true);
        succeeded = true;
      }
    }
    return succeeded;
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
while (sourceY > 0
    && (world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()
    || world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEAVES)) {
  sourceY--;
  int y = sourceY + random.nextInt(4) - random.nextInt(4);
  if (world.getBlockAt(x, y, z).isEmpty()) {
    Block blockBelow = world.getBlockAt(x, y - 1, z);
    for (Material soil : SOIL_TYPES) {

代码示例来源:origin: GlowstoneMC/Glowstone

sourceY--;
  Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
  if (block.isEmpty()) {
    continue;
if (!groundReached || !world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
  return false;

代码示例来源:origin: GlowstoneMC/Glowstone

if (!block.isEmpty()
    || block.getRelative(BlockFace.UP).getType() != Material.NETHERRACK) {
  continue;
  int y = sourceY - random.nextInt(12);
  block = world.getBlockAt(x, y, z);
  if (!block.isEmpty()) {
    continue;

代码示例来源:origin: GlowstoneMC/Glowstone

if (y < 255 && block.isEmpty() && topBlock.isEmpty()
    && block.getRelative(BlockFace.DOWN).getType() == Material.GRASS) {
  BlockState state = block.getState();

代码示例来源:origin: GlowstoneMC/Glowstone

int z = sourceZ + random.nextInt(16);
int y = world.getHighestBlockYAt(x, z) - 1;
while (y > 2 && world.getBlockAt(x, y, z).isEmpty()) {
  y--;
int z = sourceZ + random.nextInt(16);
int y = world.getHighestBlockYAt(x, z);
while (y > 2 && world.getBlockAt(x, y, z).isEmpty()) {
  y--;

代码示例来源:origin: GlowstoneMC/Glowstone

if ((block.getType() != Material.NETHERRACK && !block.isEmpty())
    || block.getRelative(BlockFace.UP).getType() != Material.NETHERRACK) {
  return;
  if (neighbor.getType() == Material.NETHERRACK) {
    netherrackBlockCount++;
  } else if (neighbor.isEmpty()) {
    airBlockCount++;

代码示例来源:origin: GlowstoneMC/Glowstone

/**
   * Generates or extends a cactus, if there is space.
   */
  @Override
  public boolean generate(World world, Random random, int x, int y, int z) {
    if (world.getBlockAt(x, y, z).isEmpty()) {
      int height = random.nextInt(random.nextInt(3) + 1) + 1;
      for (int n = y; n < y + height; n++) {
        Block block = world.getBlockAt(x, n, z);
        Material typeBelow = block.getRelative(BlockFace.DOWN).getType();
        if ((typeBelow == Material.SAND || typeBelow == Material.CACTUS)
            && block.getRelative(BlockFace.UP).isEmpty()) {
          for (BlockFace face : FACES) {
            if (block.getRelative(face).getType().isSolid()) {
              return n > y;
            }
          }
          BlockState state = block.getState();
          state.setType(Material.CACTUS);
          state.setData(new MaterialData(Material.CACTUS));
          state.update(true);
        }
      }
    }
    return true;
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

private void placeBoat(GlowPlayer player, ItemStack holding) {
  Block targetBlock = player.getTargetBlock((Set<Material>) null, 5);
  if (targetBlock != null && !targetBlock.isEmpty()
      && targetBlock.getRelative(BlockFace.UP).isEmpty()) {
    Location location = targetBlock.getRelative(BlockFace.UP).getLocation();
    // center boat on cursor location
    location.add(0.6875f, 0, 0.6875f);
    location.setYaw(player.getLocation().getYaw());
    Boat boat = targetBlock.getWorld().spawn(location, Boat.class);
    boat.setWoodType(woodType);
    if (player.getGameMode() != GameMode.CREATIVE) {
      player.getInventory().removeItem(holding);
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
  if (!world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()
      || world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType()
          != Material.ENDER_STONE) {

代码示例来源:origin: GlowstoneMC/Glowstone

int airBlockCount = 0;
for (BlockFace face : SIDES) {
  if (block.getRelative(face).isEmpty()) {
    airBlockCount++;

代码示例来源:origin: GlowstoneMC/Glowstone

private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ, World world) {
    for (int x = -2; x <= 2; x++) {
      for (int z = -2; z <= 2; z++) {
        if (Math.abs(x) == 2 && Math.abs(z) == 2) {
          continue;
        }
        for (int y = 2; y >= -3; y--) {
          Block block = world
            .getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
          if (block.getType() == Material.GRASS || block.getType() == Material.DIRT) {
            BlockState state = block.getState();
            state.setType(Material.DIRT);
            DirtType dirtType = DirtType.PODZOL;
            if (world.getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z)
              .getType().isOccluding()) {
              dirtType = DirtType.NORMAL;
            }
            state.setData(new Dirt(dirtType));
            state.update(true);
          } else if (!block.isEmpty() && sourceY + y < sourceY) {
            break;
          }
        }
      }
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public boolean generate(World world, Random random, int x, int y, int z) {
  if (!world.getBlockAt(x, y, z).isEmpty()) {
    return false;
      || block.getType() == Material.SAND) {
      Block caneBlock = block.getRelative(BlockFace.UP);
      if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP)
        .isEmpty()) {
        return n > 0;

代码示例来源:origin: GlowstoneMC/Glowstone

protected void jump() {
  if (location.getBlock().isLiquid()) {
    // jump out more when you breach the surface of the liquid
    if (location.getBlock().getRelative(BlockFace.UP).isEmpty()) {
      velocity.setY(velocity.getY() + 0.3);
    }
    // less jumping in liquid
    velocity.setY(velocity.getY() + 0.04);
  } else {
    // jump normally
    velocity.setY(velocity.getY() + 0.42);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

while (blockY > 0) {
  Block current = world.getBlockAt(loc.getBlockX(), blockY, loc.getBlockZ());
  if (current.isEmpty() && current.getRelative(BlockFace.UP).isEmpty()) {
    hadSpace = true;
  } else if (hadSpace) {

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  public void handle(GlowSession session, PlayerSwingArmMessage message) {
    GlowPlayer player = session.getPlayer();
    EventFactory eventFactory = EventFactory.getInstance();
    Block block = player.getTargetBlock((Set<Material>) null, 6);

    if (block == null || block.isEmpty()) {
      if (eventFactory.onPlayerInteract(
          player, Action.LEFT_CLICK_AIR, message.getHandSlot()).useItemInHand()
          == Result.DENY) {
        return;
      }
      // todo: item interactions with air
    }

    if (!eventFactory.callEvent(new PlayerAnimationEvent(player)).isCancelled()) {
      // play the animation to others
      player.playAnimation(message.getHand() == 1 ? EntityAnimation.SWING_OFF_HAND
          : EntityAnimation.SWING_MAIN_HAND);
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

break;
} else if (!target.isEmpty()) {
  break;

相关文章