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

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

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

World.getChunk介绍

暂无

代码示例

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

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

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

  1. @Override
  2. public final void onChunkEvent(ChunkEvent event) {
  3. EventState state = event.getState();
  4. ChunkEvent.Type type = event.getType();
  5. boolean isPostPopulate = state == EventState.POST
  6. && (type == ChunkEvent.Type.POPULATE_FULL || type == ChunkEvent.Type.POPULATE_PARTIAL);
  7. World world = baritone.getPlayerContext().world();
  8. // Whenever the server sends us to another dimension, chunks are unloaded
  9. // technically after the new world has been loaded, so we perform a check
  10. // to make sure the chunk being unloaded is already loaded.
  11. boolean isPreUnload = state == EventState.PRE
  12. && type == ChunkEvent.Type.UNLOAD
  13. && world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ());
  14. if (isPostPopulate || isPreUnload) {
  15. baritone.getWorldProvider().ifWorldLoaded(worldData -> {
  16. Chunk chunk = world.getChunk(event.getX(), event.getZ());
  17. worldData.getCachedWorld().queueForPacking(chunk);
  18. });
  19. }
  20. listeners.forEach(l -> l.onChunkEvent(event));
  21. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Notify all chunks in the range of the colony about the colony.
  3. * @param world the world of the colony.
  4. * @param add remove or add
  5. */
  6. public static void claimColonyChunks(final World world, final boolean add, final int id, final BlockPos center, final int dimension)
  7. {
  8. final Chunk centralChunk = world.getChunk(center);
  9. loadChunkAndAddData(world, center, add, id);
  10. final int chunkX = centralChunk.x;
  11. final int chunkZ = centralChunk.z;
  12. final int range = Configurations.gameplay.workingRangeTownHallChunks;
  13. final int buffer = Configurations.gameplay.townHallPaddingChunk;
  14. claimChunksInRange(id, dimension, add, chunkX, chunkZ, range, buffer, world);
  15. }

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

  1. /**
  2. * Get colony that contains a given coordinate from world.
  3. *
  4. * @param w World.
  5. * @param pos coordinates.
  6. * @return Colony at the given location.
  7. */
  8. public static Colony getColonyByPosFromWorld(@NotNull final World w, @NotNull final BlockPos pos)
  9. {
  10. final Chunk centralChunk = w.getChunk(pos);
  11. final int id = centralChunk.getCapability(CLOSE_COLONY_CAP, null).getOwningColony();
  12. if (id == 0)
  13. {
  14. return null;
  15. }
  16. return getColonyByWorld(id, w);
  17. }

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

  1. /**
  2. * Get Colony that contains a given (x, y, z).
  3. *
  4. * @param w World.
  5. * @param pos coordinates.
  6. * @return returns the view belonging to the colony at x, y, z.
  7. */
  8. private static ColonyView getColonyView(@NotNull final World w, @NotNull final BlockPos pos)
  9. {
  10. final Chunk centralChunk = w.getChunk(pos);
  11. final int id = centralChunk.getCapability(CLOSE_COLONY_CAP, null).getOwningColony();
  12. if (id == 0)
  13. {
  14. return null;
  15. }
  16. return getColonyView(id);
  17. }

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

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

代码示例来源:origin: TeamWizardry/Wizardry

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

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

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

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

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

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

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

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

  1. private int getFluidDepth(BlockPos pos) {
  2. Chunk chunk = world.getChunk(pos);
  3. int xx = pos.getX() & 15;
  4. int zz = pos.getZ() & 15;
  5. int depth = 0;
  6. for (int y = chunk.getTopFilledSegment() + 15; y > 0; --y) {
  7. IBlockState blockState = chunk.getBlockState(xx, y, zz);
  8. Block block = blockState.getBlock();
  9. if (blockState.getMaterial().isLiquid()) {
  10. depth++;
  11. } else if (!block.isAir(blockState, world, pos)) {
  12. break;
  13. }
  14. }
  15. return depth;
  16. }

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

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

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

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

相关文章

World类方法