org.bukkit.Chunk.getBlock()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(109)

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

Chunk.getBlock介绍

[英]Gets a block from this chunk
[中]从该块中获取块

代码示例

代码示例来源:origin: echurchill/CityWorld

@Override
public Block getActualBlock(int x, int y, int z) {
  return chunk.getBlock(x, y, z);
}

代码示例来源:origin: CitizensDev/CitizensAPI

@Override
  protected Material getType(Chunk chunk, int x, int y, int z) {
    return chunk.getBlock(x, y, z).getType();
  }
}

代码示例来源:origin: CitizensDev/CitizensAPI

@Override
protected int getLightLevel(Chunk chunk, int x, int y, int z) {
  return chunk.getBlock(x, y, z).getLightLevel();
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

public static int generateSupplies(OreGenResource resource, Chunk chunk) {
  if (resource == null) return 0;
  int supplies = getDefault(resource, chunk.getBlock(5, 50, 5).getBiome());
  BlockStorage.setChunkInfo(chunk, "resources_" + resource.getName().toUpperCase(), String.valueOf(supplies));
  return supplies;
}

代码示例来源:origin: nsporillo/GlobalWarming

@Override
  public void run() {
    try {
      HashSet<BlockChange> changes = results.get();
      for (BlockChange change : changes) {
        Block block = chunk.getBlock(change.getX(), change.getY(), change.getZ());
        //TODO: Add some more logic to ensure this works perfectly.
        // Currently works, but there might be edge cases not considered when written
        block.setType(change.getNewType(), true);
      }
    } catch (InterruptedException | ExecutionException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private int getChunkX(boolean min, Chunk c) {
  int cx = c.getX();
  int cz = c.getZ();
  if (min) {
    return c.getWorld().getChunkAt(cx - 4, cz).getBlock(0, 64, 0).getX();
  } else {
    return c.getWorld().getChunkAt(cx + 4, cz).getBlock(0, 64, 0).getX();
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private int getChunkZ(boolean min, Chunk c) {
  int cx = c.getX();
  int cz = c.getZ();
  if (min) {
    return c.getWorld().getChunkAt(cx, cz - 4).getBlock(0, 64, 0).getZ();
  } else {
    return c.getWorld().getChunkAt(cx, cz + 4).getBlock(0, 64, 0).getZ();
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private int getChunkX(int xx, Chunk c) {
  int cx = c.getX();
  int cz = c.getZ();
  switch (xx) {
    case 0:
      return c.getWorld().getChunkAt(cx - 4, cz).getBlock(0, 64, 0).getX();
    case 1:
      return c.getWorld().getChunkAt(cx - 3, cz).getBlock(0, 64, 0).getX();
    case 2:
      return c.getWorld().getChunkAt(cx - 2, cz).getBlock(0, 64, 0).getX();
    case 3:
      return c.getWorld().getChunkAt(cx - 1, cz).getBlock(0, 64, 0).getX();
    case 5:
      return c.getWorld().getChunkAt(cx + 1, cz).getBlock(0, 64, 0).getX();
    case 6:
      return c.getWorld().getChunkAt(cx + 2, cz).getBlock(0, 64, 0).getX();
    case 7:
      return c.getWorld().getChunkAt(cx + 3, cz).getBlock(0, 64, 0).getX();
    case 8:
      return c.getWorld().getChunkAt(cx + 4, cz).getBlock(0, 64, 0).getX();
    default:
      return c.getBlock(0, 64, 0).getX();
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private int getChunkZ(int zz, Chunk c) {
  int cx = c.getX();
  int cz = c.getZ();
  switch (zz) {
    case 0:
      return c.getWorld().getChunkAt(cz, cz - 4).getBlock(0, 64, 0).getZ();
    case 1:
      return c.getWorld().getChunkAt(cx, cz - 3).getBlock(0, 64, 0).getZ();
    case 2:
      return c.getWorld().getChunkAt(cx, cz - 2).getBlock(0, 64, 0).getZ();
    case 3:
      return c.getWorld().getChunkAt(cx, cz - 1).getBlock(0, 64, 0).getZ();
    case 5:
      return c.getWorld().getChunkAt(cx, cz + 1).getBlock(0, 64, 0).getZ();
    case 6:
      return c.getWorld().getChunkAt(cx, cz + 2).getBlock(0, 64, 0).getZ();
    case 7:
      return c.getWorld().getChunkAt(cx, cz + 3).getBlock(0, 64, 0).getZ();
    case 8:
      return c.getWorld().getChunkAt(cx, cz + 4).getBlock(0, 64, 0).getZ();
    default:
      return c.getBlock(0, 64, 0).getZ();
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private int getChunkZ(int zz, Chunk c) {
  int cx = c.getX();
  int cz = c.getZ();
  switch (zz) {
    case 0:
      return c.getWorld().getChunkAt(cx, cz - 4).getBlock(0, 64, 0).getZ();
    case 1:
      return c.getWorld().getChunkAt(cx, cz - 3).getBlock(0, 64, 0).getZ();
    case 2:
      return c.getWorld().getChunkAt(cx, cz - 2).getBlock(0, 64, 0).getZ();
    case 3:
      return c.getWorld().getChunkAt(cx, cz - 1).getBlock(0, 64, 0).getZ();
    case 5:
      return c.getWorld().getChunkAt(cx, cz + 1).getBlock(0, 64, 0).getZ();
    case 6:
      return c.getWorld().getChunkAt(cx, cz + 2).getBlock(0, 64, 0).getZ();
    case 7:
      return c.getWorld().getChunkAt(cx, cz + 3).getBlock(0, 64, 0).getZ();
    case 8:
      return c.getWorld().getChunkAt(cx, cz + 4).getBlock(0, 64, 0).getZ();
    default:
      return c.getBlock(0, 64, 0).getZ();
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

@EventHandler(ignoreCancelled = true)
public void onChunkPopulate(ChunkPopulateEvent event) {
  Chunk chunk = event.getChunk();
  // check world
  if (!chunk.getWorld().getName().equals("Gallifrey")) {
    return;
  }
  if (!chunk.getBlock(7, 63, 7).getBiome().toString().equals("GALLIFREY")) {
    return;
  }
  if (chunks.contains(chunk)) {
    return;
  }
  // scan chunk for STRUCTURE_BLOCK between y = 50 , 70
  for (int x = 0; x < 16; x++) {
    for (int z = 0; z < 16; z++) {
      for (int y = 50; y < 71; y++) {
        if (chunk.getBlock(x, y, z).getType().equals(Material.STRUCTURE_BLOCK)) {
          buildStructure(chunk, x, y, z);
          return;
        }
      }
    }
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private int getChunkX(int xx, Chunk c) {
  int cx = c.getX();
  int cz = c.getZ();
  switch (xx) {
    case 0:
      return c.getWorld().getChunkAt(cx - 4, cz).getBlock(0, 64, 0).getX();
    case 1:
      return c.getWorld().getChunkAt(cx - 3, cz).getBlock(0, 64, 0).getX();
    case 2:
      return c.getWorld().getChunkAt(cx - 2, cz).getBlock(0, 64, 0).getX();
    case 3:
      return c.getWorld().getChunkAt(cx - 1, cz).getBlock(0, 64, 0).getX();
    case 5:
      return c.getWorld().getChunkAt(cx + 1, cz).getBlock(0, 64, 0).getX();
    case 6:
      return c.getWorld().getChunkAt(cx + 2, cz).getBlock(0, 64, 0).getX();
    case 7:
      return c.getWorld().getChunkAt(cx + 3, cz).getBlock(0, 64, 0).getX();
    case 8:
      return c.getWorld().getChunkAt(cx + 4, cz).getBlock(0, 64, 0).getX();
    default:
      return c.getBlock(0, 64, 0).getX();
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

/**
 * Gets a start location for building the inner TARDIS.
 *
 * @param id the TARDIS this location belongs to.
 * @return an array of ints.
 */
public int[] getStartLocation(int id) {
  int[] startLoc = new int[4];
  int cx, cz;
  ResultSetTardisChunk rs = new ResultSetTardisChunk(plugin);
  if (rs.fromID(id)) {
    String chunkstr = rs.getChunk();
    String[] split = chunkstr.split(":");
    World w = plugin.getServer().getWorld(split[0]);
    cx = TARDISNumberParsers.parseInt(split[1]);
    cz = TARDISNumberParsers.parseInt(split[2]);
    Chunk chunk = w.getChunkAt(cx, cz);
    startLoc[0] = (chunk.getBlock(0, 64, 0).getX());
    startLoc[1] = startLoc[0];
    startLoc[2] = (chunk.getBlock(0, 64, 0).getZ());
    startLoc[3] = startLoc[2];
  }
  return startLoc;
}

代码示例来源:origin: eccentricdevotion/TARDIS

private void buildStructure(Chunk chunk, int x, int y, int z) {
    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
      chunks.add(chunk);
      // remove STRUCTURE_BLOCK so we don't get this chunk again
      Block structure = chunk.getBlock(x, y, z);
      structure.setBlockData(Material.RED_SAND.createBlockData());
      // create structure
      new TARDISBuildGallifreyanStructure(plugin).buildCity(chunk.getX() * 16 + x, y, chunk.getZ() * 16 + z);
    }, 1L);
  }
}

代码示例来源:origin: MylesIsCool/ViaVersion

@Override
public int getWorldBlockData(UserConnection user, Position position) {
  UUID uuid = user.get(ProtocolInfo.class).getUuid();
  Player player = Bukkit.getPlayer(uuid);
  if (player != null) {
    World world = player.getWorld();
    int x = (int) (position.getX() >> 4);
    int z = (int) (position.getZ() >> 4);
    if (world.isChunkLoaded(x, z)) {
      Chunk c = getChunk(world, x, z);
      Block b = c.getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue());
      return b.getTypeId() << 4 | b.getData();
    }
  }
  return 0;
}

代码示例来源:origin: BigScary/GriefPrevention

Set<Claim> getNearbyClaims(Location location)
{
  Set<Claim> claims = new HashSet<Claim>();
  
  Chunk lesserChunk = location.getWorld().getChunkAt(location.subtract(150, 0, 150));
  Chunk greaterChunk = location.getWorld().getChunkAt(location.add(300, 0, 300));
  
  for(int chunk_x = lesserChunk.getX(); chunk_x <= greaterChunk.getX(); chunk_x++)
  {
    for(int chunk_z = lesserChunk.getZ(); chunk_z <= greaterChunk.getZ(); chunk_z++)
    {
      Chunk chunk = location.getWorld().getChunkAt(chunk_x, chunk_z);
      Long chunkID = getChunkHash(chunk.getBlock(0,  0,  0).getLocation());
      ArrayList<Claim> claimsInChunk = this.chunksToClaimsMap.get(chunkID);
      if(claimsInChunk != null)
      {
        for(Claim claim : claimsInChunk)
        {
          if(claim.inDataStore && claim.getLesserBoundaryCorner().getWorld().equals(location.getWorld()))
          {
            claims.add(claim);
          }
        }
      }
    }
  }
  
  return claims;
}

代码示例来源:origin: eccentricdevotion/TARDIS

public void reclaimZeroChunk(World w, TARDISTIPSData data) {
    // get starting chunk
    Location l = new Location(w, data.getMinX(), 0, data.getMinZ());
    Chunk chunk = w.getChunkAt(l);
    Block block = chunk.getBlock(0, 0, 0);
    int sx = block.getX();
    int sz = block.getZ();
    for (int y = 64; y < 80; y++) {
      for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
          int cx = sx + x;
          int cz = sz + z;
          w.getBlockAt(cx, y, cz).setBlockData(TARDISConstants.AIR);
        }
      }
    }
  }
}

代码示例来源:origin: BigScary/GriefPrevention

@SuppressWarnings("deprecation")
public void restoreChunk(Chunk chunk, int miny, boolean aggressiveMode, long delayInTicks, Player playerReceivingVisualization)
{
  //build a snapshot of this chunk, including 1 block boundary outside of the chunk all the way around
  int maxHeight = chunk.getWorld().getMaxHeight();
  BlockSnapshot[][][] snapshots = new BlockSnapshot[18][maxHeight][18];
  Block startBlock = chunk.getBlock(0, 0, 0);
  Location startLocation = new Location(chunk.getWorld(), startBlock.getX() - 1, 0, startBlock.getZ() - 1);
  for(int x = 0; x < snapshots.length; x++)
  {
    for(int z = 0; z < snapshots[0][0].length; z++)
    {
      for(int y = 0; y < snapshots[0].length; y++)
      {
        Block block = chunk.getWorld().getBlockAt(startLocation.getBlockX() + x, startLocation.getBlockY() + y, startLocation.getBlockZ() + z);
        snapshots[x][y][z] = new BlockSnapshot(block.getLocation(), block.getTypeId(), block.getData());
      }
    }
  }
  
  //create task to process those data in another thread
  Location lesserBoundaryCorner = chunk.getBlock(0,  0, 0).getLocation();
  Location greaterBoundaryCorner = chunk.getBlock(15, 0, 15).getLocation();
  
  //create task
  //when done processing, this task will create a main thread task to actually update the world with processing results
  RestoreNatureProcessingTask task = new RestoreNatureProcessingTask(snapshots, miny, chunk.getWorld().getEnvironment(), lesserBoundaryCorner.getBlock().getBiome(), lesserBoundaryCorner, greaterBoundaryCorner, this.getSeaLevel(chunk.getWorld()), aggressiveMode, GriefPrevention.instance.creativeRulesApply(lesserBoundaryCorner), playerReceivingVisualization);
  GriefPrevention.instance.getServer().getScheduler().runTaskLaterAsynchronously(GriefPrevention.instance, task, delayInTicks);
}

代码示例来源:origin: BentoBoxWorld/BentoBox

@SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  public void onChunkLoad(ChunkLoadEvent e) {
    if (!ready) {
      return;
    }
    BentoBox plugin = BentoBox.getInstance();
    World world = e.getWorld();
    if (!e.getChunk().getBlock(0, 0, 0).getType().equals(Material.BEDROCK)
        || !Flags.CLEAN_SUPER_FLAT.isSetForWorld(world)
        || (world.getEnvironment().equals(Environment.NETHER) && (!plugin.getIWM().isNetherGenerate(world) || !plugin.getIWM().isNetherIslands(world)))
        || (world.getEnvironment().equals(Environment.THE_END) && (!plugin.getIWM().isEndGenerate(world) || !plugin.getIWM().isEndIslands(world)))) {
      return;
    }
    // Add to queue
    chunkQueue.add(new Pair<>(e.getChunk().getX(), e.getChunk().getZ()));
    if (task == null) {
      task = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
        if (!chunkQueue.isEmpty()) {
          Pair<Integer, Integer> chunkXZ = chunkQueue.poll();
          world.regenerateChunk(chunkXZ.x, chunkXZ.z); // NOSONAR - the deprecation doesn't cause any issues to us
          if (plugin.getSettings().isLogCleanSuperFlatChunks()) {
            plugin.log(chunkQueue.size() + " Regenerating superflat chunk " + world.getName() + " " + chunkXZ.x + ", " + chunkXZ.z);
          }
        }
      }, 0L, 1L);
    }
  }
}

代码示例来源:origin: nsporillo/GlobalWarming

Block block = world.getChunkAt(snapshot.getX(), snapshot.getZ()).getBlock(x, y, z);
if (block.getType() == Material.AIR) {
  if (deltaSeaLevel > 0 && y <= customSeaLevel && !isOverride) {

相关文章