congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
World.getBlockAt
Code IndexAdd Tabnine to your IDE (free)

How to use
getBlockAt
method
in
org.bukkit.World

Best Java code snippets using org.bukkit.World.getBlockAt (Showing top 20 results out of 324)

origin: Bukkit/Bukkit

/**
 * Gets the block at the represented location
 *
 * @return Block at the represented location
 */
public Block getBlock() {
  return world.getBlockAt(this);
}
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

/**
 * Sets a block type and add it to the BlockState list.
 *
 * @param world the world which contains the block
 * @param x the x-coordinate of this block
 * @param y the y-coordinate of this block
 * @param z the z-coordinate of this block
 * @param type the new type of this block
 */
public void setType(World world, int x, int y, int z, Material type) {
  GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
  state.setType(type);
  blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
origin: GlowstoneMC/Glowstone

  @Override
  public void populate(World world, Random random, Chunk chunk) {
    int sourceX = chunk.getX() << 4;
    int sourceZ = chunk.getZ() << 4;

    for (int i = 0; i < random.nextInt(6) + 3; i++) {
      int x = sourceX + random.nextInt(16);
      int z = sourceZ + random.nextInt(16);
      int y = random.nextInt(28) + 4;

      if (world.getBlockAt(x, y, z).getType() == Material.STONE) {
        world.getBlockAt(x, y, z).setType(Material.EMERALD_ORE);
      }
    }
  }
}
origin: GlowstoneMC/Glowstone

/**
 * Sets a block type, data and add it to the BlockState list.
 *
 * @param world the world which contains the block
 * @param x the x-coordinate of this block
 * @param y the y-coordinate of this block
 * @param z the z-coordinate of this block
 * @param type the new type of this block
 * @param data the new data value of this block
 */
public void setTypeAndRawData(World world, int x, int y, int z, Material type, int data) {
  GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
  state.setType(type);
  state.setRawData((byte) data);
  blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
origin: GlowstoneMC/Glowstone

/**
 * Sets a block type and MaterialData, and add it to the BlockState list.
 *
 * @param world the world which contains the block
 * @param x the x-coordinate of this block
 * @param y the y-coordinate of this block
 * @param z the z-coordinate of this block
 * @param type the new type of this block
 * @param data the new MaterialData of this block
 */
public void setTypeAndData(World world, int x, int y, int z, Material type, MaterialData data) {
  GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
  state.setType(type);
  state.setData(data);
  blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
origin: GlowstoneMC/Glowstone

/**
 * Returns the {@link BlockState} of a block at the given coordinates.
 *
 * @param world the world which contains the block
 * @param x the x-coordinate
 * @param y the y-coordinate
 * @param z the z-coordinate
 * @return The {@link BlockState} state.
 */
public BlockState getBlockState(World world, int x, int y, int z) {
  Location loc = world.getBlockAt(x, y, z).getLocation();
  if (blockStateMap.containsKey(loc)) {
    return blockStateMap.get(loc);
  } else {
    return loc.getBlock().getState();
  }
}
origin: GlowstoneMC/Glowstone

  @Override
  public void populate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = random.nextInt(world.getSeaLevel() << 1);

    for (int i = 0; i < 64; 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);

      if (world.getBlockAt(x, y, z).getType() == Material.AIR
          && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) {
        BlockState state = world.getBlockAt(x, y, z).getState();
        state.setType(Material.MELON_BLOCK);
        state.setData(new MaterialData(Material.MELON_BLOCK));
        state.update(true);
      }
    }
  }
}
origin: GlowstoneMC/Glowstone

  @Override
  public void decorate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = random.nextInt(128);

    for (int i = 0; i < 64; 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);
      Block blockBelow = world.getBlockAt(x, y - 1, z);
      if (y < 128 && block.getType() == Material.AIR && Arrays.asList(MATERIALS)
        .contains(blockBelow.getType())) {
        BlockState state = block.getState();
        state.setType(type);
        state.setData(new MaterialData(type));
        state.update(true);
      }
    }
  }
}
origin: GlowstoneMC/Glowstone

  @Override
  public void decorate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = world.getHighestBlockYAt(sourceX, sourceZ) - 1;
    while (
      world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.STATIONARY_WATER
        ||
        world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.WATER
          && sourceY > 1) {
      sourceY--;
    }
    Material material = world.getBlockAt(sourceX, sourceY, sourceZ).getType();
    if (material == Material.STATIONARY_WATER || material == Material.WATER) {
      new BlockPatch(type, horizRadius, vertRadius, overridables)
        .generate(world, random, sourceX, sourceY, sourceZ);
    }
  }
}
origin: GlowstoneMC/Glowstone

/**
 * Returns whether any of {@link #canHeightFit(int)}, {@link #canPlace(int, int, int, World)} or
 * {@link #canPlaceOn(BlockState)} prevent this tree from generating.
 *
 * @param baseX the X coordinate of the base of the trunk
 * @param baseY the Y coordinate of the base of the trunk
 * @param baseZ the Z coordinate of the base of the trunk
 * @param world the world to grow in
 * @return true if any of the checks prevent us from generating, false otherwise
 */
