public void sendPersistentChunksToPlayer(EntityPlayerMP player) {
    if (!AdditionalPipes.instance.chunkSight) {
      return;
    }
    if (sightRange > MAX_SIGHT_RANGE) sightRange = MAX_SIGHT_RANGE;

    SetMultimap<ChunkCoordIntPair, Ticket> persistentChunks =
        ForgeChunkManager.getPersistentChunksFor(player.worldObj);
    List<ChunkCoordIntPair> chunksInRange = new LinkedList<ChunkCoordIntPair>();
    int playerX = (((int) player.posX) >> 4) - sightRange / 2,
        playerZ = (((int) player.posZ) >> 4) - sightRange / 2;

    for (int i = -sightRange; i <= sightRange; i++) {
      for (int j = -sightRange; j <= sightRange; j++) {
        ChunkCoordIntPair coords = new ChunkCoordIntPair(playerX + i, playerZ + j);
        if (persistentChunks.containsKey(coords)) {
          chunksInRange.add(coords);
        }
      }
    }

    MessageChunkloadData message = new MessageChunkloadData(chunksInRange);

    PacketHandler.INSTANCE.sendTo(message, player);

    AdditionalPipes.instance.logger.info(
        "[ChunkLoadViewDataProxy] Sent chunks within " + sightRange + " of player.");
  }
  @Override
  public void forceChunkLoading(int chunkX, int chunkZ) {
    if (ticket == null) return;

    // System.out.println("loading chunks for miner");

    Set<ChunkCoordIntPair> chunks = getChunksAround(chunkX, chunkZ, 3);

    for (ChunkCoordIntPair chunk : chunks) {
      ForgeChunkManager.forceChunk(this.ticket, chunk);
    }

    ChunkCoordIntPair myChunk = new ChunkCoordIntPair(chunkX, chunkZ);
    ForgeChunkManager.forceChunk(this.ticket, myChunk);
    ForgeChunkManager.reorderChunk(this.ticket, myChunk);
  }
 @Override
 public void setChunkTicket(Ticket parTicket) {
   if (ticket != null && parTicket != ticket) {
     ForgeChunkManager.releaseTicket(ticket);
   }
   ticket = parTicket;
 }
  /**
   * Checks to see if the situation for firing the laser exists... and changes the state accordingly
   */
  public void checkCanRun() {
    // Laser requires lense, redstone power, not be jammed, and be in orbit and energy to function
    if (!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)
        || glassPanel == null
        || storage.getEnergyStored()
            == 0 /*|| !(this.worldObj.provider instanceof IOrbitDimension)*/) {
      if (laserSat.isAlive()) {
        laserSat.deactivateLaser();
      }

      isRunning = false;
    } else if (!laserSat.isAlive()
        && !finished
        && !laserSat.getJammed()
        && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)
        && canMachineSeeEarth()) {

      // Laser will be on at this point
      int orbitDimId =
          0; // =
             // WorldUtil.getProviderForName(((IOrbitDimension)this.worldObj.provider).getPlanetToOrbit()).dimensionId;
      WorldServer orbitWorld = DimensionManager.getWorld(orbitDimId);

      if (ticket == null) {
        ticket =
            ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.worldObj, Type.NORMAL);
        if (ticket != null)
          ForgeChunkManager.forceChunk(
              ticket,
              new ChunkCoordIntPair(
                  this.xCoord / 16 - (this.xCoord < 0 ? 1 : 0),
                  this.zCoord / 16 - (this.zCoord < 0 ? 1 : 0)));
      }

      isRunning = laserSat.activateLaser(orbitWorld, laserX, laserZ);
    }

    if (!this.worldObj.isRemote)
      PacketHandler.sendToNearby(
          new PacketMachine(this, (byte) 2),
          this.xCoord,
          this.yCoord,
          this.zCoord,
          128,
          this.worldObj.provider.dimensionId);
  }
  @Override
  public void invalidate() {
    if (Platform.isClient()) {
      return;
    }

    AELog.info("Released Ticket " + this.ct.toString());
    ForgeChunkManager.releaseTicket(this.ct);
  }
 public void requestTicket() {
   ForgeChunkManager.Ticket chunkTicket =
       ForgeChunkManager.requestTicket(
           HostileWorlds.instance, worldObj, ForgeChunkManager.Type.ENTITY);
   if (chunkTicket != null) {
     chunkTicket.getModData();
     chunkTicket.setChunkListDepth(12);
     chunkTicket.bindEntity(this);
     setChunkTicket(chunkTicket);
   }
 }
  void initTicket() {
    if (Platform.isClient()) {
      return;
    }

    this.ct = ForgeChunkManager.requestTicket(AppEng.instance(), this.worldObj, Type.NORMAL);

    if (this.ct == null) {
      MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
      if (server != null) {
        List<EntityPlayerMP> pl = server.getConfigurationManager().playerEntityList;
        for (EntityPlayerMP p : pl) {
          p.addChatMessage(new ChatComponentText("Can't chunk load.."));
        }
      }
      return;
    }

    AELog.info("New Ticket " + this.ct.toString());
    ForgeChunkManager.forceChunk(
        this.ct, new ChunkCoordIntPair(this.xCoord >> 4, this.zCoord >> 4));
  }
 @Override
 public void ticketsLoaded(List<ForgeChunkManager.Ticket> tickets, World world) {
   for (Ticket ticket : tickets) {
     NBTTagCompound nbt = ticket.getModData();
     if (nbt != null)
       if (nbt.getString("type").equals("TileEntity")) {
         int x = nbt.getInteger("xCoord");
         int y = nbt.getInteger("yCoord");
         int z = nbt.getInteger("zCoord");
         TileEntity te = world.getBlockTileEntity(x, y, z);
         if (te instanceof TileEntityChunkLoader)
           if (!((TileEntityChunkLoader) te).reinstateChunkTicket(ticket))
             ForgeChunkManager.releaseTicket(ticket);
       }
   }
 }
 public void forceChunkRangeOnTicket(Ticket ticket) {
   NBTTagCompound nbt = ticket.getModData();
   int minX = nbt.getInteger("rangeMinX");
   int minZ = nbt.getInteger("rangeMinZ");
   int maxX = nbt.getInteger("rangeMaxX");
   int maxZ = nbt.getInteger("rangeMaxZ");
   int chunkX = xCoord >> 4;
   int chunkZ = zCoord >> 4;
   for (int i = minX; i <= maxX; i++)
     for (int j = minZ; j <= maxZ; j++) {
       int x = chunkX + i, z = chunkZ + j;
       // System.out.printf("BaseChunkLoadingTE.forceChunkRangeOnTicket: forcing chunk (%d; %d,
       // %d)\n",
       // worldObj.provider.dimensionId, x, z);
       ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(x, z));
     }
 }
  @Mod.EventHandler
  public static void Init(FMLInitializationEvent event) {
    ForgeChunkManager.setForcedChunkLoadingCallback(
        EstateAgent.instance, new ChunkLoadingCallback());

    CraftingManager.getInstance()
        .addRecipe(
            new ItemStack(ModItems.landbook),
            "aaa",
            "aba",
            "aaa",
            'a',
            new ItemStack(Blocks.dirt),
            'b',
            new ItemStack(Items.book));

    simpleChannel = NetworkRegistry.INSTANCE.newSimpleChannel(References.MODNAME);
    simpleChannel.registerMessage(
        HandlerGeneralServer.class, PacketGeneralServer.class, 1, Side.SERVER);
    simpleChannel.registerMessage(
        HandlerGeneralClient.class, PacketGeneralClient.class, 2, Side.CLIENT);
  }
 @PostInit
 public void postInit(FMLPostInitializationEvent evt) {
   FactoryProxy.proxy.initializeNEIIntegration();
   ForgeChunkManager.setForcedChunkLoadingCallback(instance, new QuarryChunkloadCallback());
 }
  @PostInit
  public void postInit(FMLPostInitializationEvent evt) {

    ForgeChunkManager.setForcedChunkLoadingCallback(instance, new MFFSChunkloadCallback());
  }
 Ticket newTicket(World world) {
   return ForgeChunkManager.requestTicket(mod, world, Type.NORMAL);
 }
 public void releaseChunkTicket() {
   if (chunkTicket != null) {
     ForgeChunkManager.releaseTicket(chunkTicket);
     chunkTicket = null;
   }
 }
 public void onDestroy() {
   if (laserSat != null) {
     laserSat.deactivateLaser();
   }
   ForgeChunkManager.releaseTicket(ticket);
 }
 public BlockChunkloader() {
   super(Material.iron);
   this.setTileEntity(TileChunkLoader.class);
   ForgeChunkManager.setForcedChunkLoadingCallback(AppEng.instance(), this);
   this.setFeature(EnumSet.of(AEFeature.UnsupportedDeveloperTools, AEFeature.Creative));
 }
  @EventHandler
  public void init(FMLInitializationEvent event) {
    NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());

    logger.info("Registering chunk load handler");
    ForgeChunkManager.setForcedChunkLoadingCallback(this, new ChunkLoadingHandler());
    chunkLoadViewer = new ChunkLoadViewDataProxy(chunkSightRange);
    FMLCommonHandler.instance().bus().register(chunkLoadViewer);

    proxy.registerKeyHandler();

    proxy.registerRendering();

    loadConfigs(true);

    logger.info("Registering pipes");
    loadPipes();

    triggerPipeClosed = new TriggerPipeClosed("APClosed");
    ActionManager.registerTriggerProvider(new GateProvider());

    if (allowWRRemove) {
      // Additional Pipes
      GameRegistry.addRecipe(
          new ItemStack(pipeItemsTeleport), new Object[] {"A", 'A', pipePowerTeleport});
      GameRegistry.addRecipe(
          new ItemStack(pipeItemsTeleport), new Object[] {"A", 'A', pipeLiquidsTeleport});
      GameRegistry.addRecipe(
          new ItemStack(pipeItemsRedStone), new Object[] {"A", 'A', pipeLiquidsRedstone});
      // BC Liquid
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsCobblestone),
          new Object[] {"A", 'A', BuildCraftTransport.pipeFluidsCobblestone});
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsGold),
          new Object[] {"A", 'A', BuildCraftTransport.pipeFluidsGold});
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsIron),
          new Object[] {"A", 'A', BuildCraftTransport.pipeFluidsIron});
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsStone),
          new Object[] {"A", 'A', BuildCraftTransport.pipeFluidsStone});
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsWood),
          new Object[] {"A", 'A', BuildCraftTransport.pipeFluidsWood});
      // BC Power
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsGold),
          new Object[] {"A", 'A', BuildCraftTransport.pipePowerGold});
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsStone),
          new Object[] {"A", 'A', BuildCraftTransport.pipePowerStone});
      GameRegistry.addRecipe(
          new ItemStack(BuildCraftTransport.pipeItemsWood),
          new Object[] {"A", 'A', BuildCraftTransport.pipePowerWood});
    }

    // ChunkLoader
    blockChunkLoader = new BlockChunkLoader();
    blockChunkLoader.setBlockName("TeleportTether");
    GameRegistry.registerBlock(blockChunkLoader, ItemBlock.class, "chunkLoader");
    GameRegistry.registerTileEntity(TileChunkLoader.class, "TeleportTether");
    GameRegistry.addRecipe(
        new ItemStack(blockChunkLoader),
        new Object[] {
          "iii", "iLi", "iii", 'i', Items.iron_ingot, 'L', new ItemStack(Items.dye, 1, 4)
        });
  }
 public TileEntityChunkManager(LanteaCraft mod) {
   this.mod = mod;
   ForgeChunkManager.setForcedChunkLoadingCallback(mod, this);
 }