<commit_before>package crazypants.enderio.conduit.power;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.power.IPowerInterface;
import crazypants.util.BlockCoord;

public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit, IPowerConduit> {

  // ----------------------------------------------------------------------

  NetworkPowerManager powerManager;

  private Map<ReceptorKey, ReceptorEntry> powerReceptors = new HashMap<ReceptorKey, ReceptorEntry>();

  private long timeAtLastApply = -1;

  public PowerConduitNetwork() {
    super(IPowerConduit.class);
  }

  @Override
  public void init(IConduitBundle tile, Collection<IPowerConduit> connections, World world) {
    super.init(tile, connections, world);
    powerManager = new NetworkPowerManager(this, world);
    powerManager.receptorsChanged();
  }

  @Override
  public void destroyNetwork() {
    for (IPowerConduit con : conduits) {
      con.setActive(false);
    }
    powerManager.onNetworkDestroyed();
    super.destroyNetwork();
  }

  public NetworkPowerManager getPowerManager() {
    return powerManager;
  }

  @Override
  public void addConduit(IPowerConduit con) {
    super.addConduit(con);
    Set<ForgeDirection> externalDirs = con.getExternalConnections();
    for (ForgeDirection dir : externalDirs) {
      IPowerInterface pr = con.getExternalPowerReceptor(dir);
      if(pr != null) {
        TileEntity te = con.getBundle().getEntity();<commit_msg>Fixed crash when a power network is destroyed before being initialized.<commit_after>package crazypants.enderio.conduit.power;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.power.IPowerInterface;
import crazypants.util.BlockCoord;

public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit, IPowerConduit> {

  // ----------------------------------------------------------------------

  NetworkPowerManager powerManager;

  private Map<ReceptorKey, ReceptorEntry> powerReceptors = new HashMap<ReceptorKey, ReceptorEntry>();

  private long timeAtLastApply = -1;

  public PowerConduitNetwork() {
    super(IPowerConduit.class);
  }

  @Override
  public void init(IConduitBundle tile, Collection<IPowerConduit> connections, World world) {
    super.init(tile, connections, world);
    powerManager = new NetworkPowerManager(this, world);
    powerManager.receptorsChanged();
  }

  @Override
  public void destroyNetwork() {
    for (IPowerConduit con : conduits) {
      con.setActive(false);
    }
    if(powerManager != null) {
      powerManager.onNetworkDestroyed();
    }
    super.destroyNetwork();
  }

  public NetworkPowerManager getPowerManager() {
    return powerManager;
  }

  @Override
  public void addConduit(IPowerConduit con) {
    super.addConduit(con);
    Set<ForgeDirection> externalDirs = con.getExternalConnections();
    for (ForgeDirection dir : externalDirs) {
      IPowerInterface pr = con.getExternalPowerReceptor(dir);
      if(pr != null) {
        TileEntity te = con.getBundle().getEntity();
{'fraction_non_alphanumeric': 0.12868702688593056, 'fraction_numerical': 0.0005220569042025581, 'mean_word_length': 3.9830949284785437, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2894237', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1143, 'n_words': 223}