Package net.minecraft.world.gen

Examples of net.minecraft.world.gen.ChunkProviderServer


                Set<Vector2D> chunks = region.getChunks();
                IChunkProvider provider = getWorld().getChunkProvider();
                if (!(provider instanceof ChunkProviderServer)) {
                    return false;
                }
                ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
                Field u;
                try {
                    u = ChunkProviderServer.class.getDeclaredField("field_73248_b"); // chunksToUnload
                } catch(NoSuchFieldException e) {
                    u = ChunkProviderServer.class.getDeclaredField("chunksToUnload");
                }
                u.setAccessible(true);
                Set<?> unloadQueue = (Set<?>) u.get(chunkServer);
                Field m;
                try {
                    m = ChunkProviderServer.class.getDeclaredField("field_73244_f"); // loadedChunkHashMap
                } catch(NoSuchFieldException e) {
                    m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap");
                }
                m.setAccessible(true);
                LongHashMap loadedMap = (LongHashMap) m.get(chunkServer);
                Field lc;
                try {
                    lc = ChunkProviderServer.class.getDeclaredField("field_73245_g"); // loadedChunkHashMap
                } catch(NoSuchFieldException e) {
                    lc = ChunkProviderServer.class.getDeclaredField("loadedChunks");
                }
                lc.setAccessible(true);
                @SuppressWarnings("unchecked") List<Chunk> loaded = (List<Chunk>) lc.get(chunkServer);
                Field p;
                try {
                    p = ChunkProviderServer.class.getDeclaredField("field_73246_d"); // currentChunkProvider
                } catch(NoSuchFieldException e) {
                    p = ChunkProviderServer.class.getDeclaredField("currentChunkProvider");
                }
                p.setAccessible(true);
                IChunkProvider chunkProvider = (IChunkProvider) p.get(chunkServer);

                for (Vector2D coord : chunks) {
                    long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ());
                    Chunk mcChunk;
                    if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) {
                        mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ());
                        mcChunk.onChunkUnload();
                    }
                    unloadQueue.remove(pos);
                    loadedMap.remove(pos);
                    mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ());
View Full Code Here


                WorldServer[] worlds = FMLCommonHandler.instance().getMinecraftServerInstance().worldServers;

                for (int i = 0; i < worlds.length; i++)
                {
                    WorldServer world = worlds[i];
                    ChunkProviderServer chunkProviderServer = world.theChunkProviderServer;

                    Map<Long, List<Footprint>> footprintMap = TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId);

                    if (footprintMap != null)
                    {
View Full Code Here

    }
    WorldServer worldObj = DimensionManager.getWorld(0);
    if (worldObj == null) {
      LogHelper.warning("Target dimension 0 is not loaded for genesis?!");
    }
    ChunkProviderServer providerServer = (ChunkProviderServer) worldObj.getChunkProvider();
    GenesisChunkProvider providerGenesis = new GenesisChunkProvider(world, newBiome);

    // clear players from the danger zone and force unload chunks in
    // question
    List<EntityPlayerMP> players = new ArrayList<EntityPlayerMP>();
    Map<EntityPlayerMP, Vec3> playerOrigPositions = new HashMap<EntityPlayerMP, Vec3>();
    players.addAll(worldObj.playerEntities);

    final int safePad = 2;
    final double safeX = ( ( chunkX.intValue() - range - safePad ) << 4 ) - 8.0;
    final double safeZ = ( ( chunkZ.intValue() - range - safePad ) << 4 ) - 8.0;
    LogHelper.info("Safe position = " + safeX + "," + safeZ);

    Map<Pair<Integer, Integer>, Chunk> chunks = new HashMap<Pair<Integer, Integer>, Chunk>();
    for (int x1 = chunkX.intValue() - range; x1 <= chunkX.intValue() + range; x1++) {
      for (int z1 = chunkZ.intValue() - range; z1 <= chunkZ.intValue() + range; z1++) {
        for (EntityPlayerMP player : players) {
          if (worldObj.getPlayerManager().isPlayerWatchingChunk(player, x1, z1) && !playerOrigPositions.containsKey(player)) {
            final Vec3 origPosition = Vec3.createVectorHelper(player.posX, player.posY,player.posZ);
            playerOrigPositions.put(player, origPosition);
            LogHelper.info("Moving player " + player);
            player.setLocationAndAngles(safeX, player.posY, safeZ, 0.0F, 0.0F);
            worldObj.updateEntityWithOptionalForce(player, true);
          }
        }
        final Chunk chunk = world.getChunkFromBlockCoords(x, z);
        chunks.put(Pair.of(x1, z1), chunk); // save map of chunks
        providerServer.unloadChunksIfNotNearSpawn(x1, z1);
      }
    }

    // verify that chunks unloaded
    int lastloaded = 0;
    while (providerServer.getLoadedChunkCount() != lastloaded) {
      lastloaded = providerServer.getLoadedChunkCount();
      providerServer.unloadQueuedChunks();

      for (final Pair<Integer, Integer> coord : chunks.keySet()) {
        final Chunk chunk = chunks.get(coord);
        if (chunk != null) {
          if (chunk.isChunkLoaded) {
            LogHelper.warning("Failed to unload chunk @ " + coord);
            /*
             * } else { LogHelper.info("Chunk unloaded @ " + coord);
             */
          }
        }
      }
    }
    chunks.clear();
    LogHelper.info(providerServer.makeString());

    IChunkLoader chunkloader = providerServer.currentChunkLoader;
    providerServer.currentChunkLoader = null;
    for (int x1 = chunkX.intValue() - range; x1 <= chunkX.intValue() + range; x1++) {
      for (int z1 = chunkZ.intValue() - range; z1 <= chunkZ.intValue() + range; z1++) {
        // GenesisBiomeOverrideHandler.myQueue.add(new
        // GenesisBiomeOverrideHandler.coord(x1, z1));

        final Chunk chunk = providerServer.loadChunk(x1, z1);
       
        byte[] chunkBiomes = chunk.getBiomeArray();
        for (int k = 0; k < chunkBiomes.length; ++k) {
          chunkBiomes[k] = (byte) newBiome.biomeID;
        }
View Full Code Here

    _world = world;
    _biome = biome;
  }

  public IChunkLoader getCurrentChunkLoader() {
    final ChunkProviderServer parent = (ChunkProviderServer) _world.getChunkProvider();
    return parent.currentChunkLoader;
  }
View Full Code Here

    final ChunkProviderServer parent = (ChunkProviderServer) _world.getChunkProvider();
    return parent.currentChunkLoader;
  }

  public void setCurrentChunkLoader(IChunkLoader loader) {
    final ChunkProviderServer parent = (ChunkProviderServer) _world.getChunkProvider();
    parent.currentChunkLoader = loader;
  }
