Program: 171530
Project: 171530
Buggy source:
public static EnumActionResult placeStock(EntityPlayer player,EnumHand hand,World worldIn,BlockPos pos,EntityRollingStockDefinition def,List<ItemComponentType> list){
  ITrack initte=Util.getTileEntity(worldIn,new Vec3d(pos.add(0,0.7,0)),true);
  if (initte == null) {
    return EnumActionResult.FAIL;
  }
  double trackGauge=initte.getTrackGauge();
  Gauge gauge=Gauge.from(trackGauge);
  if (!player.isCreative() && gauge != ItemGauge.get(player.getHeldItem(hand))) {
    player.sendMessage(ChatText.STOCK_WRONG_GAUGE.getMessage());
    return EnumActionResult.FAIL;
  }
  double offset=def.getCouplerPosition(CouplerType.BACK,gauge) - ConfigDebug.couplerRange;
  float yaw=player.rotationYawHead;
  TickPos tp=new MovementSimulator(worldIn,new TickPos(0,Speed.ZERO,new Vec3d(pos.add(0,0.7,0)).addVector(0.5,0,0.5),yaw,yaw,yaw,0,false),def.getBogeyFront(gauge),def.getBogeyRear(gauge),gauge.value()).nextPosition(offset);
  if (!tp.isOffTrack) {
    if (!worldIn.isRemote) {
      EntityRollingStock stock=def.spawn(worldIn,tp.position,EnumFacing.fromAngle(player.rotationYawHead),gauge);
      if (stock instanceof EntityBuildableRollingStock) {
        ((EntityBuildableRollingStock)stock).setComponents(list);
      }
      if (stock instanceof EntityMoveableRollingStock) {
        EntityMoveableRollingStock mrs=(EntityMoveableRollingStock)stock;
        tp.speed=Speed.ZERO;
        mrs.initPositions(tp);
      }
    }
    if (!player.isCreative()) {
      ItemStack stack=player.getHeldItem(hand);
      stack.setCount(stack.getCount() - 1);
      player.setHeldItem(hand,stack);
    }
    return EnumActionResult.PASS;
  }
  return EnumActionResult.FAIL;
}

Fixed version (ground truth):
public static EnumActionResult placeStock(EntityPlayer player,EnumHand hand,World worldIn,BlockPos pos,EntityRollingStockDefinition def,List<ItemComponentType> list){
  ITrack initte=Util.getTileEntity(worldIn,new Vec3d(pos.add(0,0.7,0)),true);
  if (initte == null) {
    return EnumActionResult.FAIL;
  }
  double trackGauge=initte.getTrackGauge();
  Gauge gauge=Gauge.from(trackGauge);
  if (!player.isCreative() && gauge != ItemGauge.get(player.getHeldItem(hand))) {
    player.sendMessage(ChatText.STOCK_WRONG_GAUGE.getMessage());
    return EnumActionResult.FAIL;
  }
  double offset=def.getCouplerPosition(CouplerType.BACK,gauge) - ConfigDebug.couplerRange;
  float yaw=player.rotationYawHead;
  TickPos tp=new MovementSimulator(worldIn,new TickPos(0,Speed.ZERO,new Vec3d(pos.add(0,0.7,0)).addVector(0.5,0,0.5),yaw,yaw,yaw,0,false),def.getBogeyFront(gauge),def.getBogeyRear(gauge),gauge.value()).nextPosition(offset);
  if (!tp.isOffTrack) {
    if (!worldIn.isRemote) {
      EntityRollingStock stock=def.spawn(worldIn,tp.position,EnumFacing.fromAngle(player.rotationYawHead),gauge);
      if (stock instanceof EntityBuildableRollingStock) {
        ((EntityBuildableRollingStock)stock).setComponents(list);
      }
      if (stock instanceof EntityMoveableRollingStock) {
        EntityMoveableRollingStock mrs=(EntityMoveableRollingStock)stock;
        tp.speed=Speed.ZERO;
        mrs.initPositions(tp);
      }
    }
    if (!player.isCreative()) {
      ItemStack stack=player.getHeldItem(hand);
      stack.setCount(stack.getCount() - 1);
      player.setHeldItem(hand,stack);
    }
    return EnumActionResult.SUCCESS;
  }
  return EnumActionResult.FAIL;
}