protected boolean cannotGenerateAt(int baseX, int baseY, int baseZ,
    World world) {
  return !canHeightFit(baseY)
      || !canPlaceOn(world.getBlockAt(baseX, baseY - 1, baseZ).getState())
      || !canPlace(baseX, baseY, baseZ, world);
}
origin: EngineHub/WorldEdit

@Override
public int getBlockLightLevel(BlockVector3 pt) {
  return getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel();
}
origin: EngineHub/WorldEdit

@Override
public void simulateBlockMine(BlockVector3 pt) {
  getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();
}
origin: EngineHub/WorldEdit

@Override
public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) {
  Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
  return BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
origin: GlowstoneMC/Glowstone

  @Override
  public void populateOnGround(World world, Random random, Chunk chunk) {

    int sourceX = chunk.getX() << 4;
    int sourceZ = chunk.getZ() << 4;

    for (int i = 0; i < 7; i++) {
      int x = sourceX + random.nextInt(16);
      int z = sourceZ + random.nextInt(16);
      int y = world.getHighestBlockYAt(x, z);
      Block sourceBlock = world.getBlockAt(x, y, z);
      BlockStateDelegate delegate = new BlockStateDelegate();
      JungleBush bush = new JungleBush(random, delegate);
      if (bush.generate(sourceBlock.getLocation())) {
        delegate.updateBlockStates();
      }
    }

    super.populateOnGround(world, random, chunk);
    melonDecorator.populate(world, random, chunk);
  }
}
origin: Bukkit/Bukkit

/**
 * Tests if the specified location is valid for a natural spawn position
 *
 * @param world The world we're testing on
 * @param x X-coordinate of the block to test
 * @param z Z-coordinate of the block to test
 * @return true if the location is valid, otherwise false
 */
public boolean canSpawn(World world, int x, int z) {
  Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z);
  switch (world.getEnvironment()) {
  case NETHER:
    return true;
  case THE_END:
    return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA;
  case NORMAL:
  default:
    return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL;
  }
}
origin: EngineHub/WorldEdit

@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
  BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
  if (adapter != null) {
    try {
      return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
    } catch (Exception e) {
      if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) {
        logger.warning("Tried to set a corrupt tile entity at " + position.toString());
        logger.warning(((BaseBlock) block).getNbtData().toString());
      }
      e.printStackTrace();
      Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
      bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight);
      return true;
    }
  } else {
    Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight);
    return true;
  }
}
origin: EngineHub/WorldEdit

@Override
public boolean clearContainerBlockContents(BlockVector3 pt) {
  Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
  if (block == null) {
    return false;
  }
  BlockState state = block.getState();
  if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
    return false;
  }
  org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
  Inventory inven = chest.getInventory();
  if (chest instanceof Chest) {
    inven = getBlockInventory((Chest) chest);
  }
  inven.clear();
  return true;
}
origin: GlowstoneMC/Glowstone

/**
 * Builds a 1x1 column out of the given block, replacing non-solid blocks starting at a given
 * location and proceeding downward until a solid block is reached.
 *
 * @param pos the highest point to possibly replace, relative to this structure's root
 *         point
 * @param type the block type to fill
 * @param data the block data
 */
public void setBlockDownward(Vector pos, Material type, int data) {
  Vector vec = translate(pos);
  if (boundingBox.isVectorInside(vec)) {
    int y = vec.getBlockY();
    while (!world.getBlockAt(vec.getBlockX(), y, vec.getBlockZ()).getType().isSolid()
        && y > 1) {
      delegate.setTypeAndRawData(world, vec.getBlockX(), y, vec.getBlockZ(), type, data);
      y--;
    }
  }
}
origin: EngineHub/WorldEdit

  @Override
  public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
    if (block == null) {
      player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
    } else {
      player.sendBlockChange(loc, BukkitAdapter.adapt(block));
      if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
        BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
        if (adapter != null) {
          adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData());
          if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) {
            adapter.sendFakeOP(player);
          }
        }
      }
    }
  }
}
org.bukkitWorldgetBlockAt

Javadoc

Gets the Block at the given coordinates

Popular methods of World

  • getName
  • getChunkAt
    Gets the Chunk that contains the given Block
  • getPlayers
  • getMaxHeight
    Gets the maximum height of this world. If the max height is 100, there are only blocks from y=0 to y
  • getSpawnLocation
    Gets the default spawn Location of this world
  • spawnEntity
  • getEntities
  • getEnvironment
    Gets the Environment type of this world
  • isChunkLoaded
    Checks if the specified Chunk is loaded
  • dropItemNaturally
  • dropItem
  • playEffect
    Plays an effect to all players within a given radius around a location.
  • dropItem,
  • playEffect,
  • getNearbyEntities,
  • getUID,
  • playSound,
  • getTime,
  • setStorm,
  • setThundering,
  • setTime

Popular in Java

  • Creating JSON documents from java classes using gson
  • findViewById (Activity)
  • setScale (BigDecimal)
  • compareTo (BigDecimal)
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Path (java.nio.file)
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now