View Full Code Here

    final ChunkProviderServer parent = (ChunkProviderServer) _world.getChunkProvider();
    parent.currentChunkLoader = loader;
  }

  public void unloadChunksIfNotNearSpawn(int chunkX, int chunkZ) {
    final ChunkProviderServer parent = (ChunkProviderServer) _world.getChunkProvider();
    parent.unloadChunksIfNotNearSpawn(chunkX, chunkZ);
  }
View Full Code Here

  private static final Profiler profiler = MinecraftServer.getServer().theProfiler;

  public static void garbageCollect(WorldServer worldServer) {
    profiler.startSection("chunkGC");
    int viewDistance = MinecraftServer.getServer().getConfigurationManager().getViewDistance() + 1;
    ChunkProviderServer chunkProvider = worldServer.theChunkProviderServer;
    Set<Long> chunksToUnload = new HashSet<Long>();
    Iterable<Chunk> loadedChunks = chunkProvider.getLoadedChunks();
    synchronized (loadedChunks) {
      for (Chunk chunk : loadedChunks) {
        chunksToUnload.add(ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition));
      }
    }

    for (EntityPlayerMP player : (Iterable<EntityPlayerMP>) worldServer.playerEntities) {
      int cX = (int) player.managedPosX >> 4;
      int cZ = (int) player.managedPosZ >> 4;
      int minX = cX - viewDistance;
      int maxX = cX + viewDistance;
      int minZ = cZ - viewDistance;
      int maxZ = cZ + viewDistance;
      for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
          chunksToUnload.remove(ChunkCoordIntPair.chunkXZ2Int(x, z));
        }
      }
    }

    for (ChunkCoordIntPair chunkCoordIntPair : worldServer.getPersistentChunks().keySet()) {
      chunksToUnload.remove(ChunkCoordIntPair.chunkXZ2Int(chunkCoordIntPair.chunkXPos, chunkCoordIntPair.chunkZPos));
    }

    for (long chunk : chunksToUnload) {
      chunkProvider.unloadChunkForce(chunk);
    }

    profiler.endSection();
  }
