net.minecraft.world.World.getChunk()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(176)

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

World.getChunk介绍

暂无

代码示例

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

public static boolean isSlimeChunk(World world, int x, int z) {
  Chunk chunk = world.getChunk(new BlockPos(x, 0, z));
  return chunk.getRandomWithSeed(987234911L).nextInt(10) == 0;
}

代码示例来源:origin: cabaletta/baritone

@Override
public final void onChunkEvent(ChunkEvent event) {
  EventState state = event.getState();
  ChunkEvent.Type type = event.getType();
  boolean isPostPopulate = state == EventState.POST
      && (type == ChunkEvent.Type.POPULATE_FULL || type == ChunkEvent.Type.POPULATE_PARTIAL);
  World world = baritone.getPlayerContext().world();
  // Whenever the server sends us to another dimension, chunks are unloaded
  // technically after the new world has been loaded, so we perform a check
  // to make sure the chunk being unloaded is already loaded.
  boolean isPreUnload = state == EventState.PRE
      && type == ChunkEvent.Type.UNLOAD
      && world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ());
  if (isPostPopulate || isPreUnload) {
    baritone.getWorldProvider().ifWorldLoaded(worldData -> {
      Chunk chunk = world.getChunk(event.getX(), event.getZ());
      worldData.getCachedWorld().queueForPacking(chunk);
    });
  }
  listeners.forEach(l -> l.onChunkEvent(event));
}

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

/**
 * Gets a list of 9 chunks in a 3x3 area, centered around the passed chunk position.
 *
 * @param world The world to get chunks from.
 * @param chunk The chunk position.
 * @return A list of 9 chunks that are near the passed chunk pos, as well as the chunk at
 *         the passed position.
 */
public static List<Chunk> getNearbyChunks (World world, ChunkPos chunk) {
  
  final List<Chunk> chunks = new ArrayList<>();
  
  for (int offX = -1; offX < 2; offX++) {
    
    for (int offY = -1; offY < 2; offY++) {
      
      chunks.add(world.getChunk(chunk.x + offX, chunk.z + offY));
    }
  }
  
  return chunks;
}

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

/**
   * Checks if a block position is in a slime chunk.
   *
   * @param world The world instance.
   * @param pos The position to check.
   * @return Whether or not the chunk is a slime chunk.
   */
  public static boolean isSlimeChunk (World world, BlockPos pos) {
    
    return world.getChunk(pos).getRandomWithSeed(987234911L).nextInt(10) == 0;
  }
}

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

public static ChunkDataTFC get(World world, BlockPos pos)
{
  ChunkDataTFC data = world.getChunk(pos).getCapability(ChunkDataProvider.CHUNK_DATA_CAPABILITY, null);
  return data == null ? EMPTY : data;
}

代码示例来源:origin: PrinceOfAmber/Cyclic

@Override
public Chunk getChunk(int chunkX, int chunkZ) {
 return this.getCartWorld().getChunk(chunkX, chunkZ);
}

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

/**
 * Check if a given coordinate is inside any other colony.
 *
 * @param world the world to check in.
 * @param pos   the position to check.
 * @return true if a colony has been found.
 */
public static boolean isCoordinateInAnyColony(@NotNull final World world, final BlockPos pos)
{
  final Chunk centralChunk = world.getChunk(pos);
  return centralChunk.getCapability(CLOSE_COLONY_CAP, null).getOwningColony() != 0;
}

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

@Override
public boolean isCoordInColony(@NotNull final World w, @NotNull final BlockPos pos)
{
  final Chunk chunk = w.getChunk(pos);
  final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null);
  return cap.getOwningColony() == this.getID();
}

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

@Override
public boolean isCoordInColony(@NotNull final World w, @NotNull final BlockPos pos)
{
  final Chunk chunk = w.getChunk(pos);
  final IColonyTagCapability cap = chunk.getCapability(CLOSE_COLONY_CAP, null);
  return cap.getOwningColony() == this.getID();
}

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

/**
 * Notify all chunks in the range of the colony about the colony.
 * @param world the world of the colony.
 * @param add remove or add
 */
public static void claimColonyChunks(final World world, final boolean add, final int id, final BlockPos center, final int dimension)
{
  final Chunk centralChunk = world.getChunk(center);
  loadChunkAndAddData(world, center, add, id);
  final int chunkX = centralChunk.x;
  final int chunkZ = centralChunk.z;
  final int range = Configurations.gameplay.workingRangeTownHallChunks;
  final int buffer = Configurations.gameplay.townHallPaddingChunk;
  claimChunksInRange(id, dimension, add, chunkX, chunkZ, range, buffer, world);
}

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

/**
 * Get colony that contains a given coordinate from world.
 *
 * @param w   World.
 * @param pos coordinates.
 * @return Colony at the given location.
 */
