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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.Config;
import crazypants.enderio.Log;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.util.BlockCoord;
import crazypants.util.FluidUtil;
import crazypants.util.RoundRobinIterator;

public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit, EnderLiquidConduit> {

  public static final int MAX_EXTRACT_PER_TICK = Config.enderFluidConduitExtractRate;
  public static final int MAX_IO_PER_TICK = Config.enderFluidConduitMaxIoRate;

  List<NetworkTank> tanks = new ArrayList<NetworkTank>();
  Map<NetworkTankKey, NetworkTank> tankMap = new HashMap<NetworkTankKey, NetworkTank>();

  Map<NetworkTank, RoundRobinIterator<NetworkTank>> iterators;

  public EnderLiquidConduitNetwork() {
    super(EnderLiquidConduit.class);
  }

  @Override
  public Class<ILiquidConduit> getBaseConduitType() {
    return ILiquidConduit.class;
  }

  public void connectionChanged(EnderLiquidConduit con, ForgeDirection conDir) {
    NetworkTankKey key = new NetworkTankKey(con, conDir);
    NetworkTank tank = new NetworkTank(con, conDir);
    tanks.remove(tank); // remove old tank, NB: =/hash is only calced on location and dir
    tankMap.remove(key);
    tanks.add(tank);
    tankMap.put(key, tank);
  }

  public boolean extractFrom(EnderLiquidConduit con, ForgeDirection conDir) {
    NetworkTank tank = getTank(con, conDir);
    if(tank == null || !tank.isValid()) {
      return false;
    }
    FluidStack drained = tank.externalTank.drain(conDir.getOpposite(), MAX_EXTRACT_PER_TICK, false);
    if(drained == null || drained.amount <= 0 || !matchedFilter(drained, con, conDir, true)) {
      return false;
    }
    int amountAccepted = fillFrom(tank, drained, false);
    if(amountAccepted <= 0) {
      return false;
    }
    drained = tank.externalTank.drain(conDir.getOpposite(), amountAccepted, true);
    if(drained == null || drained.amount <= 0) {
      return false;
    }
    int filled = fillFrom(tank, drained, true);
    if(drained.amount != filled) {
      Log.warn("EnderLiquidConduit.extractFrom: Extracted fluid volume is not equal to inserted volume. Drained=" + drained.amount + " filled=" + filled + " Fluid: " + drained + " Accepted=" + amountAccepted);
    }
    return true;
  }

  private NetworkTank getTank(EnderLiquidConduit con, ForgeDirection conDir) {
    return tankMap.get(new NetworkTankKey(con, conDir));
  }

  public int fillFrom(EnderLiquidConduit con, ForgeDirection conDir, FluidStack resource, boolean doFill) {
    return fillFrom(getTank(con, conDir), resource, doFill);
  }

  public int fillFrom(NetworkTank tank, FluidStack resource, boolean doFill) {
    if(resource == null || tank == null || !matchedFilter(resource, tank.con, tank.conDir, true)) {
      return 0;
    }<commit_msg>Removed redundant call.<commit_after>package crazypants.enderio.conduit.liquid;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.Config;
import crazypants.enderio.Log;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.util.BlockCoord;
import crazypants.util.FluidUtil;
import crazypants.util.RoundRobinIterator;

public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit, EnderLiquidConduit> {

  public static final int MAX_EXTRACT_PER_TICK = Config.enderFluidConduitExtractRate;
  public static final int MAX_IO_PER_TICK = Config.enderFluidConduitMaxIoRate;

  List<NetworkTank> tanks = new ArrayList<NetworkTank>();
  Map<NetworkTankKey, NetworkTank> tankMap = new HashMap<NetworkTankKey, NetworkTank>();

  Map<NetworkTank, RoundRobinIterator<NetworkTank>> iterators;

  public EnderLiquidConduitNetwork() {
    super(EnderLiquidConduit.class);
  }

  @Override
  public Class<ILiquidConduit> getBaseConduitType() {
    return ILiquidConduit.class;
  }

  public void connectionChanged(EnderLiquidConduit con, ForgeDirection conDir) {
    NetworkTankKey key = new NetworkTankKey(con, conDir);
    NetworkTank tank = new NetworkTank(con, conDir);
    tanks.remove(tank); // remove old tank, NB: =/hash is only calced on location and dir
    tankMap.remove(key);
    tanks.add(tank);
    tankMap.put(key, tank);
  }

  public boolean extractFrom(EnderLiquidConduit con, ForgeDirection conDir) {
    NetworkTank tank = getTank(con, conDir);
    if(tank == null || !tank.isValid()) {
      return false;
    }
    FluidStack drained = tank.externalTank.drain(conDir.getOpposite(), MAX_EXTRACT_PER_TICK, false);
    if(drained == null || drained.amount <= 0 || !matchedFilter(drained, con, conDir, true)) {
      return false;
    }
    int amountAccepted = fillFrom(tank, drained, true);
    if(amountAccepted <= 0) {
      return false;
    }
    drained = tank.externalTank.drain(conDir.getOpposite(), amountAccepted, true);
    if(drained == null || drained.amount <= 0) {
      return false;
    }    
    if(drained.amount != amountAccepted) {
      Log.warn("EnderLiquidConduit.extractFrom: Extracted fluid volume is not equal to inserted volume. Drained=" + drained.amount + " filled=" + amountAccepted + " Fluid: " + drained + " Accepted=" + amountAccepted);
    }
    return true;
  }

  private NetworkTank getTank(EnderLiquidConduit con, ForgeDirection conDir) {
    return tankMap.get(new NetworkTankKey(con, conDir));
  }

  public int fillFrom(EnderLiquidConduit con, ForgeDirection conDir, FluidStack resource, boolean doFill) {
    return fillFrom(getTank(con, conDir), resource, doFill);
  }

  public int fillFrom(NetworkTank tank, FluidStack resource, boolean doFill) {
    if(resource == null || tank == null || !matchedFilter(resource, tank.con, tank.conDir, true)) {
      return 0;
    }
{'fraction_non_alphanumeric': 0.10318076027928627, 'fraction_numerical': 0.0012412723041117144, 'mean_word_length': 4.786355475763016, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, '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': '6892264', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2134, 'n_words': 449}