View Full Code Here

    File chunkDir = worldServer.getChunkSaveLocation();
    File chunkLoaderData = new File(chunkDir, "forcedchunks.dat");

    if (chunkLoaderData.exists() && chunkLoaderData.isFile()) {
      // MCPC+ force chunks later to help guarantee Forge event ordering
      ChunkProviderServer chunkProviderServer = worldServer.theChunkProviderServer;
      ArrayListMultimap<String, Ticket> loadedTickets = ArrayListMultimap.create();
      Map<String, ListMultimap<String, Ticket>> playerLoadedTickets = Maps.newHashMap();
      NBTTagCompound forcedChunkData;
      try {
        forcedChunkData = CompressedStreamTools.read(chunkLoaderData);
      } catch (IOException e) {
        FMLLog.log(Level.WARNING, e, "Unable to read forced chunk data at %s - it will be ignored", chunkLoaderData.getAbsolutePath());
        return;
      }
      NBTTagList ticketList = forcedChunkData.getTagList("TicketList");
      for (int i = 0; i < ticketList.tagCount(); i++) {
        NBTTagCompound ticketHolder = (NBTTagCompound) ticketList.tagAt(i);
        String modId = ticketHolder.getString("Owner");
        boolean isPlayer = "Forge".equals(modId);

        if (!isPlayer && !Loader.isModLoaded(modId)) {
          FMLLog.warning("Found chunkloading data for mod %s which is currently not available or active - it will be removed from the world save", modId);
          continue;
        }

        if (!isPlayer && !callbacks.containsKey(modId)) {
          FMLLog.warning("The mod %s has registered persistent chunkloading data but doesn't seem to want to be called back with it - it will be removed from the world save", modId);
          continue;
        }

        NBTTagList tickets = ticketHolder.getTagList("Tickets");
        for (int j = 0; j < tickets.tagCount(); j++) {
          NBTTagCompound ticket = (NBTTagCompound) tickets.tagAt(j);
          modId = ticket.hasKey("ModId") ? ticket.getString("ModId") : modId;
          Type type = Type.values()[ticket.getByte("Type")];
          byte ticketChunkDepth = ticket.getByte("ChunkListDepth");
          Ticket tick = new Ticket(modId, type, world);
          if (ticket.hasKey("ModData")) {
            tick.modData = ticket.getCompoundTag("ModData");
          }
          if (ticket.hasKey("Player")) {
            tick.player = ticket.getString("Player");
            ListMultimap<String, Ticket> playerLoadedTicket = playerLoadedTickets.get(tick.modId);
            if (playerLoadedTicket == null) {
              playerLoadedTickets.put(modId, playerLoadedTicket = ArrayListMultimap.<String, Ticket>create());
            }
            playerLoadedTicket.put(tick.player, tick);
          } else {
            loadedTickets.put(modId, tick);
          }
          if (type == Type.ENTITY) {
            tick.entityChunkX = ticket.getInteger("chunkX");
            tick.entityChunkZ = ticket.getInteger("chunkZ");
            UUID uuid = new UUID(ticket.getLong("PersistentIDMSB"), ticket.getLong("PersistentIDLSB"));
            pendingEntities.put(uuid, tick);
            // add the ticket to the "pending entity" list
          }

          // MCPC+ start - save the chunks forced by this ticket (fix for chunkloaders)
          NBTTagList ticketChunks = ticket.getTagList("Chunks");
          for (int k = 0; k < ticketChunks.tagCount(); k++) {
            NBTTagCompound nbtChunk = (NBTTagCompound) ticketChunks.tagAt(k);
            int chunkX = nbtChunk.getInteger("chunkX");
            int chunkZ = nbtChunk.getInteger("chunkZ");
            ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair(chunkX, chunkZ);
            forceChunkInternal(tick, chunkCoordIntPair);
            chunkProviderServer.cacheChunk(chunkX, chunkZ);
          }
          // MCPC+ end
        }
      }
View Full Code Here

      if (world.forcedChunksInited) {
        return;
      }
      world.forcedChunksInited = true;
    }
    ChunkProviderServer chunkProviderServer = world.theChunkProviderServer;
    ArrayListMultimap<String, Ticket> loadedTickets = worldLoadedTickets.remove(world);
    if (loadedTickets != null) {
      for (String modId : loadedTickets.keySet()) {
        LoadingCallback loadingCallback = callbacks.get(modId);
        int maxTicketLength = getMaxTicketLengthFor(modId);
View Full Code Here

    }
    synchronized (entityLock) {
      entityList.removeAll(entities);
    }

    ChunkProviderServer chunkProviderServer = world.theChunkProviderServer;
    for (Entity entity : entities) {
      if (entity == null) {
        continue;
      }
      int x = entity.chunkCoordX;
      int z = entity.chunkCoordZ;

      if (entity.addedToChunk) {
        Chunk chunk = chunkProviderServer.getChunkIfExists(x, z);
        if (chunk != null) {
          chunk.removeEntity(entity);
        }
      }
View Full Code Here

TOP

Related Classes of net.minecraft.world.gen.ChunkProviderServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.