Examples of ChunkProviderServer


Examples of net.minecraft.world.gen.ChunkProviderServer

  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

Examples of net.minecraft.world.gen.ChunkProviderServer

    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

Examples of net.minecraft.world.gen.ChunkProviderServer

      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

Examples of net.minecraft.world.gen.ChunkProviderServer

    }
    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

Examples of net.minecraft.world.gen.ChunkProviderServer

    int duplicateTiles = 0;
    int invalidTiles = 0;
    int unloadedEntities = 0;
    int unloadedTiles = 0;

    ChunkProviderServer chunkProviderServer = world.theChunkProviderServer;

    {
      Set<Entity> contained = new HashSet<Entity>();
      Set<Entity> toRemove = new ContainedRemoveSet<Entity>();
      List<Entity> unloaded = new ArrayList<Entity>();
      synchronized (entityLock) {
        for (Entity e : entityList) {
          if (add(e, false)) {
            missingEntities++;
            fixed++;
          } else if (!contained.add(e)) {
            toRemove.add(e);
            duplicateEntities++;
            fixed++;
          } else if (e instanceof IProjectile || e instanceof EntityCreature || e instanceof EntityMob) {
            synchronized (e) {
              Chunk chunk = world.getChunkIfExists(e.chunkCoordX, e.chunkCoordZ);
              if (chunk == null || !chunk.entityLists[e.chunkCoordY].contains(e)) {
                unloaded.add(e);
                unloadedEntities++;
              }
            }
          }
        }
        for (Entity e : unloaded) {
          remove(e);
        }
        entityList.removeAll(toRemove);
      }
    }

    {
      Set<TileEntity> contained = new HashSet<TileEntity>();
      Set<TileEntity> toRemove = new ContainedRemoveSet<TileEntity>();
      List<TileEntity> copy = new ArrayList<TileEntity>(tileEntityList.size());
      synchronized (tileEntityLock) {
        for (TileEntity te : tileEntityList) {
          copy.add(te);
          if (add(te, false)) {
            missingTiles++;
            fixed++;
          }
          if (!contained.add(te)) {
            toRemove.add(te);
            duplicateTiles++;
            fixed++;
          }
        }
        tileEntityList.removeAll(toRemove);
      }

      for (TileEntity te : copy) {
        Chunk chunk;
        boolean invalid = te.isInvalid();
        if (te.yCoord < 0 || te.yCoord > 255) {
          sb.append("TileEntity ").append(Log.toString(te)).append(" has an invalid y coordinate.\n");
          invalid = true;
        }
        if (invalid || (chunk = chunkProviderServer.getChunkIfExists(te.xCoord >> 4, te.zCoord >> 4)) == null || chunk.getChunkBlockTileEntity(te.xCoord & 15, te.yCoord, te.zCoord & 15) != te) {
          if (invalid) {
            invalidTiles++;
            sb.append("Removed ").append(Log.toString(te)).append(" as it is invalid.\n");
          } else {
            unloadedTiles++;
View Full Code Here

Examples of net.minecraft.world.gen.ChunkProviderServer

  }

  @Override
  @Declare
  public Object[] getChunks() {
    ChunkProviderServer chunkProviderServer = theChunkProviderServer;
    if (chunkProviderServer == null) {
      Log.warning("Bukkit getChunks call for unloaded world", new Throwable());
      return new Object[0];
    }
    List<Chunk> loadedChunks = chunkProviderServer.getLoadedChunks();
    synchronized (loadedChunks) {
      return loadedChunks.toArray();
    }
  }
View Full Code Here

Examples of net.minecraft.world.gen.ChunkProviderServer

  @Override
  public void run() {
    double tpsFactor = MinecraftServer.getTPS() / MinecraftServer.getTargetTPS();
    final Random rand = randoms.get();
    final Iterator<ChunkCoordIntPair> chunkCoordIterator = this.chunkCoordIterator;
    final ChunkProviderServer chunkProviderServer = this.theChunkProviderServer;
    final boolean isRaining = this.isRaining();
    final boolean isThundering = this.isThundering();
    final WorldProvider provider = this.provider;
    int updateLCG = this.updateLCG;
    // We use a random per thread - randoms are threadsafe, however it can result in some contention. See Random.nextInt - compareAndSet.
    // This reduces contention -> slightly increased performance, woo! :P
    while (true) {
      ChunkCoordIntPair chunkCoordIntPair;
      synchronized (chunkCoordIterator) {
        if (!chunkCoordIterator.hasNext()) {
          break;
        }
        try {
          chunkCoordIntPair = chunkCoordIterator.next();
        } catch (ConcurrentModificationException e) {
          break;
        }
      }

      if (tpsFactor < 1 && rand.nextFloat() > tpsFactor) {
        continue;
      }

      int cX = chunkCoordIntPair.chunkXPos;
      int cZ = chunkCoordIntPair.chunkZPos;

      Chunk chunk = chunkProviderServer.getChunkFastUnsafe(cX, cZ);
      if (chunk == null || !chunk.isTerrainPopulated || chunk.partiallyUnloaded || chunk.queuedUnload) {
        continue;
      }

      int xPos = cX * 16;
 
View Full Code Here

Examples of net.minecraft.world.gen.ChunkProviderServer

    super(world, manager, regionX, regionZ);
  }

  @Override
  public void doTick() {
    ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider();
    boolean profilingEnabled = manager.profilingEnabled || this.profilingEnabled;
    EntityTickProfiler entityTickProfiler = profilingEnabled ? EntityTickProfiler.ENTITY_TICK_PROFILER : null;
    long startTime = 0;
    Iterator<Entity> entitiesIterator = entitySet.startIteration();
    try {
      while (entitiesIterator.hasNext()) {
        if (profilingEnabled) {
          startTime = System.nanoTime();
        }
        Entity entity = entitiesIterator.next();
        try {
          Entity ridingEntity = entity.ridingEntity;
          if (ridingEntity != null) {
            if (!ridingEntity.isDead && ridingEntity.riddenByEntity == entity) {
              continue;
            }

            ridingEntity.riddenByEntity = null;
            entity.ridingEntity = null;
          }

          if (!entity.isDead) {
            if (entity instanceof EntityPlayerMP) {
              Unsafe $ = UnsafeAccess.$;
              Object lock = ((EntityPlayerMP) entity).playerNetServerHandler;
              if ($.tryMonitorEnter(lock)) {
                try {
                  world.updateEntity(entity);
                } finally {
                  $.monitorExit(lock);
                }
              }
            } else {
              world.updateEntity(entity);
            }
          }

          if (entity.isDead) {
            int entityX = entity.chunkCoordX;
            int entityZ = entity.chunkCoordZ;

            synchronized (entity) {
              if (entity.addedToChunk) {
                Chunk chunk = entity.chunk;
                if (chunk == null) {
                  chunkProvider.getChunkIfExists(entityX, entityZ);
                }
                if (chunk != null) {
                  chunk.removeEntity(entity);
                }
              }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.