net.minecraft.world.chunk.Chunk.getTopFilledSegment()方法的使用及代码示例

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

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

Chunk.getTopFilledSegment介绍

暂无

代码示例

代码示例来源:origin: CoFH/CoFHCore

public static int getHighestY(World world, int x, int z) {
  return world.getChunkFromBlockCoords(new BlockPos(x, 0, z)).getTopFilledSegment() + 16;
}

代码示例来源:origin: Darkhax-Minecraft/Bookshelf

/**
 * Gets a random position within a chunk. This will load the chunk if it is not already
 * loaded.
 *
 * @param world The world to get a position within.
 * @param x The chunk X position.
 * @param z The chunk Y position.
 * @return A random position within the chunk.
 */
public static BlockPos getRandomChunkPosition (World world, int x, int z) {
  
  final Chunk chunk = world.getChunk(x, z);
  final int posX = x * 16 + world.rand.nextInt(16);
  final int posZ = z * 16 + world.rand.nextInt(16);
  final int height = MathHelper.roundUp(chunk.getHeight(new BlockPos(posX, 0, posZ)) + 1, 16);
  final int posY = world.rand.nextInt(height > 0 ? height : chunk.getTopFilledSegment() + 16 - 1);
  return new BlockPos(posX, posY, posZ);
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

public static int getTopFilledHeight(Chunk chunk, int x, int z, boolean skippables) {
  int maxY = chunk.getTopFilledSegment() + 16;
  Block block;
  for (int y = maxY; y > 0; y--) {
    IBlockState state = chunk.getBlockState(new BlockPos(x, y, z));
    block = state.getBlock();
    if (block == Blocks.AIR || (skippables && AWStructureStatics.isSkippable(state))) {
      continue;
    }
    return y;
  }
  return -1;
}

代码示例来源:origin: ldtteam/minecolonies

/**
 * Check if a block is placeable and return new Y position.
 *
 * @param x     Block X position.
 * @param y     Block Y position.
 * @param z     Block Z position.
 * @param world the world.
 * @return The new Y position.
 */
public static int checkIfPlaceable(@NotNull final int x, @NotNull final int y, @NotNull final int z, @NotNull final World world)
{
  BlockPos target = new BlockPos(x,y,z);
  final Chunk chunk = world.getChunk(target);
  target = new BlockPos(x, chunk.getTopFilledSegment() + 16, z);
  while(world.getBlockState(target).getMaterial().isReplaceable())
  {
    target = target.down();
    if (target.getY() == 0)
    {
      break;
    }
  }
  return target.getY() + 1;
}

代码示例来源:origin: CoFH/CoFHCore

public static int getTopBlockY(World world, int x, int z) {
  int y = world.getChunkFromBlockCoords(new BlockPos(x, 0, z)).getTopFilledSegment() + 16;
  BlockPos pos;
  IBlockState state;
  Block block;
  do {
    if (--y < 0) {
      break;
    }
    pos = new BlockPos(x, y, z);
    state = world.getBlockState(pos);
    block = state.getBlock();
  } while (block.isAir(state, world, pos));
  return y;
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

private static int getTopFilledHeight(Chunk chunk, int x, int z) {
    int maxY = chunk.getTopFilledSegment() + 15;
    Block block;
    for (int y = maxY; y > 0; y--) {
      IBlockState state = chunk.getBlockState(new BlockPos(x, y, z));
      block = state.getBlock();
      if (AWStructureStatics.isSkippable(state)) {
        continue;
      }
      if (state.getMaterial().isLiquid()) {
        if (y >= 56) {
          continue;
        }// >=56 is fillable through underfill/border settings.  below that is too deep for a proper gradient on the border.
        return -1;//return invalid Y if liquid block is too low
      }
      if (!AWStructureStatics.isValidTargetBlock(state)) {
        AncientWarfareStructure.LOG.debug("rejecting town chunk for non-target block: " + block + " :: " + chunk.x + ":" + chunk.z);
        return -1;
      }
      return y;//if not skippable and is valid target block, return that y-level
    }
    return -1;
  }
}

代码示例来源:origin: Vazkii/Quark

private static BlockPos getTopLiquidBlock(World world, BlockPos pos) {
  Chunk chunk = world.getChunkFromBlockCoords(pos);
  BlockPos blockpos;
  BlockPos blockpos1;
  for(blockpos = new BlockPos(pos.getX(), chunk.getTopFilledSegment() + 16, pos.getZ()); blockpos.getY() >= 0; blockpos = blockpos1) {
    blockpos1 = blockpos.down();
    IBlockState state = chunk.getBlockState(blockpos1);
    if(state.getBlock() instanceof BlockLiquid)
      break;
  }
  return blockpos;
}

代码示例来源:origin: ForestryMC/ForestryMC

private int getFluidDepth(BlockPos pos) {
  Chunk chunk = world.getChunk(pos);
  int xx = pos.getX() & 15;
  int zz = pos.getZ() & 15;
  int depth = 0;
  for (int y = chunk.getTopFilledSegment() + 15; y > 0; --y) {
    IBlockState blockState = chunk.getBlockState(xx, y, zz);
    Block block = blockState.getBlock();
    if (blockState.getMaterial().isLiquid()) {
      depth++;
    } else if (!block.isAir(blockState, world, pos)) {
      break;
    }
  }
  return depth;
}

代码示例来源:origin: CoFH/CoFHCore

public static int getSurfaceBlockY(World world, int x, int z) {
  int y = world.getChunkFromBlockCoords(new BlockPos(x, 0, z)).getTopFilledSegment() + 16;
  BlockPos pos;
  IBlockState state;
  Block block;
  do {
    if (--y < 0) {
      break;
    }
    pos = new BlockPos(x, y, z);
    state = world.getBlockState(pos);
    block = state.getBlock();
  }
  while (block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos) || block.isFoliage(world, pos) || block.canBeReplacedByLeaves(state, world, pos));
  return y;
}

相关文章