public static Colony getColonyByPosFromWorld(@NotNull final World w, @NotNull final BlockPos pos)
{
  final Chunk centralChunk = w.getChunk(pos);
  final int id = centralChunk.getCapability(CLOSE_COLONY_CAP, null).getOwningColony();
  if (id == 0)
  {
    return null;
  }
  return getColonyByWorld(id, w);
}

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

/**
 * Get Colony that contains a given (x, y, z).
 *
 * @param w   World.
 * @param pos coordinates.
 * @return returns the view belonging to the colony at x, y, z.
 */
private static ColonyView getColonyView(@NotNull final World w, @NotNull final BlockPos pos)
{
  final Chunk centralChunk = w.getChunk(pos);
  final int id = centralChunk.getCapability(CLOSE_COLONY_CAP, null).getOwningColony();
  if (id == 0)
  {
    return null;
  }
  return getColonyView(id);
}

代码示例来源: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: TeamWizardry/Wizardry

private void generateMana(World world, Random rand, int x, int z) {
    for (int i = 0; i < 1; i++) {
      WorldGenManaLake gen = new WorldGenManaLake(ModFluids.MANA.getActualBlock());
      int xRand = x * 16 + rand.nextInt(16);
      int zRand = z * 16 + rand.nextInt(16);
      int yRand = world.getChunk(x, z).getLowestHeight();
//            int yRand = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).getY();
      yRand = RandUtil.nextInt(yRand - 1, yRand);
      BlockPos position = new BlockPos(xRand, yRand, zRand);
      gen.generate(world, rand, position);
    }
  }

代码示例来源:origin: gegy1000/Terrarium

@Override
public final void composeDecoration(IChunkGenerator generator, World world, RegionGenerationHandler regionHandler, int chunkX, int chunkZ) {
  int globalX = chunkX << 4;
  int globalZ = chunkZ << 4;
  this.randomMap.initPosSeed(globalX, globalZ);
  this.random.setSeed(this.randomMap.next());
  Biome biome = world.getChunk(chunkX, chunkZ).getBiome(DECORATION_CENTER, world.getBiomeProvider());
  this.composeDecoration(generator, world, chunkX, chunkZ, biome);
}

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

public void retroGen(Random random, int chunkX, int chunkZ, World world) {
  generateWorld(random, chunkX, chunkZ, world);
  ModuleManager.getInternalHandler().populateChunkRetroGen(world, random, chunkX, chunkZ);
  world.getChunk(chunkX, chunkZ).markDirty();
}

代码示例来源:origin: PrinceOfAmber/Cyclic

public static void teleportWallSafe(EntityLivingBase player, World world, double x, double y, double z) {
 BlockPos coords = new BlockPos(x, y, z);
 world.markBlockRangeForRenderUpdate(coords, coords);
 world.getChunk(coords).setModified(true);
 player.setPositionAndUpdate(x, y, z);
 moveEntityWallSafe(player, world);
}

代码示例来源: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: PrinceOfAmber/Cyclic

public static boolean teleport(EntityPlayer player, int slot) {
 ItemStack book = getPlayersBook(player);
 BlockPosDim loc = getLocation(book, slot);
 if (GuiEnderBook.BACK_BTN_ID == slot) {
  loc = getBackLocation(book);
 }
 if (player.dimension != loc.dimension) {
  return false;//button was disabled anyway,... but just in case 
 }
 //something in vanilla 
 if (player instanceof EntityPlayerMP) {//server only
  // thanks so much to
  // http://www.minecraftforge.net/forum/index.php?topic=18308.0 
  //also moving up so  not stuck in floor
  boolean success = UtilEntity.enderTeleportEvent(player, player.world, loc.X, loc.Y + 0.1, loc.Z);
  if (success) { // try and force chunk loading it it worked 
   player.getEntityWorld().getChunk(new BlockPos(loc.X, loc.Y, loc.Z)).setModified(true);
  }
 }
 return true;
}

代码示例来源:origin: gegy1000/Terrarium

private void teleport(Entity entity, Coordinate coordinate) {
  int blockX = MathHelper.floor(coordinate.getBlockX());
  int blockZ = MathHelper.floor(coordinate.getBlockZ());
  Chunk chunk = entity.world.getChunk(blockX >> 4, blockZ >> 4);
  int height = chunk.getHeightValue(blockX & 15, blockZ & 15);
  entity.dismountRidingEntity();
  if (entity instanceof EntityPlayerMP) {
    NetHandlerPlayServer connection = ((EntityPlayerMP) entity).connection;
    connection.setPlayerLocation(coordinate.getBlockX(), height + 0.5, coordinate.getBlockZ(), 180.0F, 0.0F);
  }
  entity.motionY = 0.0;
  entity.onGround = true;
  entity.sendMessage(DeferredTranslator.translate(entity, new TextComponentTranslation("commands.earth.geotp.success", coordinate.getX(), coordinate.getZ())));
}

相关文章

微信公众号

最新文章

更多

World类方法